Day 7 part 1 (part 2 kinda stupid)

This commit is contained in:
Aly 2019-12-07 15:08:52 -08:00
parent 17e061d2e1
commit 0664894ef2
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package aoc.y2019
import aoc.Day
import scala.annotation.tailrec
object Day07 extends Day {
@tailrec def runAmplifiers(machine: Intcode.Machine, order: IndexedSeq[Int], input: Int = 0): Int = {
if(order.isEmpty) {
input
} else {
val firstInput = order.head
val secondInput = input
val runAmplifier = for {
_ <- Intcode.input(firstInput)
_ <- Intcode.input(secondInput)
ran <- Intcode.run
} yield ran
val output = runAmplifier.runS(machine).value.output.head
runAmplifiers(machine, order.tail, output)
}
}
override def part1(input: String): String = {
val memory = input.split(",").toVector.map(_.toInt)
val initialState = Intcode.Machine(memory)
val maximumSignal = (0 to 4).permutations.map(runAmplifiers(initialState, _)).max
maximumSignal.toString
}
override def part2(input: String): String = ???
}

View File

@ -9,6 +9,7 @@ package object y2019 extends Year {
"4" -> Day04,
"5" -> Day05,
"6" -> Day06,
"7" -> Day07,
)
}