Don't actually need recursion
This commit is contained in:
parent
b9d62c2835
commit
83b5a09e73
@ -43,7 +43,7 @@ class Day18(@Lines val input: Input<List<String>>) {
|
|||||||
|
|
||||||
private fun solveGroup(group: String, precedence: Boolean) = solveGroup(parseGroup(group), precedence)
|
private fun solveGroup(group: String, precedence: Boolean) = solveGroup(parseGroup(group), precedence)
|
||||||
|
|
||||||
private tailrec fun solveGroup(group: Pair<LinkedList<Long>, LinkedList<Operator>>, precedence: Boolean): Long {
|
private fun solveGroup(group: Pair<LinkedList<Long>, LinkedList<Operator>>, precedence: Boolean): Long {
|
||||||
val (operands, operators) = group
|
val (operands, operators) = group
|
||||||
println(operands)
|
println(operands)
|
||||||
println(operators)
|
println(operators)
|
||||||
@ -79,7 +79,7 @@ class Day18(@Lines val input: Input<List<String>>) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return solveGroup(operands to operators, precedence = false)
|
return operands.reduce { a, b -> Operator.Multiply(a, b) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user