百度之星的一道与斐波那契数列有关的题
题目来源:http://astar.baidu.com/index.php?r=home/detail&id=2du熊对数学一直都非常感兴趣。最近在学习斐波那契数列的它,向你展示了一个数字串,它称之为“斐波那契”串:
11235813471123581347112358........
聪明的你当然一眼就看出了这个串是这么构造的:
1.先写下两位在0~9范围内的数字a, b,构成串ab;
2.取串最后的两位数字相加,将和写在串的最后面。
上面du熊向你展示的串就是取a = b = 1构造出来的串。
显然,步骤1之后不停地进行步骤2,数字串可以无限扩展。现在,du熊希望知道串的第n位是什么数字。 猜想,不管a,b是什么开始的,最终都构成一个周期重复性的数字串. 不是猜想,是必然的.
总共也就100种情况.可以用程序穷举验证.Flatten;
NestWhile[(xx[[#[[-2]] + 1, #[[-1]] + 1]] = 1; Join[#, IntegerDigits]]]) &, {i, j}, xx[[#[[-2]] + 1, #[[-1]] + 1]] == 0 &]}, {i, 0, 9}, {j, 0, 9}], 1]
{0,0} {0,0,0}
{0,1} {0,1,1,2,3,5,8,1,3,4,7,1,1}
{0,2} {0,2,2,4,6,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
{0,3} {0,3,3,6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
{0,4} {0,4,4,8,1,2,3,5,8,1,3,4,7,1,1,2}
{0,5} {0,5,5,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
{0,6} {0,6,6,1,2,3,5,8,1,3,4,7,1,1,2}
{0,7} {0,7,7,1,4,5,9,1,4}
{0,8} {0,8,8,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
{0,9} {0,9,9,1,8,9,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
{1,0} {1,0,1,1,2,3,5,8,1,3,4,7,1,1}
{1,1} {1,1,2,3,5,8,1,3,4,7,1,1}
{1,2} {1,2,3,5,8,1,3,4,7,1,1,2}
{1,3} {1,3,4,7,1,1,2,3,5,8,1,3}
{1,4} {1,4,5,9,1,4}
{1,5} {1,5,6,1,1,2,3,5,8,1,3,4,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,5,8,1,3,4,7,1,1}
{9,9} {9,9,1,8,9,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
不是猜想,是必然的.
总共也就100种情况.可以用程序穷举验证.Flatten;
NestWhile[(xx[[#[[-2]] + 1, #[[-1]] + 1]] = 1; Join[#, IntegerDigits]]]) &, {i, j}, xx[[#[[-2]] + 1, #[[-1]] +...
wayne 发表于 2012-12-13 21:17 http://bbs.emath.ac.cn/images/common/back.gif
厉害!再问个问题,用Join是不是比AppendTo更好呢 python用reduce(更像Fold)模仿Mathematica的Nest
intDigits=lambda n: map(int, str(n))
print reduce(lambda x,y: x+intDigits(sum(x[-2:])), range(10), )
AppendTo和Join的差别可以根据在文档中的路径看得出来
Mathematica > Core Language > Defining Variables and Functions > Assignments > AppendTo
Mathematica > Core Language > Expressions > Structural Operations on Expressions > Join
一个是属于赋值性质的,是要修改原值的, 一个是对结构的操作. 6# chyanog
:b:
我一定要抽个时间深入学一下Python,这语言挺不错的. 这个题目还真有些意思,matlab应该也能干这个活 其实也就是双重循环,然后再加上一个子函数