Last active
December 29, 2015 09:13
-
-
Save grayclhn/8ad99aa68b37b98c4ec0 to your computer and use it in GitHub Desktop.
Solver for wuzzit trouble (http://wuzzittrouble.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"locks = Set([18, 36, 41, 49, 54, 57])\n", | |
"gears = Set([3, 8, 18])\n", | |
"maxmoves = 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 56, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\" \"" | |
] | |
}, | |
"execution_count": 56, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"i = 3\n", | |
"g = 18\n", | |
"mod([g:g:g*i], 20)\n", | |
"\" \"^3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 106, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"wuzzit (generic function with 3 methods)" | |
] | |
}, | |
"execution_count": 106, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function wuzzit(position, gears, locks, maxmoves, indent)\n", | |
" for g in gears\n", | |
" for i in [1:5, -1:-1:-5]\n", | |
" locksleft = setdiff(locks, Set(mod(position .+ [(g*sign(i)):(g*sign(i)):(g*i)], 65)))\n", | |
" isempty(locksleft) && return [g i]\n", | |
" if maxmoves > 1\n", | |
" nexttry = wuzzit(mod(position + g*i, 65), gears, locksleft, maxmoves - 1, indent + 1)\n", | |
" length(nexttry) > 0 && return [[g i], nexttry]\n", | |
" end\n", | |
" end\n", | |
" end\n", | |
" return []\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 108, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2x2 Array{Int64,2}:\n", | |
" 19 4\n", | |
" 8 -4" | |
] | |
}, | |
"execution_count": 108, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"a = wuzzit(0, Set([3, 8, 19]), Set([19, 38, 44, 52, 57, 60]), 2, 0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 103, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"-1" | |
] | |
}, | |
"execution_count": 103, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sign(-1):" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 100, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"4-element Array{Int64,1}:\n", | |
" 45\n", | |
" 25\n", | |
" 5\n", | |
" 50" | |
] | |
}, | |
"execution_count": 100, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mod(20 * [-1:-1:-4], 65)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 102, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"5-element Array{Int64,1}:\n", | |
" 42\n", | |
" 34\n", | |
" 26\n", | |
" 18\n", | |
" 10" | |
] | |
}, | |
"execution_count": 102, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mod(50 + 8*[-1:-1:-5], 65)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.3.12-pre", | |
"language": "julia", | |
"name": "julia-0.3" | |
}, | |
"language_info": { | |
"name": "julia", | |
"version": "0.3.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The function
wuzzit
does everything. The rest is scratch code that I should probably clean up but haven't.