@@ -14,10 +14,10 @@ import Operation.*
1414
1515def loadInput (): String = loadFileSync(s " $currentDir/../input/day21 " )
1616
17- def part1 (input : String ): BigInt =
17+ def part1 (input : String ): Long =
1818 resolveRoot(input)
1919
20- def part2 (input : String ): BigInt =
20+ def part2 (input : String ): Long =
2121 whichValue(input)
2222
2323enum Operator (val eval : BinOp , val invRight : BinOp , val invLeft : BinOp ):
@@ -28,10 +28,10 @@ enum Operator(val eval: BinOp, val invRight: BinOp, val invLeft: BinOp):
2828
2929enum Operation :
3030 case Binary (op : Operator , depA : String , depB : String )
31- case Constant (value : BigInt )
31+ case Constant (value : Long )
3232
33- type BinOp = (BigInt , BigInt ) => BigInt
34- type Resolved = Map [String , BigInt ]
33+ type BinOp = (Long , Long ) => Long
34+ type Resolved = Map [String , Long ]
3535type Source = Map [String , Operation ]
3636type Substitutions = List [(String , PartialFunction [Operation , Operation ])]
3737
@@ -42,7 +42,7 @@ def readAll(input: String): Map[String, Operation] =
4242 case s " $x $binop $y" =>
4343 Binary (Operator .valueOf(binop), x, y)
4444 case n =>
45- Constant (BigInt (n) )
45+ Constant (n.toLong )
4646 )
4747
4848@ tailrec
@@ -63,21 +63,21 @@ def reachable(names: List[String], source: Source, resolved: Resolved): Resolved
6363 resolved
6464end reachable
6565
66- def resolveRoot (input : String ): BigInt =
66+ def resolveRoot (input : String ): Long =
6767 val values = reachable(" root" :: Nil , readAll(input), Map .empty)
6868 values(" root" )
6969
70- def whichValue (input : String ): BigInt =
70+ def whichValue (input : String ): Long =
7171 val source = readAll(input) - " humn"
7272
7373 @ tailrec
74- def binarySearch (name : String , goal : Option [BigInt ], resolved : Resolved ): BigInt =
74+ def binarySearch (name : String , goal : Option [Long ], resolved : Resolved ): Long =
7575
7676 def resolve (name : String ) =
7777 val values = reachable(name :: Nil , source, resolved)
7878 values.get(name).map(_ -> values)
7979
80- def nextGoal (inv : BinOp , value : BigInt ): BigInt = goal match
80+ def nextGoal (inv : BinOp , value : Long ): Long = goal match
8181 case Some (prev) => inv(prev, value)
8282 case None => value
8383
0 commit comments