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

[演示项目] 奥运五环中的数字 --- 编程小题

[复制链接]
发表于 2008-4-22 12:44:18 | 显示全部楼层 |阅读模式 来自 江苏无锡
奥运五环中的数字 --- 编程小题

Pandigital Olympic Circles





提示:

1. 共八解
2. 思考如何提高算法效率和降低运行时间。

答案:Mathematica online demonstration and Code
http://demonstrations.wolfram.com/PandigitalOlympicCirclesPuzzle/

游客,如果您要查看本帖隐藏内容请回复


[ 本帖最后由 FreddyMusic 于 2008-4-27 16:26 编辑 ]

本帖子中包含更多资源

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

×

评分

1

查看全部评分

发表于 2008-4-22 18:00:59 | 显示全部楼层 来自 湖北武汉
Simdroid开发平台
。。。
纯回复贴
回复 不支持

使用道具 举报

发表于 2008-4-22 18:24:59 | 显示全部楼层 来自 安徽合肥
ok!ok!
回复 不支持

使用道具 举报

发表于 2008-4-22 21:19:59 | 显示全部楼层 来自 陕西安康
向FreddyMusic学习!
回复 不支持

使用道具 举报

发表于 2008-4-23 03:53:09 | 显示全部楼层 来自 美国
en, en,

  1. fontsize = 25;
  2. c1[n1_, n2_] :=
  3.   Graphics[{Blue, Thick, Circle[{-2.2, 1}],
  4.     Text[Style[n1, Black, fontsize], {-2.2, 1.3}],
  5.     Text[Style[n2, Black, fontsize], {-1.1 - .55, .6}]}];
  6. c2[n3_, n4_, n5_] :=
  7.   Graphics[{Black, Thick, Circle[{0, 1}],
  8.     Text[Style[n3, Black, fontsize], {-.55, .6}],
  9.     Text[Style[n4, Black, fontsize], {0, 1.3}],
  10.     Text[Style[n5, Black, fontsize], {.55, .6}]}];
  11. c3[n6_, n7_] :=
  12.   Graphics[{Red, Thick, Circle[{2.2, 1}],
  13.     Text[Style[n6, Black, fontsize], {2.2 - .55, .6}],
  14.     Text[Style[n7, Black, fontsize], {2.2, 1.3}]}];
  15. c4[n2_, n8_, n3_] :=
  16.   Graphics[{Yellow, Thick, Circle[{-1.1, 0.3}],
  17.     Text[Style[n8, Black, fontsize], {-1.1, -0.3}]}];
  18. c5[n5_, n9_, n6_] :=
  19.   Graphics[{Green, Thick, Circle[{1.1, 0.3}],
  20.     Text[Style[n9, Black, fontsize], {1.1, -0.3}]}];
  21. graph[r_] :=
  22. Show[c1[r[[1]], r[[2]]], c2[r[[3]], r[[4]], r[[5]]],
  23.   c3[r[[6]], r[[7]]], c4[r[[2]], r[[8]], r[[3]]],
  24.   c5[r[[5]], r[[9]], r[[6]]], PlotRange -> 3.5, AspectRatio -> 1]

  25. rsum = 13;
  26. c = Permutations[Range[9], {4}];
  27. csum = Total[c, {2}];
  28. v = rsum*5 - 45;
  29. p = Flatten[Position[csum, v]];
  30. l = {};
  31. Do[{
  32.    cc = c[[p[[i]]]];
  33.    r = {rsum - cc[[1]], cc[[1]], cc[[2]], rsum - cc[[2]] - cc[[3]],
  34.      cc[[3]], cc[[4]], rsum - cc[[4]], rsum - cc[[1]] - cc[[2]],
  35.      rsum - cc[[3]] - cc[[4]]};
  36.    r1 = Union[r];
  37.    If[ Min[r1] == 1 && Max[r1] == 9 &&
  38.      Length[r1] == 9, {l = Append[l, r]}];}, {i, Length[p]}];
  39. Length[l];
  40. y = Table[graph[l[[i]]], {i, Length[l]}]
复制代码

[ 本帖最后由 pcqsl 于 2008-4-23 06:35 编辑 ]

评分

2

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2008-4-23 09:06:40 | 显示全部楼层 来自 江苏无锡
pcqsl,

Speed good,
Algorithm smart.
回复 不支持

使用道具 举报

