Skip to content

Commit 6948418

Browse files
committed
Small improvements for solution 2015-07
1 parent fae6fc7 commit 6948418

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main/kotlin/de/ronny_h/aoc/year2015/day07/SomeAssemblyRequired.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class SomeAssemblyRequired : AdventOfCode<Int>(2015, 7) {
2323
operations.forEach {
2424
val result = it.execute(values)
2525
if (result.out is ValueOutput) {
26-
values.put(result.wire, result.out.value)
26+
values[result.wire] = result.out.value
2727
} else {
28-
this.add(it)
28+
add(it)
2929
}
3030
}
3131
}
@@ -71,12 +71,17 @@ data class ReWire(val from: String, val out: String) : Operation {
7171
override fun execute(values: Map<String, UShort>) = Output(out, values[from]?.let { ValueOutput(it) } ?: NoSignal)
7272
}
7373

74-
data class UnaryOperation(val operand: String, val operator: UnaryOperator, val out: String) : Operation {
74+
data class UnaryOperation(private val operand: String, private val operator: UnaryOperator, val out: String) :
75+
Operation {
7576
override fun execute(values: Map<String, UShort>) = Output(out, operator.execute(values, operand))
7677
}
7778

78-
data class BinaryOperation(val op1: String, val op2: String, val operator: BinaryOperator, val out: String) :
79-
Operation {
79+
data class BinaryOperation(
80+
private val op1: String,
81+
private val op2: String,
82+
private val operator: BinaryOperator,
83+
val out: String
84+
) : Operation {
8085
override fun execute(values: Map<String, UShort>) = Output(out, operator.execute(values, op1, op2))
8186
}
8287

@@ -135,4 +140,4 @@ data class Output(val wire: String, val out: OperatorOutput)
135140
sealed interface OperatorOutput {
136141
data class ValueOutput(val value: UShort) : OperatorOutput
137142
object NoSignal : OperatorOutput
138-
}
143+
}

0 commit comments

Comments
 (0)