Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bf7055a0f9f75ea93b3c to your computer and use it in GitHub Desktop.
Save anonymous/bf7055a0f9f75ea93b3c to your computer and use it in GitHub Desktop.
class Equation
def read
File.open("./input", "r") do |file|
file.each_line do |line|
sum(line.split)
end
end
end
private
def sum(args)
res = []
for i in -100..100 do
result = 0
args.each_with_index do |value, index|
value = value.to_i
result += value * i ** ((args.size - 1) - index)
end
res << i if result == 0
end
show(res)
end
def show(res)
puts "SUM #{res}"
end
end
check = Equation.new
check.read
1 -3 0 0
3 -15 18 0
1 -7 -33 135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment