aboutsummaryrefslogtreecommitdiff
path: root/day09/part1
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2018-12-09 07:55:40 +0000
committerNat Lasseter <user@4574.co.uk>2018-12-09 07:55:40 +0000
commit400c7a256d3f3d41b84889c4c34ea90afb51f730 (patch)
tree5ec2af7b89c92a7ce1db9b22d9d45142b9ac17eb /day09/part1
parenta80aa90a8b47a3e6be04a4ee1ebb11b3dd29494f (diff)
[day09] Part 1 done, does not scale
Diffstat (limited to 'day09/part1')
-rwxr-xr-xday09/part129
1 files changed, 29 insertions, 0 deletions
diff --git a/day09/part1 b/day09/part1
new file mode 100755
index 0000000..c0c0a5f
--- /dev/null
+++ b/day09/part1
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+input = gets.chomp
+input =~ /(\d+) players; last marble is worth (\d+) points/
+num_players = $1.to_i
+num_marbles = $2.to_i
+marbles = [0]
+players = Array.new(num_players, 0)
+current = 0
+player = 0
+
+num_marbles.times do |m|
+ marble = m + 1
+
+ if (marble % 23).zero?
+ players[player] += marble
+ d = (current - 7) % marbles.length
+ players[player] += marbles.delete_at(d)
+ current = d
+ else
+ nm = ((current + 1) % marbles.length) + 1
+ marbles.insert(nm, marble)
+ current = nm
+ end
+
+ player = (player + 1) % num_players
+end
+
+puts players.max