Commit 9262af29 authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

Add strict mapValues to Map as extension

parent 6a3a8684
......@@ -13,7 +13,7 @@ def day16(input: List[String]): String =
case err => (errors + err.sum, valids)
}}
val columns = findFields(rules)(valid)
val departureInfo = columns.filter(_._1.startsWith("departure")).view.mapValues(own(_)).toMap
val departureInfo = columns.filter(_._1.startsWith("departure")).mapValuesS(own(_))
val checksum = departureInfo.values.map(_.toLong).product
s"""Error rate: $errorRate\n
......
......@@ -149,7 +149,7 @@ object day19 extends (List[String] => String) {
extension (rules: Rules)
def optimize: Rules =
val opt = rules.view.mapValues(Optimizer.optimizeSingle(rules)).toMap
val opt = rules.mapValuesS(Optimizer.optimizeSingle(rules))
if opt == rules then opt else opt.optimize
def prune(root: Int = 0): Rules =
......
......@@ -26,3 +26,7 @@ extension (s: String | UncheckedNull)
extension (s: Array[String | UncheckedNull] | UncheckedNull)
def nn: List[String] = s.asInstanceOf[Array[String]].toList
extension [K,V,W](map: Map[K,V])
def mapValuesS(f: V => W): Map[K, W] = map.view.mapValues(f).toMap
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment