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 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: |
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 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(_)) |
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 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 = |
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 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._ |
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 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 |
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 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 |
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 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: |
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 sungkmi.aoc2020.day15 | |
case class State( | |
lastSpokenTurn: IndexedSeq[Int], | |
lastSpokenNumber: Int, | |
turn: Int, | |
) | |
extension (s: State) | |
def next: State = State( |
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 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 | |
) |
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 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") |