弊社のパズル事情

弊社のパズル事情Our Company's Puzzle Ventures

はじめに

あけましておめでとうございます。昨年のNature Architectsではちょっとしたパズルブームが起こりました。この記事では、特に人気が高かった木組みパズルと箱詰めパズルの2種を取り上げ、3DCAD・3Dプリンタ・最適化ソルバなどを利用した様々なアプローチでパズルに取り組んだ様子を紹介します。

3peace-puzzle
学生時代に友人から借りた木組みパズル。目的は3つのピースを組んだ状態にすること。10年間解けていない。
pla-puzzle-24
2024年最も人気を博したパズル。箱にいれるというシンプルな目標ながら、なかなかの難易度。

twisty-puzzles
ルービックキューブに代表される twisty puzzle。近年の競技用パズルの滑らかさについては過去記事で紹介。
origami-puzzle
折り紙パズル。目的は、折りたたむことで片面は白、もう片面は黒しか見えない状態にすること(左下)。弊社CEOには楽勝だったよう。

木組みパズル

パズルブームの発端は一つの木組みのパズルでした。私が学生の時(10年ほど前)友人から借りて、解けたら返却予定でしたが未だに手元にあります。弊社はパズルが好きな人が多いので、オフィスのサンプル置き場に設置してみました。

3peace-puzzle
3つのピース
pla-puzzle-24
パズルの目的

計算機で並進総当たり

設置後、何人かが手でパズルに取り組みましたが、すぐには解けません。まもなくチーフエンジニアにより3Dデータが作成・共有されました。これにより計算機でパズルに取り組むことが可能となりました。

cad-3-piece-puzzle
3Dデータを作成

パズルを解くためにとった方法は以下です。本来のパズルの楽しみ方ではなくずるい感じもしますが、10年解けてないので手段を選んでいられません。

  1. 組み立て状態(完成状態)を求める
  2. 組立状態から干渉無しで可能な操作で到達できる状態を列挙
  3. 分解状態まで到達する操作が見つかったら、それを逆順にすることで組み立て手順を得る

上記手順の結果、2つの完成状態と、そこから遷移可能な4状態が発見されました。しかしながら、分解状態までは到達することができず、並進のみの操作によっては解けないことが明らかになりました。

disasembly-graph
完成状態とそこから各手数で遷移可能な状態。干渉は各立方体の中心点の重なりで判定。

インターロッキングパズル

エンジニアの一人から、類似のパズルを生成するアルゴリズムに関するの論文[1]を教えてもらいました。

それによると、今回取り組んでいる木組みのパズルは、業界ではインターロッキングパズルと呼ばれいていて、1つ目の部品が外れるまでの手数をパズルのレベルと呼ぶようです。

インターロッキングパズルを解く手順を見つけることはNP困難に属する問題であり、ブロックの数が増えると組み合わせが爆発的大きくなりますが、今回のサイズにおいては簡単に列挙可能でした。

文献では任意のレベルのパズルを効率的に生成する方法が紹介されていて、ソフトウェアも公開されていました。せっかくなので、6手で外れる弊社ロゴマークのパズルを生成してみました(冒頭カバー画像)。

N-puzzle
パズル生成アルゴリズムによって得られたN形状。これの外形を削ってカバー画像のパズルを作成。

上記文献においても、パズルの操作としては並進のみが扱われていました。回転を考慮した研究もなくはないようですが、干渉の判定のの計算が難しくなるため、計算機で扱うことが非常に困難と予想されました。

3Dプリンタの利用

さて先程の木組みパズルですが、回転の操作の考慮は計算機では困難と判断し、完成状態を3Dプリントして外す方法を探りました。

造形品を動かすことで、先程列挙した状態に加え、回転動作で到達できる状態がいくつか発見されましたが、残念ながらこの方法でも解は見つかりませんでした。

3peace-puzzle
クリアランスと造形の角度をうまく調整することで一般的なFDMのプリンタでの造形が可能。
pla-puzzle-24
造形された完成状態の候補2種。

本当に解はある?

あまりの困難さに、貸してくれた方に連絡してみたところ、

「父が趣味で作ったもので、もしかしたら設計が間違っているかも。しかし、一度解けたことがあるような気がする。」とのこと。

