Created
December 2, 2014 21:28
-
-
Save merbussa/576a87e02c905cfe0389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dec2fib(n): #Ozyineli fibonacci mantigiyla fibonacci dizisini buldurur. | |
if n==0: | |
return 0 | |
elif n==1: | |
return 1 | |
else: | |
return (dec2fib(n-1) + dec2fib(n-2)) | |
def indis_parcala(a): #Fibonacci dizisinde yerine '1' koyulmasi gereken indisleri dondurur. | |
i=1 | |
while a > i: | |
if (a >= dec2fib(i) and a < dec2fib(i + 1)): | |
break | |
i += 1 | |
return i | |
dec = int(input("Decimal Number:\n")) #Kullanicidan bir sayi ister. | |
if (dec>0): | |
def indis_tamamla(dec): | |
array=[] | |
while dec >= 1: | |
x=indis_parcala(dec) | |
array.append(x) | |
dec= dec-dec2fib(x) | |
return array | |
print (end='Index Series: ') #Bulmus oldugu indisleri dizi formatinda ekrana yazdirir. | |
array = indis_tamamla(dec) #Diziyi yukarida ki fonksiyondan cagirma islemini gercelestirir. | |
print (array) | |
z = [] | |
i = 0 | |
while (i <= array[0]-1): | |
z.append(0) | |
i += 1 | |
i=1 | |
for i in array: | |
if i == 1: | |
z[0] = 1 | |
z[i-1] = 1 | |
z.reverse() | |
print ("Fibonacci Value= ", ''.join(map(str,z))) #Tamamen internetten buldugum bir kalip | |
#Amacim sayiyinin ekranda dizi seklinde gorunmemesiydi. | |
number=input("Fibonacci Base to Number:\n")#Yine internetten bulduğum bir kalıp | |
range=list(map(int,str(number))) #Indislerde gezinebilmek amaciyla; stringi diziye cevirdim. | |
print ("Input Series: ", range) | |
#Fibonacciyi ustten cagirmak yerine buraya basitce bir fibonacci yazdirdim. | |
step = len(range) | |
fibonacci=[] | |
i = 0 | |
while (i != step): | |
if i > 1: | |
fibonacci.append(fibonacci[i - 1] + fibonacci[i - 2]) | |
else: | |
fibonacci.append(1) | |
i += 1 | |
fibonacci.reverse() #Fibonacciyi sag bastan baslatmıs oldum. | |
print ("Fibonacci Series:", fibonacci) | |
i=0 | |
result=0 | |
while (i<len(range)): | |
if range[i]==1: | |
result = result + fibonacci[i] | |
i+=1 | |
else: | |
i+=1 | |
print ("Decimal Value= ", result) #Sayimizin ondalik tabana cevrilmis hali.. | |
else: | |
print ("Attention! Entered negative number..") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment