A Snake Egg Puzzle Solver

栏目: IT技术 · 发布时间: 5年前

内容简介:A Sentient program to solve Snake Egg puzzles. The puzzle is explained inThe example puzzle from the YouTube video is in the

Snake Egg puzzle

A Sentient program to solve Snake Egg puzzles. The puzzle is explained in this YouTube video .

Sentient is a programming language I wrote a few years ago to solve difficult combinatorial problems. This seemed like a fun and unusual problem so I thought I'd try using Sentient to solve it. It was definitely a challenge and required thinking hard about some tricky constraints but it works!

The example puzzle from the YouTube video is in the example/ directory. You can solve this puzzle with Sentient by providing assignments that specify the head/tail positions of the snake and the two numbers given to you for this puzzle. Here's how you'd do that:

sentient --run snake-egg.json --machine lingeling --assign-file example/assignments.json \
         | ruby pretty_print.rb

This produces the following output after about two minutes:

9 9 █ █ █ 7 █ █ █ █
9 9 9 9 █ 7 █ 5 5 █
█ █ █ 9 █ 7 █ █ 5 █
2 2 █ 9 █ 7 7 █ 5 █
█ █ █ 9 █ 7 █ █ 5 █
█ 8 8 █ █ 7 █ 4 █ █
█ █ 8 █ 1 █ █ 4 █ 6
3 █ 8 █ █ █ 4 4 █ 6
3 █ 8 8 8 8 █ █ █ 6
3 █ █ █ █ █ █ 6 6 6

Alternatively, you can create your own assignments to solve different puzzles or run Sentient with no assignments at all to generate finished puzzles! Check out the comments in the snake-egg.snt file for a general overview of how the constraints are specified.

There's also a search_minimal.rb script that takes, as input, a finished puzzle and tries to find the minimal sets of numbers that produce it as a unique solution. This is very time consuming - it iteratively solves the puzzle over and over.

Gallery

Here are some finished puzzles generated by Sentient:

1) Smiley Face                 2) TWO!                     3) THREE!                  4) Squirrel

█ █ █ 2 █ █ █ █ █ █         █ █ █ █ 1 █ █ █ 4 4         █ █ █ █ █ █ █ █ █ 8         █ █ █ 8 8 █ █ █ █ 1
█ 9 █ 2 █ 5 5 5 5 █         █ 2 2 █ █ 7 7 █ 4 4         █ 9 9 9 9 9 9 9 █ 8         █ 6 █ 8 8 █ 5 5 █ █
█ 9 █ █ █ 5 █ █ █ █         █ █ █ 9 █ █ 7 █ █ █         █ █ █ 9 9 █ █ █ █ 8         █ 6 █ 8 █ █ 5 5 5 █
█ 9 9 9 9 █ █ 8 8 8         9 9 █ 9 9 █ 7 7 7 █         6 6 █ █ █ 8 8 8 8 8         █ 6 █ 8 █ 9 █ █ █ █
█ █ █ █ 9 █ 8 8 8 8         9 9 9 9 █ █ 7 █ █ █         6 6 6 6 █ █ █ █ █ █         █ 6 █ 8 █ 9 █ 3 3 3
7 7 7 █ 9 █ 8 █ █ █         █ █ █ █ █ 8 █ █ 5 5         █ █ █ █ 7 7 7 7 7 █         █ 6 █ 8 █ 9 █ █ █ █
7 7 7 █ 9 █ █ █ 1 █         █ 8 8 8 8 8 █ 5 5 5         █ 2 2 █ █ 7 █ █ 7 █         █ 6 █ █ █ 9 9 9 9 █
█ █ 7 █ █ 6 6 6 █ █         █ 8 █ █ █ 8 █ █ █ █         █ █ █ 5 █ █ █ 1 █ █         █ █ 4 4 4 █ █ █ 9 9
3 █ █ 6 6 6 █ █ █ 4         █ █ █ 6 █ █ 3 3 3 █         4 4 █ 5 5 5 5 █ █ 3         2 █ 4 █ █ █ 7 █ █ █
3 3 █ █ █ █ █ 4 4 4         6 6 6 6 6 █ █ █ █ █         4 4 █ █ █ █ █ █ 3 3         2 █ █ █ 7 7 7 7 7 7



    5) FIVE!                  6) Raised Hands                7) Poodle                  8) Doberman

