a = 1
b = 1
for i in range(n):
a, b = b, a+b
return a
def main():
i = 1
j = 0
nums = ''
flag = 0
while flag != 1:
funs = str(fun(i))
for each in funs:
if each not in nums:
nums += each
else:
nums = ''
i = j
j += 1
i += 1
temp = ''.join(sorted(nums)) == '0123456789':
print(nums)
flag = 1
if __name__ == '__main__':
main()
好像没找到符合的数。是不是我理解错题目了 #创建函数,生成第n项斐波那契数
def Fib(n):
if n==1 or n==2:
return 1
else:
return Fib(n-1)+Fib(n-2)
#创建函数,将前n项项斐波那契数合并成一个字符串
def Fibs(n):
list_Fib=[]
for i in range(1,n+1):
list_Fib.append(str(Fib(i)))
return ''.join(list_Fib)
m=8
#从第8项开始,前n项自然数个数大于10
flag=1
while flag:
for i in range(len(Fibs(m))-9):
fibs=Fibs(m)
a=
b=
if sorted(a)==b:
#判断合成的字符串里有没有0~10
print(fibs)
flag=0
break
else:
print(Fibs(m))
m=m+1
本帖最后由 AlexEdwars 于 2018-4-7 18:45 编辑
fib_start = 1
fib_end = 1
while True:
data = ''
for i in range(10):
data += str(fib_start)
fib_end, fib_start = (fib_end + fib_start), fib_end
for i in range(10):
if str(i) in data:
pass
else:
break
else:
print(data)
print()
a, b = 0, 1
s = '1'
while s:
a, b = b, a + b
s += str(b)
for i in range(len(s)):
if len(set(s)) == 10:
print(s)
s = '' 本帖最后由 lxchace 于 2018-4-7 20:04 编辑
#funny Fibonacci
def fibs():
a,b = 0,1
while True:
a,b = b,a+b
#print(a)
yield a
return
def include10(s):
for i in range(10):
if s.find(str(i))==-1:
return False
return True
def findnums():
Fibs=fibs()
fibs_str=''
i=0
while len(fibs_str)<10:
fibs_str+=str(next(Fibs))
while True:
if include10(fibs_str):
break
i+=1
if len(fibs_str)-i<10:
fibs_str+=str(next(Fibs))
print(fibs_str)
return
def main():
findnums()
return
if __name__ == "__main__":
main() 达锅 发表于 2018-4-5 21:38
def findDigits():
m,n,txt=1,1,"11"#mn分别是数列前后项
while len(set(txt[:10]))!=10:#每次 ...
好厉害,都没想过用几何元素的互异性来判断是否符合 def KO(s):
for i in range(10):
if str(i) not in s:
return False
return True
为什么代码的空格会不对的
n = 10
b = True
# 为了提高效率,这里不用FB产生数列的项,而是用前面的产生后面的项
a1 = 1
a2 = 1
strfb = "11"
for i in range(1, 5):
a1, a2 = a2, a1 + a2
strfb = strfb + str(a2)
while b:
for i in range(len(strfb)-9):
if KO(strfb):
print(strfb)
print("在", a2, "里找到的,是第", n, "项")
b = False
break
if b:
n += 1
a1, a2 = a2, a1 + a2
strfb = strfb[-9:] + str(a2)
吴有才 发表于 2018-4-5 23:28
shu=1000
a=0
b=10
老哥这个代码写的很有趣哈{:10_279:} 塔利班 发表于 2018-4-5 21:18
日了,手抖多加了一项= = a,b,i,j=0,1,0,0
l=''
whilei<=1000:
a,b=b,a+b
l+=str(a)
i+=1
for j in range(len(l)):
if len(set(l))==10:
print(l)
来晚了,写了个,有点复杂……
def fib_itr(n):
if n < 0:
return None
if n <= 1:
return (0, 1)
a, b = 0, 1
for i in range(n-1):
a, b = b, a+b
return b
def judge(str1):
num =
return True if num.count(1) == 10 else False
str1 = ''
n = 1
while len(str1) < 10:
str1 += str(fib_itr(n))
n += 1
while n < 1000:
l = len(str1)
str1 += str(fib_itr(n))
n += 1
for i in range(len(str(fib_itr(n-1)))):
if judge(str1):
print(str1)
break
结果:
9034621587
5037496128
4538679120
0685291437
1307952468
0625379814
3495718260
4872635019
8094635172
9051628347
0235879461
8350479216
1548620397
9530278614
2083746915
9812437560
2641803975
3450921867
8374291560
3912754068
4785690312
7392561840
4510687932
9061852743
0875496123
7245190386
4158302967
6457130298
7456930182
0529186743
6084251379
4165238709
4029157638
0983571624
1947268035
6280794315
5647928031
0147296835
6480123579
3481926075
1095837246
4028135679
5386701924 num=int(input('请输入一个整数:'))
def fib(n):
a = 1
b = 0
string = ''
for i in range(n):
a ,b = b,a+b
string += str(b)
return string
string = fib(num)
length = len(string)
for i in range(length):
if len(set(string)) == 10:
print(string)
break def haspan(s): #判断字符串s是否含用全字符
if len(s)<10:
return '0'
for i in range(len(s)-10):
if ''.join(sorted(s))=='0123456789':
return s
return '0'
a,b,s=1,1,'1'
while True:
a,b=b,a+b
s+=str(a)
t=haspan(s)
if t!='0':
break
print(t) def Fib():
a,b = 0,1
while True:
a,b=b,a+b
yield a
string,flag,f = '',1,Fib()
while flag:
if len(set(string))!=10:
string=string+str(next(f))
string=string[-11:-1]
else:
print(string)
flag=0 def fib(n):
s = ''
a = 0
b = 1
for i in range(n):
a,b = b,a+b
s += str(a)
return s
n = 0
while True:
check = fib(999)
# if check == '9034621587':
#print(check)
for each in check:
if check.count(each) != 1:
n += 1
break
else:
print(n,(n+10),check)
n += 1
if n > 3000:
break
import random
def feibonaqie():
a =
b = 0
while True:
if len(a) == 1:
b += a
a.append(b)
continue
b = a+a
a.append(b)
if len(a) == 100:
feibo = ''.join('%s'%number for number in a)
return feibo
break
answer = []
for i in feibonaqie():
if int(i) == 2 or int(i) == 1 or int(i) == 3 or int(i) == 5 or int(i) == 8:
answer.append(i)
feibo = ''.join('%s'%number for number in answer)
if len(answer) == 10:
break
print(feibo)
a= 0
b =1
string =''
ls = []
for i in range(1000):
a,b = b,a+b
string += str(a)
else:
# print(string)
for j in string:
# print(j)
if j in ls:
ls = ls
ls.append(j)
else:
ls.append(j)
if len(ls) == 10:
for l in ls:
print(l,end="")
print()
本帖最后由 子沙 于 2018-8-22 18:32 编辑
x1=1
x2=1
x3=x1+x2
f=str(x1)+str(x2)+str(x3)
n=3
while len(f)<10:
x1=x2
x2=x3
x3=x1+x2
f+=str(x3)
n=n+1
i=0
m=0
while m==0:
while i+9<=len(f):
if ('0'in list(f)and'1'in list(f)and'2'in list(f)and'3'in list(f)and'4'in list(f)and
'5'in list(f)and'6'in list(f)and'7'in list(f)and'8'in list(f) and'9'in list(f)):
print('最先出现在斐波那契数列第%d项:%d,10个数即为'%(n,x3),'',*list(f))
m=1
break
i+=1
x1=x2
x2=x3
x3=x1+x2
f+=str(x3)
n=n+1 a = b = 1
flag = False
while not flag:
s = str(a) + str(b)
for i in range(len(s) - 9):
if len(set(s)) == 10:
flag = True
print(s)
break
a, b = b, a + b
页:
1
[2]