发表于 2008-4-23 15:40:49 | 显示全部楼层 来自 湖南长沙
什么东西也要顶一下
回复 不支持

使用道具 举报

 楼主| 发表于 2008-4-24 14:57:39 | 显示全部楼层 来自 江苏无锡
pcqsl,

游客,本帖隐藏的内容需要积分高于 5 才可浏览,您当前积分为 0


[ 本帖最后由 FreddyMusic 于 2008-4-24 15:27 编辑 ]

本帖子中包含更多资源

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

×
回复 不支持

使用道具 举报

 楼主| 发表于 2008-4-24 15:17:57 | 显示全部楼层 来自 江苏无锡
We have two possiblity:

1. To make dynamic list with more digitals and one pcs shorter rings.
Eg. digital 1-11 or 1-13,  / Rings 6 or 7 pcs   ( One digital in one ring space )
then check the middle data same as our demo ?

2. To make with more digitals and two digital in one rings.   
Eg. digital 1-19  / Rings 5 pcs ( two digital in one ring space ) ( three digital in one ring space)
then check the middle data same as our demo ?

What's your opinion ? I perfer the 2nd.

[ 本帖最后由 FreddyMusic 于 2008-4-24 15:24 编辑 ]
回复 不支持

使用道具 举报

发表于 2008-4-25 03:50:06 | 显示全部楼层 来自 美国
原帖由 FreddyMusic 于 2008-4-24 15:17 发表
We have two possiblity:

1. To make dynamic list with more digitals and one pcs shorter rings.
Eg. digital 1-11 or 1-13,  / Rings 6 or 7 pcs   ( One digital in one ring space )
then check the mid ...


According to my understanding, we were just asked for dynamic controls, the sliders.  It is simple.  I don't think they are asking for more complicated problems and algorithms.  By slightly modifying your code, I come up with
  1. rsum = 11;
  2. Print["Control the identical target sum of each circle by " Slider[
  3.    Dynamic[rsum], {3, 24, 1}]]
  4. Print["Current target sum is " Style[Dynamic[rsum], Large, Bold, Purple]]
  5. Dynamic[{
  6.   numberintwo = Permutations[Range[1, 9], {4}];
  7.   csum = Total[numberintwo, {2}];
  8.   v = rsum*5 - 45;
  9.   p = Flatten[Position[csum, v]];
  10.   
  11.   (* Search pandigital list *)
  12.   Sol = {};
  13.   Do[{cc = numberintwo[[p[]]];
  14.        r = { rsum - cc[[1]], cc[[1]],  rsum  - cc[[1]] - cc[[2]],
  15.       cc[[2]],  rsum  - cc[[2]] - cc[[3]], cc[[3]],
  16.       rsum - cc[[3]] - cc[[4]], cc[[4]], rsum - cc[[4]]};
  17.        r1 = Union[r];
  18.        If[
  19.      Min[r1] == 1 && Max[r1] == 9 &&
  20.       Length[r1] == 9, {Sol = Append[Sol, r]}];}, {i, Length[p]}];
  21.   
  22.   (* Plot digital and rings *)
  23.   If[Sol == {},
  24.    Graphics[{Text[
  25.       Style["No solution.", Large, Bold, Purple], {0, 0},
  26.       Automatic]}, ImageSize -> {575, 300}],
  27.    GraphicsGrid[Table[
  28.      Graphics[{Thickness[0.01],
  29.        (* Plot Olympic five rings *)
  30.        RGBColor[0, .5, .76], Circle[{0, 0}, 2],
  31.        RGBColor[34/256, 30/256, 29/256], Circle[{4.5, 0}, 2],
  32.        RGBColor[235/256, 29/256, 42/256], Circle[{9, 0}, 2],
  33.        RGBColor[251/256, 178/256, 49/256], Circle[{2.25, -2.25}, 2],
  34.        RGBColor[1/256, 156/256, 88/256], Circle[{6.75, -2.25}, 2],
  35.        (* Replot Olympic five rings to make it connect *)
  36.        RGBColor[0, .5, .76], Circle[{0, 0}, 2, {-Pi/3, 0}],
  37.        RGBColor[34/256, 30/256, 29/256],
  38.        Circle[{4.5, 0}, 2, {-Pi/3, 0}],
  39.        RGBColor[34/256, 30/256, 29/256],
  40.        Circle[{4.5, 0}, 2, {Pi*1.3, Pi*1.5}],
  41.        RGBColor[235/256, 29/256, 42/256],
  42.        Circle[{9, 0}, 2, {Pi*1.3, Pi*1.5}],
  43.        (* Plot Numbers in rings *)
  44.        Text[Style[Sol[[2 i + j]][[1]], 20, Purple], {0, 0}],
  45.        Text[
  46.         Style[Sol[[2 i + j]][[2]], 20, Purple], {2.25/2, -2.25/2}],
  47.        Text[Style[Sol[[2 i + j]][[3]], 20, Purple], {2.25, -2.25}],
  48.        Text[
  49.         Style[Sol[[2 i + j]][[4]], 20,
  50.          Purple], {(2.25 + 4.5)/2, -2.25/2}],
  51.        Text[Style[Sol[[2 i + j]][[5]], 20, Purple], {4.5, 0}],
  52.        Text[
  53.         Style[Sol[[2 i + j]][[6]], 20,
  54.          Purple], {(4.5 + 6.75)/2, -2.25/2}],
  55.        Text[Style[Sol[[2 i + j]][[7]], 20, Purple], {6.75, -2.25}],
  56.        Text[
  57.         Style[Sol[[2 i + j]][[8]], 20,
  58.          Purple], {(6.75 + 9)/2, -2.25/2}],
  59.        Text[Style[Sol[[2 i + j]][[9]], 20, Purple], {9, 0}]
  60.        }], {i, 0, Length[Sol]/2 - 1}, {j, 1, 2}],
  61.     ImageSize -> {575, 300}]]}]
