Last active
August 29, 2015 14:06
-
-
Save JohnathanWeisner/eee0e098bf0b3924b289 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# From | |
# | |
# $*.map{|a|(i=a=~/0/)?(v=*?1..?9).fill{|j|v-=[a[j+i-k=i%9],a[ | |
# k+j*=9],a[j%26+i-i%3-i%27+k]]}+v.map{|k|$*.<<$`<<k<<$'}:p(a)} | |
# | |
# | |
# To | |
start = Time.now | |
ARGV.map do |board| | |
if index_of_zero = (board =~ /0/) | |
buffer = (possibilities = ('1'..'9').to_a ).fill do |step| | |
possibilities -=[ | |
board[step + index_of_zero - index_within_row = index_of_zero % 9], #row | |
board[index_within_row + step *= 9], #col | |
board[step % 26 + index_of_zero - index_of_zero % 3 - index_of_zero % 27 + index_within_row ] #box | |
] | |
end | |
steps_to_expand_from = possibilities.map do |possibility| | |
ARGV.<< $` << possibility << $' | |
end | |
buffer + steps_to_expand_from | |
else #if solved | |
puts board | |
end | |
end | |
puts "Solved in #{(Time.now - start).round(3)} seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work buddy.
-rebo