6 6 6 6 █ █ █ █ █ █         2 █ █ █ 1 █ █ █ 3 3         █ █ █ █ 6 6 █ █ █ █         6 6 6 6 6 █ 4 █ █ █
6 6 █ █ █ 4 4 4 4 █         2 █ 5 █ █ 4 4 █ █ 3         █ 7 7 █ 6 6 █ 3 3 █         █ █ █ 6 █ █ 4 █ 3 █
█ █ █ 7 7 █ █ █ █ █         █ █ 5 5 █ █ 4 4 █ █         █ 7 7 █ 6 █ █ 3 █ █         █ 1 █ █ █ 4 4 █ 3 █
█ 7 7 7 7 █ 5 5 5 5         █ 8 █ 5 5 █ █ █ 7 █         █ 7 7 █ 6 █ 8 █ █ 9         █ █ 9 9 9 █ █ █ 3 █
█ █ █ █ 7 █ █ █ █ 5         █ 8 █ █ █ 9 9 █ 7 █         █ █ 7 █ █ █ 8 █ 9 9         2 █ 9 █ █ █ 7 7 █ █
3 3 3 █ █ 9 9 9 █ █         █ 8 8 8 █ 9 █ █ 7 █         1 █ █ 8 8 8 8 █ 9 9         2 █ 9 █ 8 8 █ 7 █ 5
█ █ █ 1 █ █ █ 9 9 █         █ █ █ 8 █ 9 █ 7 7 █         █ 4 █ 8 █ █ 8 █ █ 9         █ █ 9 █ 8 █ █ 7 █ 5
█ 8 █ █ 2 2 █ 9 9 █         6 6 █ 8 █ 9 █ █ 7 █         █ 4 █ █ 5 █ █ 2 █ 9         █ 9 9 █ 8 █ 7 7 █ 5
█ 8 8 █ █ █ █ 9 9 █         6 6 █ 8 █ 9 9 █ 7 █         █ 4 4 █ 5 5 █ 2 █ 9         █ 9 █ █ 8 █ █ 7 █ 5
█ █ 8 8 8 8 8 █ █ █         6 6 █ █ █ 9 9 █ █ █         █ █ █ █ 5 5 █ █ █ 9         █ █ █ 8 8 8 █ █ █ 5



  9) Angry Face              10) Confused Face            11) MechWarrior             12) Tall Boots

7 7 █ █ █ 3 3 █ █ █         █ █ █ 4 4 4 █ █ █ █         3 3 3 █ █ █ 4 █ █ █         6 6 █ █ █ 1 █ █ █ █
7 7 █ 9 █ █ 3 █ 2 █         █ 9 █ 4 █ █ █ 6 6 █         █ █ █ █ 7 █ 4 █ 6 █         6 6 █ 8 █ █ █ 4 4 █
7 7 █ 9 9 █ █ █ 2 █         █ 9 █ █ █ 6 6 6 6 █         █ 7 7 7 7 █ 4 █ 6 █         6 6 █ 8 8 8 8 █ 4 █
7 █ █ 9 9 9 9 9 █ █         █ 9 9 9 9 █ █ █ █ █         █ █ █ 7 7 █ 4 █ 6 █         █ █ █ 8 █ 8 █ █ 4 █
█ █ 8 █ █ █ 9 █ █ 4         █ █ █ █ 9 █ 8 8 8 8         8 8 █ █ █ 9 █ █ 6 █         █ 7 7 █ █ 8 █ 9 █ █
█ 8 8 █ 6 █ █ █ 4 4         7 7 7 █ 9 █ 8 8 8 8         8 8 8 8 █ 9 █ 6 6 █         █ 7 7 █ 5 █ █ 9 █ 2
█ 8 █ █ 6 6 6 6 █ 4         7 7 7 █ 9 █ █ █ █ █         8 8 █ █ █ 9 █ █ █ 5         █ █ 7 █ 5 █ 9 9 █ 2
█ 8 8 8 █ █ █ 6 █ █         █ █ 7 █ █ 5 5 5 5 █         █ █ █ 9 9 9 9 9 █ 5         3 █ 7 █ 5 █ 9 9 █ █
█ 8 █ █ █ 5 █ █ 1 █         3 █ █ 2 2 █ █ █ 5 █         █ 2 2 █ █ █ 9 █ █ 5         3 █ 7 █ 5 █ 9 9 9 █
█ █ █ 5 5 5 5 █ █ █         3 3 █ █ █ █ 1 █ █ █         █ █ █ █ 1 █ █ █ 5 5         3 █ █ █ 5 █ █ █ █ █



  13) Octopus                  14) Werewolf                15) Antennae               16) Steam Train

