aboutsummaryrefslogtreecommitdiff
path: root/day03/part1
blob: 609a2877cf58dac65f9ebf25fb70c2d95852a6f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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