aboutsummaryrefslogtreecommitdiff
path: root/day18/part1.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2022-12-18 14:34:19 +0000
committerNat Lasseter <user@4574.co.uk>2022-12-18 14:34:19 +0000
commit896addebb0843d99d9845140eb3b1167bf6e9787 (patch)
treeb665de11587d4e640ec239a8c078e7f58a3e1f4a /day18/part1.rb
parentfe291a1f95defa9d99f5952183f8be67c2f847a1 (diff)
Day 18, part 1
Diffstat (limited to 'day18/part1.rb')
-rw-r--r--day18/part1.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/day18/part1.rb b/day18/part1.rb
new file mode 100644
index 0000000..dd4ba41
--- /dev/null
+++ b/day18/part1.rb
@@ -0,0 +1,29 @@
+require 'set'
+
+grid = Hash.new
+
+$stdin.readlines.each do |line|
+ x, y, z = line.strip.split(?,).map(&:to_i)
+ grid[x] = Hash.new if grid[x].nil?
+ grid[x][y] = Set.new if grid[x][y].nil?
+ grid[x][y] << z
+end
+
+sa = 0
+
+grid.each do |x, yzs|
+ yzs.each do |y, zs|
+ zs.each do |z|
+ tsa = 6
+ tsa -= 1 if !grid[x-1].nil? && grid[x-1][y]&.include?(z)
+ tsa -= 1 if !grid[x+1].nil? && grid[x+1][y]&.include?(z)
+ tsa -= 1 if grid[x][y-1]&.include?(z)
+ tsa -= 1 if grid[x][y+1]&.include?(z)
+ tsa -= 1 if grid[x][y].include?(z-1)
+ tsa -= 1 if grid[x][y].include?(z+1)
+ sa += tsa
+ end
+ end
+end
+
+puts sa