Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 2016/src/main/scala/aoc2016/Day08.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ object Day08 extends AoC:
object Screen:

val empty: Screen =
Screen(List.fill(6, 50)('.'))
Screen(Vector.fill(6, 50)('.'))


case class Screen(pixels: List[List[Char]]):
case class Screen(pixels: Vector[Vector[Char]]):
import Operation.*

val sizeX: Int = pixels.head.size
Expand All @@ -41,13 +41,13 @@ object Day08 extends AoC:

def rectangle(sizeX: Int, sizeY: Int): Screen =
val (top, bottom) = pixels.splitAt(sizeY)
val updated = top.map(row => List.fill(sizeX)('#') :++ row.drop(sizeX))
val updated = top.map(row => Vector.fill(sizeX)('#') :++ row.drop(sizeX))
Screen(updated :++ bottom)

def shiftRow(index: Int, by: Int): Screen =
val (top, bottom) = pixels.splitAt(index)
val (row, rest) = bottom.splitAt(1)
val shifted = Iterator.continually(row.head).flatten.slice(sizeX - by, 2 * sizeX - by).toList
val shifted = Iterator.continually(row.head).flatten.slice(sizeX - by, 2 * sizeX - by).toVector
Screen(top :+ shifted :++ rest)

infix def process(op: Operation): Screen =
Expand Down
20 changes: 10 additions & 10 deletions 2016/src/main/scala/aoc2016/Day10.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import scala.collection.mutable

object Day10 extends AoC:

enum Target(val i: Int):
case Bot(override val i: Int) extends Target(i)
case Out(override val i: Int) extends Target(i)
enum Target(val index: Int):
case Bot(override val index: Int) extends Target(index)
case Out(override val index: Int) extends Target(index)

import Target.*

Expand Down Expand Up @@ -59,16 +59,16 @@ object Day10 extends AoC:

def solve1(instructions: Vector[Inst], values: Set[Int]): Int =
val (_, targets) = solve(instructions)
targets.find(_.values.contains(values)).get.target.i
targets.find(_.values.contains(values)).get.target.index

def solve2(instructions: Vector[Inst]): Int =
val (targets, _) = solve(instructions)
targets(Out(0)).head * targets(Out(1)).head * targets(Out(2)).head

private val init =
private val ParseInit =
"""value (\d+) goes to bot (\d+)""".r

private val sort =
private val ParseSort =
"""bot (\d+) gives low to (bot|output) (\d+) and high to (bot|output) (\d+)""".r

def targetFromString(s: String, i: Int): Target =
Expand All @@ -78,10 +78,10 @@ object Day10 extends AoC:

def instFromString(s: String): Inst =
s match
case init(value, boti) =>
Init(Bot(boti.toInt), value.toInt)
case sort(boti, lowTarget, lowi, highTarget, highi) =>
Sort(Bot(boti.toInt), targetFromString(lowTarget, lowi.toInt), targetFromString(highTarget, highi.toInt))
case ParseInit(value, index) =>
Init(Bot(index.toInt), value.toInt)
case ParseSort(index, lowTarget, low, highTarget, high) =>
Sort(Bot(index.toInt), targetFromString(lowTarget, low.toInt), targetFromString(highTarget, high.toInt))

def instructionsFromString(s: String): Vector[Inst] =
s.linesIterator.map(instFromString).toVector
Expand Down