Skip to content

Instantly share code, notes, and snippets.

@ReganRyanNZ
Created November 6, 2018 11:34
Show Gist options
  • Save ReganRyanNZ/4ebe93074b4d6be867bf556016d7f138 to your computer and use it in GitHub Desktop.
Save ReganRyanNZ/4ebe93074b4d6be867bf556016d7f138 to your computer and use it in GitHub Desktop.
Calculator: The Game (solver)
# This runs through all possible moves for the app "Calculator: The Game"
#
# Note that in the app the buttons keep changing their functions,
# so you will need to edit the functions according to your level.
def calc
moves = 6
start = 111
goal = 126
def up(input)
input * 3
end
def mid(input)
input-9
end
def right(input)
input * -1
end
def down(input)
input.to_s[0..-2].to_i
end
seqs = [:up, :mid, :right, :down].repeated_permutation(moves)
seqs.each do |seq|
res = start
seq.each {|fn| res = send(fn, res) }
puts seq.inspect if res == goal
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment