Day 20 (WIP)
This commit is contained in:
53
src/main/kotlin/com/basdado/adventofcode/Day20.kt
Normal file
53
src/main/kotlin/com/basdado/adventofcode/Day20.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.basdado.adventofcode
|
||||
|
||||
import java.util.*
|
||||
|
||||
const val DAY20_INPUT = "/day/20/example1.txt"
|
||||
|
||||
fun main() {
|
||||
|
||||
val day = Day20()
|
||||
day.puzzle1()
|
||||
}
|
||||
|
||||
class Day20 {
|
||||
|
||||
fun puzzle1() {
|
||||
|
||||
val input = lines(DAY20_INPUT).findFirst().get()
|
||||
]
|
||||
val rooms = mutableListOf(Room(Vector2(0, 0), mutableListOf()))
|
||||
val bracketStarts = Stack<Room>()
|
||||
var currentRoom = rooms[0]
|
||||
|
||||
for(c in input) {
|
||||
if (c == '^') {
|
||||
continue
|
||||
}
|
||||
|
||||
if (c == '(') {
|
||||
bracketStarts.push(currentRoom)
|
||||
}
|
||||
|
||||
if (c == '|') {
|
||||
currentRoom = bracketStarts.pop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Room(val pos: Vector2, val connections: MutableList<Room>)
|
||||
|
||||
data class Vector2(val x: Long, val y: Long) {
|
||||
fun move(c: Char): Vector2 {
|
||||
return when(c) {
|
||||
'N' -> Vector2(x, y - 1)
|
||||
'E' -> Vector2(x + 1, y)
|
||||
'S' -> Vector2(x, y + 1)
|
||||
'W' -> Vector2(x - 1, y)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
src/main/resources/day/20/example1.txt
Normal file
1
src/main/resources/day/20/example1.txt
Normal file
@@ -0,0 +1 @@
|
||||
^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$
|
||||
1
src/main/resources/day/20/example2.txt
Normal file
1
src/main/resources/day/20/example2.txt
Normal file
@@ -0,0 +1 @@
|
||||
^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$
|
||||
1
src/main/resources/day/20/input.txt
Normal file
1
src/main/resources/day/20/input.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user