aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--day3.input1
-rwxr-xr-xday3.rb50
3 files changed, 52 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index cba7efc..03496f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
a.out
+*.swp
diff --git a/day3.input b/day3.input
new file mode 100644
index 0000000..f7791cc
--- /dev/null
+++ b/day3.input
@@ -0,0 +1 @@
+v>v<vvv<<vv^v<v>vv>v<<<^^^^^<<^<vv>^>v^>^>^>^>^><vvvv<^>^<<^><<<^vvvv>^>^><^v^><^<>^^>^vvv^<vv>>^>^^<>><>^>vvv>>^vv>^<><>^<v^>^>^><vv^vv^>><<^><<v>><>^<^>>vvv>v>>>v<<^<><^<v<>v>^^v^^^<^v^^>>><^>^>v<>^<>>^>^^v^><v<v>>><>v<v^v>^v<>>^><v>^<>v^>^<>^v^^^v^^>>vv<<^^><^<vvv>^>^^<^>>^^^^^v^<v>vv<>>v^v<^v^^<><^<^vv^><>><><>v>vvv^vv^^<<><<vvv><<^v^><v<>vvv^<^>vvvv^>^>>^v^<v^vv<^^v<>v>vv^<>><v<<<^v^<<><v<^<^<><^^^>^>>v>^>v^<>v><^<^<v^>^^vv<^^<>v^v^vv<>>>>v^v<>><^^v>vv^^>v^v>v<vv>>v>><v^v^v>vv>^^>^v><<vv^v^^vv<^v><^<<v<v^>vv^^^<v^>v>v^^^>><^^<v^<^>>v><vv<v^^>^^v>>v^^^<^^v>^v>><^<^<>>v<<^^vv>^^^v<^<^<v<v^^vv>^vv^>>v^><v>><<<>^vv^<^<>v^^<<<v<^>^><><v^^>>^^^<^vv<^^^>><^^v>^^v^<v^v^>^^<v>^<^v<^<<<<^<v^>v^<^^<>^^>^><<>>^v><>><^<v><^^^>>vv>^><vv>^^^^^v^vvv><><^<^>v>v^v^>^><><^<^><>v<<vv<^>><>^v^^v>^<<<>^v^>^<<v^vv<>v^<v^^vv><<v^<>>>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v^^v<vvvv><^>>^v^>^^<<<^>>^^>^<^^<^<<<v^<^^v<<vv^<<^^^vv><v<vv^>v^^v<v>^^<^v<^>>><<>vv<<^><<v^v^^^v<vv>^>vv<^>>^<v<>vv>>>^>>><<v<^<>^<<<>>^<<>><^<<^^^>>v^^>v<<<>v>v>v<v<^>^<>>>^vvv><<^^<<><v<><^<v<vvv>v>>>>vv^^v<v<^<^><v>^v<<v<vv>>v>v<<<<><<>vv<><^^^<>>v<v<vvv><v^<vv^>>><v^^<>>>^^<><^<^v^><vv>>^^v>^<<v^>v>^^>^v^<v<^<v^v><>>v^^<^v^^<<>^^>v^^>><<<<^<^^v>^^v>v<<vv^^vv>^>v^<v<v><>vv>>^<v^v^<v<^>^v>v^^>vvvvv<v><<>vv>vvvvvv>>v>>^^^<v>vv^^><<v>>v^^^^v>vv>v<^v>>>>^>^><v^>^<v<vv>v>^>><v>><<>>^vv<vv^^<^^>>>>><><<^<v<><<v>^><^vv^v>>>>>v>^>^<vv>^v^>v<^v^<^<<vv<<>v<>>^vv<<>^v^v>><><<>>v^^<<>^^<v><>v<<^^<^^>^^>^<^><>>v<>>^^<^>><<<v<>>>^v^>v>v<<^^<<^>v<v^>>v^^v^^<<>^v>v><v^>v<^^>^<vv><vv^<>v<><^<<<vv<<v>v<^<<<<^^>v^v^^><<><^^^<v>v^^>>>vvv><>vv<>>^^v^v<<^>v^^v^>vv>^<<v<^<v^>^^<<v<^^>^v^^<^^v<<>>vv<^>>^><><>v>>v<>^<v^^><<>>>
diff --git a/day3.rb b/day3.rb
new file mode 100755
index 0000000..17fd0ca
--- /dev/null
+++ b/day3.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+map = {:onlysanta => Hash.new(0), :robosanta => Hash.new(0)}
+map[:onlysanta][[0,0]] += 1
+map[:robosanta][[0,0]] += 1
+
+onlysanta = {:northing => 0, :easting => 0}
+santa = {:northing => 0, :easting => 0}
+robosanta = {:northing => 0, :easting => 0}
+
+input = STDIN.readlines.map(&:chomp).join
+
+input.chars.each_with_index do |ch, idx|
+ case ch
+ when '<'
+ onlysanta[:easting] -= 1
+ if idx.odd? then
+ santa[:easting] -= 1
+ else
+ robosanta[:easting] -= 1
+ end
+ when '>'
+ onlysanta[:easting] += 1
+ if idx.odd? then
+ santa[:easting] += 1
+ else
+ robosanta[:easting] += 1
+ end
+ when 'v'
+ onlysanta[:northing] -= 1
+ if idx.odd? then
+ santa[:northing] -= 1
+ else
+ robosanta[:northing] -= 1
+ end
+ when '^'
+ onlysanta[:northing] += 1
+ if idx.odd? then
+ santa[:northing] += 1
+ else
+ robosanta[:northing] += 1
+ end
+ end
+ map[:onlysanta][[onlysanta[:easting], onlysanta[:northing]]] += 1
+ map[:robosanta][[santa[:easting], santa[:northing]]] += 1
+ map[:robosanta][[robosanta[:easting], robosanta[:northing]]] += 1
+end
+
+puts "Santa only: #{map[:onlysanta].length}"
+puts "Robosanta: #{map[:robosanta].length}"