From 400c7a256d3f3d41b84889c4c34ea90afb51f730 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 9 Dec 2018 07:55:40 +0000 Subject: [day09] Part 1 done, does not scale --- day09/Dockerfile | 7 +++++++ day09/Makefile | 17 +++++++++++++++++ day09/entrypoint | 13 +++++++++++++ day09/input | 1 + day09/part1 | 29 +++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 day09/Dockerfile create mode 100644 day09/Makefile create mode 100755 day09/entrypoint create mode 100644 day09/input create mode 100755 day09/part1 (limited to 'day09') diff --git a/day09/Dockerfile b/day09/Dockerfile new file mode 100644 index 0000000..5e0a8b7 --- /dev/null +++ b/day09/Dockerfile @@ -0,0 +1,7 @@ +FROM ruby:2.5-slim + +WORKDIR /opt + +COPY . . + +ENTRYPOINT ["./entrypoint"] diff --git a/day09/Makefile b/day09/Makefile new file mode 100644 index 0000000..df55a83 --- /dev/null +++ b/day09/Makefile @@ -0,0 +1,17 @@ +DAY = 09 + +.PHONY: run clean push + +run: build + docker run -it --rm aoc2018day$(DAY) + +build: part* input + docker build -t aoc2018day$(DAY) . + touch build + +clean: + rm -f build + +push: build + docker tag aoc2018day$(DAY) advent.4574.co.uk/aoc2018day$(DAY) + docker push advent.4574.co.uk/aoc2018day$(DAY) diff --git a/day09/entrypoint b/day09/entrypoint new file mode 100755 index 0000000..8982d21 --- /dev/null +++ b/day09/entrypoint @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ -x part1 ] ; then + echo -ne "Part 1:\n\t" + time ./part1 < input +fi +if [ -x part1 -a -x part2 ] ; then + echo +fi +if [ -x part2 ] ; then + echo -ne "Part 2:\n\t" + time ./part2 < input +fi diff --git a/day09/input b/day09/input new file mode 100644 index 0000000..a8d7ca0 --- /dev/null +++ b/day09/input @@ -0,0 +1 @@ +468 players; last marble is worth 71010 points 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 -- cgit v1.2.1