找回密码
 欢迎注册
查看: 64469|回复: 34

[提问] 百度之星的一道与斐波那契数列有关的题

[复制链接]
发表于 2012-12-13 18:38:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
题目来源:http://astar.baidu.com/index.php?r=home/detail&id=2 du熊对数学一直都非常感兴趣。最近在学习斐波那契数列的它,向你展示了一个数字串,它称之为“斐波那契”串: 11235813471123581347112358........ 聪明的你当然一眼就看出了这个串是这么构造的: 1.先写下两位在0~9范围内的数字a, b,构成串ab; 2.取串最后的两位数字相加,将和写在串的最后面。 上面du熊向你展示的串就是取a = b = 1构造出来的串。 显然,步骤1之后不停地进行步骤2,数字串可以无限扩展。现在,du熊希望知道串的第n位是什么数字。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-13 21:09:49 | 显示全部楼层
猜想,不管a,b是什么开始的,最终都构成一个周期重复性的数字串.
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-13 21:17:37 | 显示全部楼层
不是猜想,是必然的. 总共也就100种情况.可以用程序穷举验证.
  1. Flatten[Table[{{i, j}, xx = Table[0, {i, 10}, {j, 10}];
  2. NestWhile[(xx[[#[[-2]] + 1, #[[-1]] + 1]] = 1; Join[#, IntegerDigits[Total[Take[#, -2]]]]) &, {i, j}, xx[[#[[-2]] + 1, #[[-1]] + 1]] == 0 &]}, {i, 0, 9}, {j, 0, 9}], 1]
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-13 22:22:15 | 显示全部楼层
  1. {0,0} {0,0,0}
  2. {0,1} {0,1,1,2,3,5,8,1,3,4,7,1,1}
  3. {0,2} {0,2,2,4,6,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  4. {0,3} {0,3,3,6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  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3,5,8,1,3,4,7,1,1}
  31. {3,0} {3,0,3,3,6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  32. {3,1} {3,1,4,5,9,1,4}
  33. {3,2} {3,2,5,7,1,2,3,5,8,1,3,4,7,1,1,2}
  34. {3,3} {3,3,6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  35. {3,4} {3,4,7,1,1,2,3,5,8,1,3,4}
  36. {3,5} {3,5,8,1,3,4,7,1,1,2,3,5}
  37. {3,6} {3,6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  38. {3,7} {3,7,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  39. {3,8} {3,8,1,1,2,3,5,8,1,3,4,7,1,1}
  40. {3,9} {3,9,1,2,3,5,8,1,3,4,7,1,1,2}
  41. {4,0} {4,0,4,4,8,1,2,3,5,8,1,3,4,7,1,1,2}
  42. {4,1} {4,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  43. {4,2} {4,2,6,8,1,4,5,9,1,4}
  44. {4,3} {4,3,7,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  45. {4,4} {4,4,8,1,2,3,5,8,1,3,4,7,1,1,2}
  46. {4,5} {4,5,9,1,4,5}
  47. {4,6} {4,6,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  48. {4,7} {4,7,1,1,2,3,5,8,1,3,4,7}
  49. {4,8} {4,8,1,2,3,5,8,1,3,4,7,1,1,2}
  50. {4,9} {4,9,1,3,4,7,1,1,2,3,5,8,1,3}
  51. {5,0} {5,0,5,5,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  52. {5,1} {5,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  53. {5,2} {5,2,7,9,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  54. {5,3} {5,3,8,1,1,2,3,5,8,1,3,4,7,1,1}
  55. {5,4} {5,4,9,1,3,4,7,1,1,2,3,5,8,1,3}
  56. {5,5} {5,5,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  57. {5,6} {5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  58. {5,7} {5,7,1,2,3,5,8,1,3,4,7,1,1,2}
  59. {5,8} {5,8,1,3,4,7,1,1,2,3,5,8}
  60. {5,9} {5,9,1,4,5,9}
  61. {6,0} {6,0,6,6,1,2,3,5,8,1,3,4,7,1,1,2}
  62. {6,1} {6,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  63. {6,2} {6,2,8,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  64. {6,3} {6,3,9,1,2,3,5,8,1,3,4,7,1,1,2}
  65. {6,4} {6,4,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  66. {6,5} {6,5,1,1,2,3,5,8,1,3,4,7,1,1}
  67. {6,6} {6,6,1,2,3,5,8,1,3,4,7,1,1,2}
  68. {6,7} {6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  69. {6,8} {6,8,1,4,5,9,1,4}
  70. {6,9} {6,9,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  71. {7,0} {7,0,7,7,1,4,5,9,1,4}
  72. {7,1} {7,1,8,9,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  73. {7,2} {7,2,9,1,1,2,3,5,8,1,3,4,7,1,1}
  74. {7,3} {7,3,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  75. {7,4} {7,4,1,1,2,3,5,8,1,3,4,7,1,1}
  76. {7,5} {7,5,1,2,3,5,8,1,3,4,7,1,1,2}
  77. {7,6} {7,6,1,3,4,7,1,1,2,3,5,8,1,3}
  78. {7,7} {7,7,1,4,5,9,1,4}
  79. {7,8} {7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  80. {7,9} {7,9,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  81. {8,0} {8,0,8,8,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  82. {8,1} {8,1,9,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  83. {8,2} {8,2,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  84. {8,3} {8,3,1,1,2,3,5,8,1,3,4,7,1,1}
  85. {8,4} {8,4,1,2,3,5,8,1,3,4,7,1,1,2}
  86. {8,5} {8,5,1,3,4,7,1,1,2,3,5,8,1,3}
  87. {8,6} {8,6,1,4,5,9,1,4}
  88. {8,7} {8,7,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  89. {8,8} {8,8,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  90. {8,9} {8,9,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  91. {9,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}
  92. {9,1} {9,1,1,0,1,1,2,3,5,8,1,3,4,7,1,1}
  93. {9,2} {9,2,1,1,2,3,5,8,1,3,4,7,1,1}
  94. {9,3} {9,3,1,2,3,5,8,1,3,4,7,1,1,2}
  95. {9,4} {9,4,1,3,4,7,1,1,2,3,5,8,1,3}
  96. {9,5} {9,5,1,4,5,9,1,4}
  97. {9,6} {9,6,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  98. {9,7} {9,7,1,6,7,1,3,4,7,1,1,2,3,5,8,1,3}
  99. {9,8} {9,8,1,7,8,1,5,6,1,1,2,3,5,8,1,3,4,7,1,1}
  100. {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}
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2012-12-13 23:07:58 | 显示全部楼层
不是猜想,是必然的. 总共也就100种情况.可以用程序穷举验证.Flatten; NestWhile[(xx[[#[[-2]] + 1, #[[-1]] + 1]] = 1; Join[#, IntegerDigits[Total[Take[#, -2]]]]) &, {i, j}, xx[[#[[-2]] + 1, #[[-1]] + ... wayne 发表于 2012-12-13 21:17
厉害!再问个问题,用Join是不是比AppendTo更好呢
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2012-12-13 23:40:14 | 显示全部楼层
python用reduce(更像Fold)模仿Mathematica的Nest
  1. intDigits=lambda n: map(int, str(n))
  2. print reduce(lambda x,y: x+intDigits(sum(x[-2:])), range(10), [1,1])
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-14 10:54:54 | 显示全部楼层
AppendTo和Join的差别可以根据在文档中的路径看得出来 Mathematica > Core Language > Defining Variables and Functions > Assignments > AppendTo Mathematica > Core Language > Expressions > Structural Operations on Expressions > Join 一个是属于赋值性质的,是要修改原值的, 一个是对结构的操作.
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-14 11:09:13 | 显示全部楼层
6# chyanog 我一定要抽个时间深入学一下Python,这语言挺不错的.
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-14 13:23:05 | 显示全部楼层
这个题目还真有些意思,matlab应该也能干这个活
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-12-14 13:23:55 | 显示全部楼层
其实也就是双重循环,然后再加上一个子函数
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-23 19:40 , Processed in 0.023765 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表