diff options
-rw-r--r-- | day03/input | 1 | ||||
-rwxr-xr-x | day03/part1 | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/day03/input b/day03/input new file mode 100644 index 0000000..ce15bc4 --- /dev/null +++ b/day03/input @@ -0,0 +1 @@ +325489 diff --git a/day03/part1 b/day03/part1 new file mode 100755 index 0000000..609a287 --- /dev/null +++ b/day03/part1 @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +input = gets.chomp.to_i + +n = 0 +n += 1 while ((n*2)+1)**2 < input + +s = ((n*2)+1)**2 + +d = s +d -= n +d -= 2*n while d > input +d += 2*n + +if d - n <= input then + puts d - input + n +else + puts input - (d - 2*n) + n +end |