設計が間違っているか、あるいは残る可能性としては回転を含む動きで試せていないものがあるかいずれかです。後者がない可能性を証明することは困難ですが、前者の可能性が高いのではというのが現時点での認識です。

後日わかったのですが、以下のサイトに良く似たパズルがあるので、これを元にした可能性が高いです。サイトに記載のパズルは回転を使うととけるよう巧妙に設計されていました。
https://puzzlewillbeplayed.com/555Cross/Okey3PieceBurr/

結論として解けてないのは残念ですが、奥深いインターロッキングパズルの世界に触れることができ、かなり楽しむことができました。

printed-yamamotos-puzzle
おそらくこれがオリジナルか。Design and Copyright : 山本長徳 (Osanori Yamamoto) (2008) .

[2]

箱詰めパズル

pla-puzzle-24
プラパズルNo.24 (発売年1963~?)

[3]

2024年社内で最も流行ったパズルは間違いなくこれでしょう。パズルの目的は24個のピースを箱に詰めることです。

弊社CTOが骨董市で購入したそうで、フタに書かれた文字のフォントが時代を感じさせます。電子計算機と結びついているそうなので、計算機との共創を掲げる弊社としては取り組まざるを得ません。

正三角形を連結してできる図形はポリイアモンドとよばれます[4]。7枚のポリイアモンド(ヘプタモンド)には24種類ありますが、そのすべてを一枚ずつ使っているところがこのパズルの美しいところです。

何人か挑戦しましたが、人間で解けたのはエンジニアYさんのみ(ブログ公開時点)。残り2~3まで詰めた後、部品を入れ替えながら解を探っていく手法のようです。

計算機で解く

計算機で解いてみます。こちらもチーフエンジニアにより即座に3Dモデルが作られました。

cad-pla-puzzle-24
3Dデータを作成

はじめ、何人かのエンジニアが本業でよく使用するCAD環境のRhinoceros/Grasshopper + 最適化ツールtunnyを使って解こうと試みましたが、困難でした。そもそもtunnyで使用できるのは関数の性質がわかっていない場合に用いられるブラックボックス最適化であり、今回のような中身のわかっている問題については、もっと適した手法がありそうです。

文献[5]によると、パズル用のソルバとしてはburrtoolsがよく用いられるが、このような問題に対しては整数計画法向けの汎用ソルバのほうが高速とのことです。今回はオープンソースの混合整数計画問題向けのツールであるPython-MIP[7] を用いることにします。

先程の文献を参考に、以下のように定式化しました。各ピースの形状が異なる点が文献とは異なるので、制約2を追加しています。

  1. 箱形状を構成する各正三角形に番号をふる 0 ~ 167 (下の図)
  2. 変数
    • 部品iの可能な置き方を、盤面の番号を用いた2値変数 \(p_i(a,b,c,d,e,f,g)\)で表す
      (ただし表現を一意にするために \(a < b < c < d < e < f < g\) )。
    • 変数の値が1であれば部品が配置され、0であれば配置されていないことを表す。
    • 例えば部品0が(下の図の黄色)のように置かれているとき、\(p_0(0,5,6,16,17,18,34)=1\)となる。
    • 変数の数は全部品の全配置方法の数となる。全13667個。
  3. 下記を満たすことがパズルの解の必要十分条件
    • 制約条件1:(すべての場所ちょうど1枚のピースが覆う)
      • 場所0に関する制約式:
        (場所0を埋めるすべての置き方に対応した変数の和) = 1
        つまり、\(p_0(0,5,6,16,17,18,34) + p_0(0,6,7,18,19,20,38) +… =1\)
      • 場所1に関する制約式:
        (場所1を埋めるすべての置き方に対応した変数の和) = 1
      • ……
    • 制約条件2:(すべての部品を1度ずつ使用)
      • 部品0に関する制約式:
        (部品0のすべての置き方に対応した変数の和) = 1
        つまり、\(p_0(0,5,6,16,17,18,34) + p_0(0,6,7,18,19,20,38) +… =1\)
      • 部品1に関する制約式:
        (部品1のすべての置き方に対応した変数の和) = 1
      • ……

cad-pla-puzzle-24
p_1(0,5,6,16,17,18,34)=1のピース配置。

実装は、Rhino/Grasshopper上で形状を元にソルバに与える情報を準備し、pythonコンポーネント上で解いた後、Rhino/Grasshopperで可視化する構成としました。

