aboutsummaryrefslogtreecommitdiff
path: root/day02/part2
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-02 16:34:42 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-02 16:34:42 +0000
commit54350d120ff81743476fa851a2f049b3f50f617f (patch)
tree5c584100555c72c0ebbc7ac21a3b1abad93b74ce /day02/part2
parentea3c3f6bc4fcdb65cfaba8432ac88998faf7848c (diff)
Day 02
Diffstat (limited to 'day02/part2')
-rwxr-xr-xday02/part223
1 files changed, 23 insertions, 0 deletions
diff --git a/day02/part2 b/day02/part2
new file mode 100755
index 0000000..5d05da2
--- /dev/null
+++ b/day02/part2
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+
+def findpair(nums)
+ (0...nums.length).each do |i|
+ (0...nums.length).each do |j|
+ next if j == i
+ pair = [nums[i], nums[j]]
+ return pair if pair.max % pair.min == 0
+ end
+ end
+end
+
+cs = 0
+
+input = $stdin.readlines.map(&:chomp)
+
+input.each do |line|
+ nums = line.split.map(&:to_i)
+ pair = findpair(nums)
+ cs += pair.max / pair.min
+end
+
+puts cs