找回密码
 注册
Simdroid-非首页
查看: 133|回复: 9

[欧拉习题] ProjEuler[38]: pandigital number

[复制链接]
发表于 2009-11-18 15:10:49 | 显示全部楼层 |阅读模式 来自 黑龙江大庆
本帖最后由 FreddyMusic 于 2009-11-20 15:15 编辑

Take the number 192 and multiply it by each of 1, 2, and 3:
   192 * 1 = 192
   192 * 2 = 384
   192 * 3 = 576

   By concatenating each product we get the 1 to 9 pandigital, 192384576.
   We will call 192384576 the concatenated product of 192 and (1,2,3)

   The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).
   What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?
发表于 2009-11-19 10:54:55 | 显示全部楼层 来自 上海宝山区
Simdroid开发平台
报题号,这是第几题?
回复 不支持

使用道具 举报

发表于 2009-11-19 11:18:25 | 显示全部楼层 来自 美国
太官僚了吧,google一下就知道是38题了。
回复 不支持

使用道具 举报

发表于 2009-11-19 13:19:35 | 显示全部楼层 来自 甘肃兰州
既然本版经常发PE的题目就应该相对整齐一点,至少标题里应该写清楚吧。
回复 不支持

使用道具 举报

 楼主| 发表于 2009-11-20 09:34:08 | 显示全部楼层 来自 黑龙江大庆
呵呵。。以后记住题号。。。大家都参与一下怎么解决这个问题呢?
回复 不支持

使用道具 举报

发表于 2009-11-20 17:06:46 | 显示全部楼层 来自 上海
这是我以前的解,只有答案,你们谁能 优化效率或者缩短代码,有加分。


  1. pandigitalMax=987654321;
  2. pandigitalMin=123456789;
  3. productListR2=Table[With[{p=FromDigits[Flatten[IntegerDigits[i*Range[2]]]]},If[pandigitalMin<p&&p<pandigitalMax,p]],{i,4999,10000}];
  4. productListR3=Table[With[{p=FromDigits[Flatten[IntegerDigits[i*Range[3]]]]},If[pandigitalMin<p&&p<pandigitalMax,p]],{i,100,500}];
  5. productListR4=Table[With[{p=FromDigits[Flatten[IntegerDigits[i*Range[4]]]]},If[pandigitalMin<p&&p<pandigitalMax,p]],{i,1,50}];
  6. productListR5=Table[With[{p=FromDigits[Flatten[IntegerDigits[i*Range[5]]]]},If[pandigitalMin<p&&p<pandigitalMax,p]],{i,1,10}];
  7. pandigitalQ[number_Integer]:=If[Length[Intersection[Range[9],IntegerDigits[number]]]==9,True,False]
  8. pandigitalR2=Select[productListR2,pandigitalQ[#]&]
  9. {672913458,679213584,692713854,726914538,729314586,732914658,769215384,792315846,793215864,926718534,927318546,932718654}
  10. pandigitalR3=Select[productListR3,pandigitalQ[#]&]
  11. {192384576,219438657,273546819,327654981}
  12. pandigitalR4=Select[productListR4,pandigitalQ[#]&]
  13. {}
  14. pandigitalR4=Select[productListR5,pandigitalQ[#]&]
  15. {918273645}
  16. answer=932718654
  17. 932718654
复制代码
回复 不支持

使用道具 举报

发表于 2009-11-20 21:15:00 | 显示全部楼层 来自 甘肃兰州
6# FreddyMusic
  1. In[42]:= Timing[ans = {};
  2. Do[If[Sort[(s = Flatten@IntegerDigits[i Range[5]])] == Range[9],
  3.    ans = Append[ans, s]], {i, 1, 9}];
  4. Do[If[Sort[(s = Flatten@IntegerDigits[i Range[4]])] == Range[9],
  5.    ans = Append[ans, s]], {i, 10, 33}];
  6. Do[If[Sort[(s = Flatten@IntegerDigits[i Range[3]])] == Range[9],
  7.    ans = Append[ans, s]], {i, 34, 333}];
  8. Do[If[Sort[(s = Flatten@IntegerDigits[i Range[2]])] == Range[9],
  9.    ans = Append[ans, s]], {i, 5000, 9999}]; FromDigits /@ ans // Max]

  10. Out[42]= {0.11, 932718654}
复制代码

我也不知道如何写的更短一些,如果可以欢迎提出。
既然你的代码用到了“分情况讨论”,那么我直接将这一步用口算得出,在程序中省略掉了。

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2009-11-20 21:27:43 | 显示全部楼层 来自 上海
把那4 句 Do 可以并称一句,用函数{ 2, 3, 4, 5 } 表示值域。
回复 不支持

使用道具 举报

发表于 2009-11-20 21:50:39 | 显示全部楼层 来自 甘肃兰州
8# FreddyMusic 但是i的取值和那个2,3,4,5没什么直接关系啊
回复 不支持

使用道具 举报

发表于 2009-11-21 09:40:28 | 显示全部楼层 来自 上海
抓大放小。控制数量级,那些100, 1000 的不影响效率。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-27 11:25 , Processed in 0.044053 second(s), 18 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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