@@ -6,14 +6,14 @@ object Day05 extends App:
66 val day : String =
77 this .getClass.getName.filter(_.isDigit).mkString(" " )
88
9- val jumps : Array [Int ] =
9+ val jumps : Vector [Int ] =
1010 Source
1111 .fromResource(s " input $day.txt " )
1212 .getLines
1313 .map(_.trim.toInt)
14- .toArray
14+ .toVector
1515
16- case class CPU (mem : Array [Int ], update : Int => Int , pc : Int = 0 , steps : Int = 0 ):
16+ case class CPU (mem : Vector [Int ], update : Int => Int , pc : Int = 0 , steps : Int = 0 ):
1717 @ tailrec
1818 final def run : CPU =
1919 mem.lift(pc) match
@@ -22,18 +22,12 @@ object Day05 extends App:
2222 case Some (offset) =>
2323 CPU (mem.updated(pc, update(offset)), update, pc + offset, steps + 1 ).run
2424
25- val start1 : Long =
26- System .currentTimeMillis
27-
28- val answer1 : Int =
29- CPU (jumps, offset => offset + 1 ).run.steps
25+ val start1 : Long = System .currentTimeMillis
26+ val answer1 : Int = CPU (jumps, offset => offset + 1 ).run.steps
3027
3128 println(s " Answer AOC 2017 day $day part 1: $answer1 [ ${System .currentTimeMillis - start1}ms] " )
3229
33- val start2 : Long =
34- System .currentTimeMillis
35-
36- val answer2 : Int =
37- CPU (jumps, offset => if offset >= 3 then offset - 1 else offset + 1 ).run.steps
3830
31+ val start2 : Long = System .currentTimeMillis
32+ val answer2 : Int = CPU (jumps, offset => if offset >= 3 then offset - 1 else offset + 1 ).run.steps
3933 println(s " Answer AOC 2017 day $day part 2: $answer2 [ ${System .currentTimeMillis - start2}ms] " )
0 commit comments