This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class World(val map: MutableMap<P<Int, Int>, Char>, var hasMoved: Boolean = false) { | |
private var considerDir = listOf(listOf(N, NE, NW), listOf(S, SE, SW), listOf(W, NW, SW), listOf(E, NE, SE)) | |
private var plan = 0 | |
val elvesCount : Int by lazy { map.entries.count { it.value == '#' }} | |
fun step() { | |
val elves = map.entries.filter { it.value == '#' }.map { it.key }.toList() | |
val planElves = elves.filter { neighbors(it).any { n -> map[n] == '#' } } | |
val plannedMoves = mutableMapOf<Point, Point>() | |
for (elf in planElves) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package se.saidaspen.aoc.aoc2022 | |
import junit.framework.TestCase.assertEquals | |
import org.junit.Test | |
import se.saidaspen.aoc.aoc2022.Day22.DIR.* | |
import se.saidaspen.aoc.util.P | |
internal class Day22Test { | |
@Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Day22 : Day(2022, 22) { | |
enum class DIR(val p: Point) { RIGHT(P(1, 0)), DOWN(P(0, 1)), LEFT(P(-1, 0)), UP(P(0, -1)); | |
fun right() = values()[(this.ordinal + 1).mod(values().size)] | |
fun left() = values()[(this.ordinal - 1).mod(values().size)] | |
} | |
enum class SIDE { A, B, C, D, E, F } | |
private val map = toMap(input.split("\n\n")[0]).entries.filter { it.value != ' ' }.associate { it.key to it.value } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import se.saidaspen.aoc.util.Day | |
import se.saidaspen.aoc.util.words | |
import kotlin.math.absoluteValue | |
import kotlin.math.max | |
fun main() = Dayxx.run() | |
object Dayxx : Day(2022, 21) { | |
var input2 = "root: pppw + sjmn\n" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Day20 : Day(2022, 20) { | |
override fun part1() = solve(1, 1) | |
override fun part2() = solve(811589153, 10) | |
private fun solve(key: Long, times: Int): Long { | |
// Changes 1, 2, 3 to (0, 1), (1, 2), (2, 3) to keep the original positions while moving things around | |
val wPos = longs(input).withIndex().map { P(it.index, it.value * key) }.toMutableList() | |
repeat(times) { | |
for (i in 0 until wPos.size) { | |
// Idx is the current index, elem.first is the original index, elem.second is the value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package se.saidaspen.aoc.aoc2022 | |
import se.saidaspen.aoc.util.* | |
import java.lang.Integer.max | |
import kotlin.math.min | |
fun main() = Day19.run() | |
object Day19 : Day(2022, 19) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import se.saidaspen.aoc.util.* | |
import java.math.BigInteger | |
import kotlin.math.absoluteValue | |
fun main() = Dayxx.run() | |
object Dayxx : Day(2022, 17) { | |
var dash = toMap("####").map { it.key }.toSet() | |
var plus = toMap(".#.\n" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import se.saidaspen.aoc.util.* | |
fun main() = Dayxx.run() | |
object Dayxx : Day(2022, 16) { | |
private val valves = input.lines().associate { it.split(" ")[1] to ints(it)[0] } | |
private val relevantValves = valves.entries.filter { it.value > 0 }.map { it.key to it.value }.toMap() | |
private val connections = input.lines().map { it.split(" ") }.associate { | |
it[1] to it.drop(9).map { c -> c.replace(",", "").trim() }.toList() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import se.saidaspen.aoc.util.* | |
import kotlin.math.sign | |
fun main() = Dayxx.run() | |
object Dayxx : Day(2022, 14) { | |
override fun part1() : Any { | |
// input = "498,4 -> 498,6 -> 496,6\n" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import se.saidaspen.aoc.util.Day | |
import se.saidaspen.aoc.util.P | |
fun main() = Day13.run() | |
object Day13 : Day(2022, 13) { | |
class Packet (private val fixed : Int? = null, val values : MutableList<Packet> = mutableListOf()) : Comparable<Packet> { | |
override fun toString() = fixed?.toString() ?: ("[" + values.joinToString(",") + "]") |
NewerOlder