Skip to content

Instantly share code, notes, and snippets.

@tomnis
Created December 6, 2025 06:27
Show Gist options
  • Select an option

  • Save tomnis/f392b67419dcee33f9fa74cccf638a8c to your computer and use it in GitHub Desktop.

Select an option

Save tomnis/f392b67419dcee33f9fa74cccf638a8c to your computer and use it in GitHub Desktop.
day6part2
def part2(data: Seq[String]): Long = {
val grid: Grid[Char] = data.dropRight(1).toArray.map(_.toCharArray).transpose
var grandTotal: Long = 0
var curTotal: Long = 0
var op: Op = null
data.last.zipWithIndex.foreach { case (ch, idx) =>
if (ch == '+') {
curTotal = grid(idx).mkString.trim.toLong
op = (a, b) => a + b
}
else if (ch == '*') {
curTotal = grid(idx).mkString.trim.toLong
op = (a, b) => a * b
}
else if (grid(idx).forall(_ == ' ') && ch == ' ') {
grandTotal += curTotal
curTotal = 0
}
else if (ch == ' ') {
val num = grid(idx).mkString.trim.toLong
curTotal = op(curTotal, num)
}
else {
???
}
}
grandTotal += curTotal
grandTotal
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment