1 | package com.adventofcode.day01 | |
2 | ||
3 |
3
1. getFirstEntry : replaced int return with 0 for com/adventofcode/day01/EntryCode::getFirstEntry → SURVIVED 2. getSecondEntry : replaced int return with 0 for com/adventofcode/day01/EntryCode::getSecondEntry → SURVIVED 3. getThirdEntry : replaced int return with 0 for com/adventofcode/day01/EntryCode::getThirdEntry → SURVIVED |
class EntryCode(val firstEntry: Int, val secondEntry: Int, val thirdEntry: Int) { |
4 | ||
5 |
2
1. <init> : Replaced integer multiplication with division → KILLED 2. <init> : Replaced integer multiplication with division → KILLED |
private val code: Int = firstEntry * secondEntry * thirdEntry |
6 | ||
7 | ||
8 | constructor() : this(0, 0, 0) | |
9 | constructor(firstEntry: Int, secondEntry: Int) : this(firstEntry, secondEntry, 1) | |
10 | ||
11 | private val EXPECTED_SUM = 2020 | |
12 | ||
13 | private fun findTwoEntriesThatSumUpTo2020(input: List<Int>): Set<Int> { | |
14 |
2
1. findTwoEntriesThatSumUpTo2020 : Replaced integer subtraction with addition → KILLED 2. findTwoEntriesThatSumUpTo2020 : negated conditional → KILLED |
return input.associateWith { EXPECTED_SUM - it }.filterValues { input.contains(it) }.keys |
15 | } | |
16 | ||
17 | private fun findThreeEntriesThatSumUpTo2020(input: List<Int>): Set<Int> { | |
18 | val values = input | |
19 | .map { it to findTwoOtherEntriesThatSumUpTo2020With(it, input) } | |
20 | .toMap() | |
21 |
3
1. findThreeEntriesThatSumUpTo2020 : negated conditional → KILLED 2. findThreeEntriesThatSumUpTo2020 : negated conditional → KILLED 3. findThreeEntriesThatSumUpTo2020 : negated conditional → KILLED |
.filterNot { it.value.isNullOrEmpty() } |
22 | .entries | |
23 | .first() | |
24 | .toPair() | |
25 |
1
1. findThreeEntriesThatSumUpTo2020 : replaced return value with Collections.emptyList for com/adventofcode/day01/EntryCode::findThreeEntriesThatSumUpTo2020 → KILLED |
return setOf(values.first) union values.second |
26 | } | |
27 | ||
28 | private fun findTwoOtherEntriesThatSumUpTo2020With(firstEntry: Int, input: List<Int>): Set<Int> { | |
29 |
2
1. findTwoOtherEntriesThatSumUpTo2020With : Replaced integer addition with subtraction → KILLED 2. findTwoOtherEntriesThatSumUpTo2020With : Replaced integer subtraction with addition → KILLED |
return input.associateWith { EXPECTED_SUM - (firstEntry + it) } |
30 |
1
1. findTwoOtherEntriesThatSumUpTo2020With : negated conditional → KILLED |
.filterValues { input.contains(it) } |
31 | .keys | |
32 | } | |
33 | ||
34 | fun findFromTwoEntriesOf(input: List<Int>): EntryCode { | |
35 | val entries = findTwoEntriesThatSumUpTo2020(input) | |
36 | return EntryCode(entries.first(), entries.last()) | |
37 | } | |
38 | ||
39 | fun findFromThreeEntriesOf(input: List<Int>): EntryCode { | |
40 | val entries = findThreeEntriesThatSumUpTo2020(input) | |
41 | return EntryCode(entries.first(), entries.elementAt(1), entries.last()) | |
42 | } | |
43 | ||
44 | override fun toString(): String { | |
45 |
1
1. toString : replaced return value with "" for com/adventofcode/day01/EntryCode::toString → NO_COVERAGE |
return "$firstEntry + $secondEntry = $code" |
46 | } | |
47 | } | |
48 | ||
49 | ||
Mutations | ||
3 |
1.1 2.2 3.3 |
|
5 |
1.1 2.2 |
|
14 |
1.1 2.2 |
|
21 |
1.1 2.2 3.3 |
|
25 |
1.1 |
|
29 |
1.1 2.2 |
|
30 |
1.1 |
|
45 |
1.1 |
|
63 |
1.1 |
|
87 |
1.1 |