cad-pla-puzzle-24
Grasshopper上での構成

実行した結果、ラップトップPCで10分程度で解を得ることができました。

今回、変数が13667個あるので、総当たりだと2^13667=1.50297×10^4114 通りとなり現実的ではないですが、python-MIPで使用されるCBCと呼ばれるアルゴリズムが非常に優秀で解を発見できていることは興味深いです。

また、実行速度から想像するに、人間はさらに効率の良いアルゴリズムで解いていることが予想され、計算機上での探索は改良の余地がありそうです。

さいごに

私は普段非線形性の高い解析をやることが多く、最適化ではブラックボックス最適化を使いがちだったので、問題によって正しく使い分ける重要性を再認識でき、非常に勉強になりました。

今後も、おもしろいパズルがあれば手と計算機で味わっていきたいと思います。

参考文献

[1] Rulin Chen and Ziqi Wang and Peng Song and Bernd Bickel. "Computational Design of High-level Interlocking Puzzles". ACM Transactions on Graphics (SIGGRAPH). 2022. https://sutd-cgl.github.io/supp/Publication/projects/2022-SIGGRAPH-High-LevelPuzzle/index.html

[2] puzzlewillbeplayed.com. "Okey 3 Piece Burr". https://puzzlewillbeplayed.com/555Cross/Okey3PieceBurr/. (2025/01/17閲覧)

[3] 株式会社テンヨー. "テンヨーの歩み". https://tenyo.jp/history.html. (2025/01/17閲覧)

[4] ウィキペディア. "ポリイアモンド". https://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%AA%E3%82%A4%E3%82%A2%E3%83%A2%E3%83%B3%E3%83%89. (2025/01/17閲覧)

[5] Mutsunori Banbara, Kenji Hashimoto, Takashi Horiyama, Shin-ichi Minato,
Kakeru Nakamura, Masaaki Nishino, Masahiko Sakai, Ryuhei Uehara,
Yushi Uno, Norihito Yasuda, "レプ・タイルの定式化を用いた各種ソルバの性能比較", 工知能基本問題研究会 SIG-FPAI-119-01, 2022, https://www.jstage.jst.go.jp/article/jsaifpai/119/0/119_02/_pdf

[6] @miso_taku, "Python mipライブラリを使った数理最適化", https://qiita.com/miso_taku/items/be16af812f3d81486bd4, (2025/01/17閲覧)

[7] Python-MIP, https://www.python-mip.com/, (2025/01/17閲覧)

Introduction

Happy New Year! Last year, a small puzzle boom occurred at Nature Architects. In this article, we will focus on two particularly popular puzzles: a wooden assembly puzzle and a packing puzzle. We will showcase various approaches to tackling these puzzles using tools like 3D CAD, 3D printers, and optimization solvers.

3peace-puzzle
A wooden assembly puzzle borrowed from a friend during my student days. The goal is to assemble the three pieces. It has remained unsolved for 10 years.
pla-puzzle-24
The most popular puzzle of 2024. Despite its simple goal of fitting the pieces into the box, it is quite challenging.

twisty-puzzles
Twisty puzzles, represented by the Rubik's Cube. The smoothness of modern competitive puzzles has been covered in previous articles.
origami-puzzle
An origami puzzle. The goal is to fold it so that one side is entirely white and the other side is entirely black (bottom left). It seems our CEO found it very easy.

Wooden Assembly Puzzle

The puzzle boom began with a single wooden assembly puzzle. I borrowed it from a friend during my student days (about 10 years ago) with the intention of returning it once solved, but it is still in my possession. Since many in our company love puzzles, I placed it in the office sample area.

3peace-puzzle
Three pieces
pla-puzzle-24
Puzzle goal

Exhaustive Search with a Computer

After its placement, a few people attempted the puzzle by hand but could not solve it immediately. Soon after, our chief engineer created and shared 3D data, enabling computational approaches to tackle the puzzle.

cad-3-piece-puzzle
3D data created

The steps taken to solve the puzzle are as follows. While this approach might feel like cheating and not in the spirit of the puzzle, after 10 years of failure, no means could be spared:

  1. Identify the assembled (completed) state.
  2. Enumerate all possible states reachable from the completed state without interference.
  3. If a disassembled state is reached, reverse the sequence to obtain the assembly steps.