█ █ █ 4 █ █ █ █ █ 9         █ █ █ 8 █ █ █ 5 5 5         █ █ █ 3 █ █ █ █ 6 6         7 7 █ █ █ 1 █ █ █ █
█ 4 4 4 █ 6 6 6 █ 9         █ 9 █ 8 8 8 █ █ 5 5         █ 9 █ 3 █ 4 4 █ 6 6         7 7 █ 9 █ █ █ 2 2 █
█ █ █ █ █ 6 █ 6 █ 9         █ 9 █ 8 █ 8 8 █ █ █         █ 9 █ 3 █ █ 4 █ 6 6         7 7 █ 9 9 9 9 █ █ █
7 7 7 7 7 █ █ 6 █ 9         █ 9 █ 8 █ █ █ 7 7 █         █ 9 █ █ 2 █ 4 █ █ █         7 █ █ 9 9 █ █ █ 8 8
█ █ █ █ 7 █ 8 █ █ 9         █ 9 █ █ 6 6 █ 7 █ █         █ 9 9 █ 2 █ █ 5 5 █         █ █ 9 9 █ █ 8 8 8 8
█ 3 3 █ 7 █ 8 █ 9 9         █ 9 9 █ 6 6 █ 7 █ 1         █ █ 9 █ █ 8 █ █ 5 █         █ 6 █ █ █ 8 8 █ █ █
█ █ 3 █ █ █ 8 █ 9 9         █ 9 9 █ 6 6 █ 7 █ █         7 █ 9 9 █ 8 8 █ 5 █         █ 6 █ 4 4 █ █ █ 5 █
5 █ █ 8 8 8 8 █ █ █         █ █ 9 █ █ █ █ 7 7 █         7 █ █ 9 █ █ 8 █ 5 █         █ 6 █ 4 █ █ 5 5 5 █
5 5 █ 8 █ █ █ 2 2 █         3 █ █ 4 4 4 4 █ █ █         7 7 █ █ 8 8 8 8 █ █         █ 6 █ 4 █ 3 █ █ 5 █
5 5 █ █ █ 1 █ █ █ █         3 3 █ █ █ █ █ █ 2 2         7 7 7 █ █ █ █ █ █ 1         6 6 █ █ █ 3 3 █ █ █



   17) Rabbit                   18) Kissing               19) Hang Glider

1 █ █ █ █ █ 7 7 █ █         3 █ █ █ █ 1 █ █ █ █         5 5 5 █ █ █ █ █ █ █
█ █ 3 3 3 █ █ 7 7 █         3 █ 7 7 7 █ █ 9 9 █         5 5 █ █ 9 9 9 9 9 █
█ 8 █ █ █ 4 █ █ 7 █         3 █ 7 7 █ █ 9 9 9 █         █ █ █ 9 9 █ █ █ █ █
█ 8 █ 2 █ 4 4 █ 7 █         █ █ 7 7 █ 2 █ █ 9 █         █ 6 6 █ 9 █ 8 8 8 8
█ 8 █ 2 █ 4 █ █ 7 █         █ 5 █ █ █ 2 █ 9 9 █         █ █ 6 █ 9 █ █ 8 8 8
█ 8 █ █ 9 █ █ 5 █ █         █ 5 █ 6 6 █ █ 9 █ █         3 █ 6 █ █ 1 █ █ █ 8
█ 8 8 █ 9 █ 5 5 █ 6         █ 5 █ 6 █ █ 4 █ █ 8         3 █ 6 6 █ █ 7 7 █ █
█ 8 8 █ 9 █ 5 █ █ 6         █ 5 █ 6 █ 4 4 █ 8 8         3 █ █ █ 4 █ 7 7 7 █
█ █ █ █ 9 █ 5 █ 6 6         █ 5 █ 6 █ 4 █ █ 8 8         █ 2 2 █ 4 █ █ 7 7 █
9 9 9 9 9 █ █ █ 6 6         █ █ █ 6 █ █ █ 8 8 8         █ █ █ █ 4 4 █ █ █ █

以上所述就是小编给大家介绍的《A Snake Egg Puzzle Solver》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

用户力:需求驱动的产品、运营和商业模式

用户力:需求驱动的产品、运营和商业模式

郝志中 / 机械工业出版社 / 2015-11-1 / 59.00

《用户力:需求驱动的产品、运营和商业模式》从用户需求角度深刻阐释了互联网产品设计、网络运营、商业模式构建的本质与方法论! 本书以“用户需求”为主线,先用逆向思维进行倒推,从本质的角度分析了用户的需求是如何驱动企业的产品设计、网络运营和商业模式构建的,将这三个重要部分进行了系统性和结构化的串联,然后用顺向思维进行铺陈,从实践和方法论的角度总结了企业究竟应该如围绕用户的真实需求来进行产品设计、网......一起来看看 《用户力:需求驱动的产品、运营和商业模式》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具