Skip to content

Commit

Permalink
Merge pull request #45 from jwg4/jupyter_support
Browse files Browse the repository at this point in the history
Jupyter support
  • Loading branch information
jwg4 authored Dec 20, 2023
2 parents 202551d + 692376c commit 1eb5e50
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is a package for manipulating polyominos and in particular, solving tiling

To solve a tiling problem, you need to create a 'board', the set of squares to be covered, and a 'tileset', the collection of polyominos which can be used. There are examples of the syntax to do this in examples/fluid.md The example file examples/gardner.md uses the package to solve a number of problems from the chapter on polyominos from Martin Gardner's book 'Mathematical Puzzles and Diversions'.

The folder examples/ also has a couple of Jupyter notebooks: these show how you can work with basic boards and solutions, and how they can be displayed in a notebook. The notebook display should work out-of-the-box.

Note that each tile can play one of several roles in a tiling problem. It could be a tile which can only appear once, as in problems like covering a chessboard with one copy of each pentomino and a square tetromino. It could be a tile which can be used an arbitrary number of times. Problems like this are often simply to cover a shape completely with copies of a single polyomino. Finally, it could be used either once or not at all. When constructing a tileset, it is possible to include tiles in any of these three classes.

## Design
Expand Down
6 changes: 6 additions & 0 deletions examples/.ipynb_checkpoints/display_boards-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
134 changes: 134 additions & 0 deletions examples/.ipynb_checkpoints/display_solutions-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c5f94563",
"metadata": {},
"outputs": [],
"source": [
"from polyomino.board import Chessboard, Irregular\n",
"from polyomino.constant import TETROMINOS, ALL_PENTOMINOS"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a990b439",
"metadata": {},
"outputs": [],
"source": [
"solution = Chessboard().tile_with(ALL_PENTOMINOS + [TETROMINOS['Square']]).solve()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "24061091",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAAKlBMVEUAAADHAmpXhq27nv0P09O+aOhDO+yTXJ/3b0Je9l31av2rSvJGyVnRuL77hKSIAAAAYklEQVR4nO3Mtw3AMBAEQULekOq/XGXP5HCQ0udOAVOmMP+2CIWQMHmorBYh4TjhFnyzh8MiJMweertFSJg9PIXrI0LCccI7qLqG3rTwCISE2UNV97BZhIQjhtVSDSFh8vAFbS7Jkaszv9kAAAAASUVORK5CYII=\n",
"text/plain": [
"<polyomino.solution.Solution at 0x6f537fe8>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"solution"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "076e18a7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+-+-+-+-+-+-+-+-+\n",
"| | | |\n",
"+ +-+-+-+-+-+ +\n",
"| | | |\n",
"+-+ +-+ +-+-+-+-+\n",
"| | | | | |\n",
"+ +-+-+-+ +-+-+ +\n",
"| | | |\n",
"+-+-+-+-+-+-+ + +\n",
"| | | | |\n",
"+-+ +-+-+ +-+-+-+\n",
"| | | | | | |\n",
"+ +-+ + +-+ +-+ +\n",
"| | | | | |\n",
"+ +-+ +-+ +-+ +\n",
"| | | | |\n",
"+-+-+-+-+-+-+-+-+\n"
]
}
],
"source": [
"print(solution.display())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "45085dd3",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHgAAACgCAMAAADw11iiAAAAk1BMVEUAAACBwY3ac/hk0/mbAEoJ9QGTXJ7ydEoWUaeNs7AXWTtcDgONxtiUs2IrEdqBgtgbhHCs6SGq72YpD6d4r8iWYLJ1mXWi2op3zdOIlOALFnivsiUhhdoFzLH3PGk3RDY4tweuj5Rka49aRhpf1ElPVhqFkRlyJ7oUG+/958OetdD6VNMXulL7EKfxKRLFMco+FIFhhjlHAAABL0lEQVR4nO3OSVJCURQEUcNeOhUUBLEDsRdk/5tzVjWpeIMfd5i5gZMHh82O1HGzE3WqzpodAAMDA3eGz1Xi3IVKXILTQk8BAwMDV8CurxLsBirBQ9ULAQMDA1fA/WbmRmoQGoYuFTAwMHAFfNXsWo1C5sZqohLsgIGBgbvDNypx7lYZHocmIXNTBQwMDFwBu5lKsLtTCZ6raQgYGBi4Al6oWShxqXnoXgEDAwNXwIuQuaV6aPaonlSCHTAwMHB3+FkZXoZeVOIS7MytFDAwMHAF7NYqwe5VJXijViFgYGDgCnjdLHGpTehNAQMDA1fA780+1GezL/WtEuyAgYGBu8M/KnHuVyUuwc7cVgEDAwNXwG6nEuz+VIL3ahsCBgYGroB3zRKX2jcDBgYGLoD/ASi7eOqIz7E2AAAAAElFTkSuQmCC\n",
"text/plain": [
"<polyomino.solution.Solution at 0x6f59b5e0>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"board = Irregular([(i, j) for i in range(0, 12) for j in range(0, 16)])\n",
"problem = board.tile_with_many(TETROMINOS['T'])\n",
"problem.solve()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba1efa04",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
154 changes: 154 additions & 0 deletions examples/display_boards.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "2f48725f",
"metadata": {},
"outputs": [],
"source": [
"from polyomino.board import Chessboard\n",
"from polyomino.constant import DOMINO"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "325f7427",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAMAAAC45U6nAAAABlBMVEX///8AAABVwtN+AAAAV0lEQVR4nO3ZyQ0AIAgAQe2/aTsgGokHmS2A4eNHWpP0Wj2n2MjZlMFgLE2ZfaFbRspkBoPBYDAYDAaDwWAwGAwGg8FgMKob8a/93xcJBqOAceBqLulGA1OUAUFeFCJvAAAAAElFTkSuQmCC\n",
"text/plain": [
"<polyomino.board.DeletedRectangle at 0x6f56ef58>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Chessboard().remove((0, 0)).remove((7, 7))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c9cc6b80",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAMAAAC45U6nAAAABlBMVEX///8AAABVwtN+AAAAV0lEQVR4nO3ZsQ0AIAgAQdx/aTcwGJFQ3LcmnI2NREia1qrpbNTclMFgXE3JvtAno2Qyg8FgMBgMBoPBYDAYDAaDwWAwGIONhv/27CmDwfhuNOzPJfW1AVLMAUGKU2ZPAAAAAElFTkSuQmCC\n",
"text/plain": [
"<polyomino.board.DeletedRectangle at 0x6f56e8b0>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Chessboard().remove((0, 0)).remove((0, 7))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "1d7225b7",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAAYFBMVEUAAADRfMe128vfBLykVLaAn4yORk/ED0Y7BRi4APlDH8DH99yFDqL6Syfy7QqxZoaXsVkrI/w6ikMOoXxywYIZDnn655alzz6GxzDOGxJq621IrlMSBZmPuhg0uoxthljQxCNxAAAAb0lEQVR4nO3MSQ6CQAAAwYmoKCKLiops/v+V3JoTyZwnXQ+oEHBAhiNOOCPHBcHQMMnwCkNDw5iwwA0l7qhQo4GhYZphC0NDw5jwgSde6PDGB18YGqYZ9jA0NIwJfxgwYsKMBX8YGqYZbgwNDXfDFSiJm8jaDSAvAAAAAElFTkSuQmCC\n",
"text/plain": [
"<polyomino.solution.Solution at 0x6f558c10>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Chessboard().remove((0, 0)).remove((0, 7)).tile_with_many(DOMINO).solve()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "722aee60",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAMAAAC45U6nAAAABlBMVEX///8AAABVwtN+AAAAZklEQVR4nO3ZSQrAIBAAQf3/pz0L4gLjAlYfQ6DMYQRNSpLeKEfXMqLXzGAwGAwGg8FgMBgMxldG/9wdZEy+x2AwNhmNOV+/c1vfr/rfxmAwthsH5nywAgaDwWAwGPWzA//PJd2oACSvAZFe6vBVAAAAAElFTkSuQmCC\n",
"text/plain": [
"<polyomino.board.DeletedRectangle at 0x65fd08e0>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Chessboard().remove((3, 4)).remove((5, 5))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "a8b83b0a",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAAYFBMVEUAAAD/WpECZ4JtsHwtqH/UjXsc4mfFa/yqRlVFJ7raNUcvOyNN8Q0Hhde1j2rAMtm5mlOnufGBFbMsR9seR9flE24JuRvEDZodeWqCj4X3DFETOpC+wkNJ57OeZkN2KD3VpDDiAAAAdElEQVR4nO3N2xWCMADA0B4FBBFUQPCJ7j+lf+lPJ6C5AyRhhz0KlKhwQI0GwaBBgwYNZhs8osUJHXqcccEVBg0aNGgw3+CAERMCbpgTFhg0mGPwjhiMkwcMGtx68IkX3ojBT0IMrjBoMMfgN+GXYNDgxoN/pFKbyN9fg4YAAAAASUVORK5CYII=\n",
"text/plain": [
"<polyomino.solution.Solution at 0x65fd0118>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Chessboard().remove((3, 4)).remove((5, 5)).tile_with_many(DOMINO).solve()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eeb51823",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 1eb5e50

Please sign in to comment.