As a result of the above steps, two completed states and four states reachable from them were discovered. However, a disassembled state could not be reached, making it clear that the puzzle cannot be solved using translational movements alone.

disasembly-graph
Completed states and reachable states with each step. Interference was determined based on overlapping cube centers.

Interlocking Puzzles

One of our engineers introduced a paper [1] about algorithms for generating similar puzzles.

According to the paper, the wooden assembly puzzle we tackled is referred to in the industry as an "interlocking puzzle." The number of steps required to remove the first piece is called the puzzle's "level."

Finding the steps to solve an interlocking puzzle is classified as an NP-hard problem. As the number of blocks increases, the combinations grow exponentially. However, for the size of our puzzle, it was relatively easy to enumerate all possibilities.

The paper introduced a method for efficiently generating puzzles of any level, and the associated software was made publicly available. Taking advantage of this, we generated a company logo puzzle that can be disassembled in six steps (featured in the cover image).

A shape generated by the puzzle generation algorithm. The outer shape was trimmed to create the cover image puzzle.

N-puzzle
A shape generated by the puzzle generation algorithm. The outer shape was trimmed to create the cover image puzzle.

The paper also dealt with translational movements as the sole operation for solving puzzles. While studies considering rotational movements do exist, interference detection becomes significantly more complex, making computational handling extremely challenging.

Using a 3D Printer

As for the wooden assembly puzzle, it was deemed computationally difficult to consider rotational operations. Instead, we explored the possibility of disassembling the puzzle by 3D printing the completed state.

By manipulating the printed models, we discovered several new states reachable through rotational movements in addition to the translational ones. Unfortunately, no solution was found even with this approach.

3peace-puzzle
By adjusting clearance and print angles, the models could be created using a standard FDM printer.
pla-puzzle-24
Two candidate completed states created via 3D printing.

Does a Solution Exist?

Frustrated by the difficulty, I contacted the friend who lent me the puzzle. They said:

"My father made it as a hobby, so the design might be flawed. However, I feel like it was solvable at some point."

The puzzle may indeed be flawed, or there might be some unexplored possibilities involving rotational movements. While proving the latter is unlikely is difficult, we currently believe the former is more probable.

Later, we discovered a puzzle on the following website that closely resembles this one. The puzzle described on the site is cleverly designed to be solved with rotational movements: https://puzzlewillbeplayed.com/555Cross/Okey3PieceBurr/

In conclusion, it is unfortunate that we could not solve the puzzle. However, we had a lot of fun exploring the fascinating world of interlocking puzzles.

printed-yamamotos-puzzle
This might be the original. Design and Copyright: Osanori Yamamoto (2008).

[2]

Packing Puzzle

pla-puzzle-24
Pla Puzzle No.24 (Release year: 1963~?)

[3]

The most popular puzzle in 2024 within the company was undoubtedly this one. The goal of the puzzle is to fit 24 pieces into the box.

Our CTO purchased it at an antique market, and the font on the lid evokes a sense of its era. Since the puzzle has ties to electronic computing, we felt compelled to tackle it as a company committed to human-computer collaboration.

The shapes formed by connecting equilateral triangles are called polyiamonds [4]. There are 24 types of 7-piece polyiamonds (heptiamonds), and what makes this puzzle beautiful is that each piece is used exactly once.

Several people attempted to solve it, but the only successful human solver (as of the blog publication date) was Engineer Y. The approach seemed to involve filling in 2-3 remaining pieces, swapping parts, and gradually finding the solution.

Solving with a Computer

We attempted to solve the puzzle computationally. Once again, our chief engineer promptly created a 3D model.

cad-pla-puzzle-24
3D data created

Initially, some engineers tried solving it using the CAD environment Rhinoceros/Grasshopper and the optimization tool Tunny, which they frequently use in their work. However, this approach proved difficult. Tunny is a black-box optimization tool typically used for problems with unknown function properties. For a problem like this, where the inner workings are clear, a more suitable approach seemed necessary.

According to a paper [5], burrtools is commonly used as a solver for puzzles, but for problems like this one, general-purpose solvers for integer programming are faster. Therefore, we decided to use Python-MIP, an open-source tool for mixed-integer programming.

