basephi.py

Created by nicolas-patrois

Created on December 15, 2018

609 Bytes

Décompose un nombre en base ϕ (le nombre d’or tel que ϕ^2=ϕ+1). Comme 6=ϕ^3+ϕ+ϕ^-4, on note 6=1010.0001 en base ϕ. Si on impose qu’aucun chiffre n’est supérieur à 1 et que deux chiffres égaux à 1 ne soient pas consécutifs, la décomposition est unique.


def basephi(n):
  l=[n,0]
  v=1
  cont=True
  while cont:
    cont=False
    for i,e in enumerate(l):
      if e>1:
        cont=True
        if i==0:
          l.insert(0,0)
          v+=1
          i=1
        while i+2>=len(l):
          l.append(0)
        l[i-1]+=1
        l[i]-=2
        l[i+2]+=1
        break
    for i,e in enumerate(l[:-1]):
      if e>0 and l[i+1]>0:
        cont=True
        if i==0:
          l.insert(0,0)
          v+=1
          i=1
        l[i-1]+=1
        l[i]-=1
        l[i+1]-=1
        break
  return "".join(map(str,l[:v]))+"."+"".join(map(str,l[v:]))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.