Skip to content

Instantly share code, notes, and snippets.

package sungkmi.aoc2020.day22
import scala.collection.immutable.Queue
case class Decks(p1: Queue[Int], p2: Queue[Int])
extension (d: Decks)
def step: Either[Boolean, Decks] =
//println(s"===> $d")
dealWithTopCards:
package sungkmi.aoc2020.day21
case class Ingredient(name: String) extends AnyVal
case class Allergen(name: String) extends AnyVal
type Food = (Set[Ingredient], Set[Allergen])
type Pair = (Allergen, Ingredient)
def parseLine(line: String): Food =
val Array(f, e) = line `split` " \\(contains "
val ingredients = (f `split` " ").toSet.map(Ingredient(_))
package sungkmi.aoc2020.day20
import scala.collection.BitSet
type Tile = IndexedSeq[BitSet]
extension (t: Tile)
def edges: IndexedSeq[BitSet] =
def regulateEdge(edge: BitSet): BitSet =
def toBigInt(bitset: BitSet): BigInt =
package sungkmi.aoc2020.day19
enum Rule:
case SingleChar(char: Char) extends Rule
case Index(n: Int) extends Rule
case And(rules: Seq[Rule]) extends Rule
case Or(rules: Seq[Rule]) extends Rule
import Rule._
package sungkmi.aoc2020.day18
sealed trait Token
final case class Digit(n: BigInt) extends OpDigit
sealed trait OpParen extends Token
enum Op extends OpParen with OpDigit:
case Plus, Multiply
package sungkmi.aoc2020.day17
type Coordinate = (Int, Int, Int)
type State = Set[Coordinate]
extension (s: State)
def neighbors(p: Coordinate): Set[Coordinate] =
val (x0, y0, z0) = p
val ps = for {
i <- -1 to 1
package sungkmi.aoc2020.day16
type Ranges = Map[String, Seq[Range]]
extension (rs: Ranges)
def containsNumber(n: Int): Boolean = rs.values.flatten.exists(_ `contains` n)
def parse(s: String): (Ranges, Seq[Int], Seq[Seq[Int]]) =
val Array(input1, input2, input3) = s `split` "\n\n"
val ranges: Ranges = input1.split("\n").map:
package sungkmi.aoc2020.day15
case class State(
lastSpokenTurn: IndexedSeq[Int],
lastSpokenNumber: Int,
turn: Int,
)
extension (s: State)
def next: State = State(
package sungkmi.aoc2020.day14
case class State(mask: Mask, memory: Memory)
object State:
val initial: State = State(
mask = Mask(Set.empty, Set.empty),
memory = Map.empty
)
package sungkmi.aoc2020.day13
import scala.util.Try
type Timestamp = Long
type Id = Int
type Minute = Long
def parse(s: String): (Timestamp, Seq[Option[Id]]) =
val Array(line1, line2) = s.split("\n")