Referring to the paper, we formulated the problem as follows. One difference from the paper was that the shapes of the pieces in our puzzle are all distinct, so we added an additional constraint.

  1. Assign a number (0–167) to each equilateral triangle in the box shape (see diagram below).
  2. Variables
    • The possible placements of piece i are represented using binary variables \(p_i(a,b,c,d,e,f,g)\) based on the triangle numbers on the board.
      (To ensure unique representation, \(a < b < c < d < e < f < g\).)
    • A variable value of 1 indicates that the piece is placed, while 0 indicates it is not.
    • For example, if piece 0 is placed as shown in the yellow area below, \(p_0(0,5,6,16,17,18,34)=1\).
    • The total number of variables equals the total number of placement options for all pieces: 13,667 in total.
  3. The following conditions are necessary and sufficient for solving the puzzle:
    • Constraint 1: (Every location is covered by exactly one piece)
      • Constraint for location 0:
        (The sum of variables corresponding to all placements covering location 0) = 1
        That is, \(p_0(0,5,6,16,17,18,34) + p_0(0,6,7,18,19,20,38) + … = 1\).
      • Constraint for location 1:
        (The sum of variables corresponding to all placements covering location 1) = 1
      • ……
    • Constraint 2: (Every piece is used exactly once)
      • Constraint for piece 0:
        (The sum of variables corresponding to all placements of piece 0) = 1
        That is, \(p_0(0,5,6,16,17,18,34) + p_0(0,6,7,18,19,20,38) + … = 1\).
      • Constraint for piece 1:
        (The sum of variables corresponding to all placements of piece 1) = 1
      • ……

cad-pla-puzzle-24
Placement of p_1(0,5,6,16,17,18,34)=1

The implementation involved preparing solver input based on the shapes in Rhino/Grasshopper, solving the problem with a Python component, and visualizing the solution in Rhino/Grasshopper.

cad-pla-puzzle-24
Configuration in Grasshopper

The solution was found in about 10 minutes on a laptop PC.

cad-pla-puzzle-24
The discovered solution

With 13,667 variables, a brute-force search would require evaluating 2^13,667 = 1.50297×10^4114 combinations, which is impractical. However, the CBC algorithm used by Python-MIP proved to be highly efficient in finding the solution, which is quite remarkable.

From the observed execution speed, it seems likely that humans use an even more efficient algorithm to solve such puzzles. This suggests there is room for further improvement in computational search methods.

Conclusion

In my usual work, I often deal with highly nonlinear analyses and tend to rely on black-box optimization. This experience has been a valuable reminder of the importance of choosing the right method for each problem.

Going forward, I plan to continue enjoying intriguing puzzles with both manual and computational approaches.

References

[1] Rulin Chen, Ziqi Wang, Peng Song, and Bernd Bickel. "Computational Design of High-level Interlocking Puzzles." ACM Transactions on Graphics (SIGGRAPH), 2022. https://sutd-cgl.github.io/supp/Publication/projects/2022-SIGGRAPH-High-LevelPuzzle/index.html.

[2] puzzlewillbeplayed.com. "Okey 3 Piece Burr." https://puzzlewillbeplayed.com/555Cross/Okey3PieceBurr/. (Accessed: January 17, 2025).

[3] Tenyo Co., Ltd. "History of Tenyo." https://tenyo.jp/history.html. (Accessed: January 17, 2025).

[4] Wikipedia. "Polyiamond." https://en.wikipedia.org/wiki/Polyiamond. (Accessed: January 17, 2025).

[5] Mutsunori Banbara, Kenji Hashimoto, Takashi Horiyama, Shin-ichi Minato, Kakeru Nakamura, Masaaki Nishino, Masahiko Sakai, Ryuhei Uehara, Yushi Uno, Norihito Yasuda. "Performance Comparison of Various Solvers Using Formulation of Rep-Tiles." SIG-FPAI-119-01, 2022. https://www.jstage.jst.go.jp/article/jsaifpai/119/0/119_02/_pdf.

[6] @miso_taku. "Mathematical Optimization with Python-MIP Library." https://qiita.com/miso_taku/items/be16af812f3d81486bd4. (Accessed: January 17, 2025).

[7] Python-MIP. https://www.python-mip.com/. (Accessed: January 17, 2025).

Author