- 注册时间
- 2021-11-19
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 9178
- 在线时间
- 小时
|
楼主 |
发表于 2025-3-5 08:57:53
|
显示全部楼层
编程穷举
- Clear["Global`*"];(*mathematica11.2,win7(64bit)Clear all variables*)
- aaa=Permutations@Range@9;(*生成所有的1-9的排列,为穷举做准备*)
- bbb=Select[aaa,
- 13
- ==#[[1]]+#[[2]]
- ==#[[2]]+#[[3]]+#[[4]]
- ==#[[4]]+#[[5]]+#[[6]]
- ==#[[6]]+#[[7]]+#[[8]]
- ==#[[8]]+#[[9]]
- &(*过滤条件*)
- ](*根据条件,穷举出所有的可能*)
- ccc={"迎","奥","运","讲","文","明","树","新","风"}
- ddd=Thread[ccc->#]&/@bbb(*汉字与数字对应起来*)
- Grid[ddd,Alignment->Left](*列表显示*)
复制代码
输出结果
{{"迎" -> 4, "奥" -> 9, "运" -> 1, "讲" -> 3, "文" -> 8, "明" -> 2, "树" -> 5, "新" -> 6, "风" -> 7},
{"迎" -> 7, "奥" -> 6, "运" -> 5, "讲" -> 2, "文" -> 3, "明" -> 8, "树" -> 1, "新" -> 4, "风" -> 9},
{"迎" -> 7, "奥" -> 6, "运" -> 5, "讲" -> 2, "文" -> 8, "明" -> 3, "树" -> 1, "新" -> 9, "风" -> 4},
{"迎" -> 9, "奥" -> 4, "运" -> 1, "讲" -> 8, "文" -> 3, "明" -> 2, "树" -> 5, "新" -> 6, "风" -> 7}}
总共也就四组解
\[\begin{array}{lllllllll}
\unicode{8fce}\to 4 & \unicode{5965}\to 9 & \unicode{8fd0}\to 1 & \unicode{8bb2}\to 3 & \unicode{6587}\to 8 & \unicode{660e}\to 2 & \unicode{6811}\to 5 & \unicode{65b0}\to 6 & \unicode{98ce}\to 7 \\
\unicode{8fce}\to 7 & \unicode{5965}\to 6 & \unicode{8fd0}\to 5 & \unicode{8bb2}\to 2 & \unicode{6587}\to 3 & \unicode{660e}\to 8 & \unicode{6811}\to 1 & \unicode{65b0}\to 4 & \unicode{98ce}\to 9 \\
\unicode{8fce}\to 7 & \unicode{5965}\to 6 & \unicode{8fd0}\to 5 & \unicode{8bb2}\to 2 & \unicode{6587}\to 8 & \unicode{660e}\to 3 & \unicode{6811}\to 1 & \unicode{65b0}\to 9 & \unicode{98ce}\to 4 \\
\unicode{8fce}\to 9 & \unicode{5965}\to 4 & \unicode{8fd0}\to 1 & \unicode{8bb2}\to 8 & \unicode{6587}\to 3 & \unicode{660e}\to 2 & \unicode{6811}\to 5 & \unicode{65b0}\to 6 & \unicode{98ce}\to 7 \\
\end{array}\]上面的不知道为什么不显示,我重新整理\[\begin{array}{lllllllll}
迎\to 4 & 奥\to 9 & 运\to 1 & 讲\to 3 & 文\to 8 & 明\to 2 & 树\to 5 & 新\to 6 & 风\to 7 \\
迎\to 7 & 奥\to 6 & 运\to 5 & 讲\to 2 & 文\to 3 & 明\to 8 & 树\to 1 & 新\to 4 & 风\to 9 \\
迎\to 7 & 奥\to 6 & 运\to 5 & 讲\to 2 & 文\to 8 & 明\to 3 & 树\to 1 & 新\to 9 & 风\to 4 \\
迎\to 9 & 奥\to 4 & 运\to 1 & 讲\to 8 & 文\to 3 & 明\to 2 & 树\to 5 & 新\to 6 & 风\to 7 \\
\end{array}\]
|
|