Part 1
This commit is contained in:
parent
b941cf4ec7
commit
63021fa173
24
spirallingdistance.rb
Normal file
24
spirallingdistance.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
###
|
||||
# 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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user