复制代码
You see the range of sum is from 3 to 24.  The basic reason is that there are at least two or at most three numbers in any circle, so  the sum can not be less than 1+2 or greater than 9+8+7. Definitely, this is a necessary condition.

And I remove "found" because we have checked fully.  "No solution" is the fact.

[ 本帖最后由 pcqsl 于 2008-4-25 04:31 编辑 ]
回复 不支持

使用道具 举报

 楼主| 发表于 2008-4-25 14:57:35 | 显示全部楼层 来自 江苏无锡
pcqsl,

OK, I send attahced Demo to editor, we wait what they say.

See attachment.

本帖子中包含更多资源

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

×
回复 不支持

使用道具 举报

 楼主| 发表于 2008-4-27 16:25:00 | 显示全部楼层 来自 江苏无锡
pcqsl,

They go back to the previous demonstration design.
but they want to have mutiply dynamic sliders in future.
Good News, they published this demonstration.
http://demonstrations.wolfram.com/PandigitalOlympicCirclesPuzzle/

Cheers !

============================================

Editor's comments

I think we'll stick with the original version. You simply changed thesetter to a slider. That's not the point. Discrete controls are fine aslong as there is a good reason for them. Your concept works better witha discrete control. The point is that was the only control. Its best totry to come up with multiple controls so that more than one thing ischanging and its obvious this isn't just a collection of static slides.This is more obvious with multiple controls or sliders. Just, in the future, remember to try to make these more dynamic.
回复 不支持

使用道具 举报

发表于 2008-5-7 07:22:49 | 显示全部楼层 来自 浙江台州

回复 1# 的帖子

好的,见识一下!
回复 不支持

使用道具 举报

发表于 2008-5-9 10:41:02 | 显示全部楼层 来自 山东威海
厉害厉害!
回复 不支持

使用道具 举报

发表于 2008-5-10 07:52:11 | 显示全部楼层 来自 湖南长沙
hao jianshiyixia
回复 不支持

使用道具 举报

发表于 2008-5-14 17:41:34 | 显示全部楼层 来自 广东广州

nb

nbnbnbnbnb
回复 不支持

使用道具 举报

发表于 2008-6-16 20:07:26 | 显示全部楼层 来自 LAN
顶起来 。。。。。。。。。。。。。
回复 不支持

使用道具 举报

发表于 2008-6-16 20:13:55 | 显示全部楼层 来自 LAN
非常不错
回复 不支持

使用道具 举报

发表于 2008-6-26 22:24:29 | 显示全部楼层 来自 江苏常州

dddd

tdddddd:handshake
回复 不支持

使用道具 举报

发表于 2008-7-19 13:44:50 | 显示全部楼层 来自 山西太原
先顶后看
好东西我会分享的
回复 不支持

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-7 04:04 , Processed in 0.052493 second(s), 19 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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