Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JohnathanWeisner/eee0e098bf0b3924b289 to your computer and use it in GitHub Desktop.
Save JohnathanWeisner/eee0e098bf0b3924b289 to your computer and use it in GitHub Desktop.
# 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"
@MarmosetMusic
Copy link

Nice work buddy.
-rebo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment