From 63021fa173b0ec041cad972238394c4966895770 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 3 Dec 2017 13:24:42 +0100 Subject: [PATCH] Part 1 --- spirallingdistance.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spirallingdistance.rb diff --git a/spirallingdistance.rb b/spirallingdistance.rb new file mode 100644 index 0000000..d198059 --- /dev/null +++ b/spirallingdistance.rb @@ -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 + + +