You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
val (buckets, instructions) = input.split(lineSeparator * 2).toSeq match
case Seq(first, second) =>
val lines = first.split(lineSeparator)
val range = 1 until lines.last.size by 4
val buckets = lines.init.map(s => range.map(i => if s.indices.contains(i) && s(i).isLetter then Some(s(i)) else None)).toIndexedSeq.transpose.map(_.flatten)
val instructions = second.split(lineSeparator).map {
case s"move $a from $b to $c" => (a.toInt, b.toInt - 1, c.toInt - 1)
}
(buckets, instructions)
def execute(tpe: Boolean): String =
instructions.foldLeft(buckets) { case (acc, (amount, from, to)) =>
val (moved, fromRemaining) = acc(from).splitAt(amount)
acc.updated(from, fromRemaining).updated(to, (if tpe then moved else moved.reverse) ++ acc(to))