aboutsummaryrefslogtreecommitdiff
path: root/day03
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-04 10:34:03 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-04 10:34:03 +0000
commita5bdbb8e5848ad44041c14dddf6bcc484d5fc4d5 (patch)
tree5c89360efd2f96fcaded990a31a1ce4fb93a78d6 /day03
parent54350d120ff81743476fa851a2f049b3f50f617f (diff)
Day03 Part 1
Diffstat (limited to 'day03')
-rw-r--r--day03/input1
-rwxr-xr-xday03/part119
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