Skip to content

Commit

Permalink
Day 18 part 1 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mlcohen committed Jan 16, 2023
1 parent a48b4e9 commit 01102b3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions input/day18_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
2,2,2
1,2,2
3,2,2
2,1,2
2,3,2
2,2,1
2,2,3
2,2,4
2,2,6
1,2,5
3,2,5
2,1,5
2,3,5
48 changes: 48 additions & 0 deletions src/day18/solution1/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package day18

// Original solution used to solve the AoC day 18 puzzle.

import common.Solution

data class Vec3(val x: Int, val y: Int, val z: Int) {
operator fun plus(v: Vec3): Vec3 = Vec3(this.x + v.x, this.y + v.y, this.z + v.z)
override fun toString(): String = "($x, $y, $z)"
}

val Directions: List<Vec3> = listOf(
Vec3(1, 0, 0),
Vec3(0, 1, 0),
Vec3(0, 0, 1),
Vec3(-1, 0, 0),
Vec3(0, -1, 0),
Vec3(0, 0, -1),
)

typealias Point = Vec3

typealias ParsedInput = List<Vec3>

object Day18 : Solution.LinedInput<ParsedInput>(day = 18) {

override fun parseInput(input: List<String>): ParsedInput {
return input.map{ line ->
line.split(',').map(String::toInt).let { (x, y, z) -> Vec3(x, y, z) }
}
}

override fun part1(input: ParsedInput): Any {
val cubes = input.toSet()
val exposedFaces = cubes.fold(0) { count, cube ->
count + Directions.count { dir -> (cube + dir) !in cubes }
}
return exposedFaces
}

override fun part2(input: ParsedInput): Any {
return Unit
}
}

fun main() {
Day18.solve(test = false)
}

0 comments on commit 01102b3

Please sign in to comment.