AdventOfCode/spirallingdistance.rb

25 lines
418 B
Ruby
Raw Normal View History

2017-12-03 12:24:42 +00:00
###
# Part 1
###
a = 325489
b = a
while Math.sqrt(b) % 2 != 1 do
b += 1
end
puts "Total: " + b.to_s
side_length = Math.sqrt(b).ceil
puts "Side length: " + side_length.to_s
diff = b - a
puts "Diff: " + diff.to_s
steps_req = diff % (side_length - 1)
to_center = (side_length-1) / 2
to_mid_of_row = ((side_length / 2) - steps_req).abs
solution = to_center + to_mid_of_row
puts "Pls correct yes: " + solution.to_s