HomeMadeAdapter.kt

1
package com.adventofcode.day10
2
3
typealias  Adapters = List<Adapter>
4
typealias Adapter = Int
5
6
enum class JoltDifferences(private val jolts: Int) {
7
    ONE_JOLT_DIFF(1), THREE_JOLT_DIFF(3);
8
9
    companion object {
10
        fun forDiff(diff: Int): JoltDifferences {
11 3 1. forDiff : Changed increment from 1 to -1 → KILLED
2. forDiff : negated conditional → KILLED
3. forDiff : negated conditional → KILLED
            return JoltDifferences.values().first { it.jolts == diff }
12
        }
13
    }
14
}
15
16
class HomeMadeAdapter(private val adaptersJolts: Adapters) {
17
18
    private val startingJolt = 0
19
    val rateJolts = adaptersJolts.max()!! + 3
20
21
    constructor(adaptersAsString: String) : this(adaptersAsString.split('\n').map { it.toInt() }.sorted())
22
23
    fun joinAdapters(): Map<JoltDifferences?, Int> {
24
25
        val availableAdapters: MutableMap<Adapter, JoltDifferences?> = adaptersJolts.map { it to null }.toMap().toMutableMap()
26
        var joltage = startingJolt
27 2 1. joinAdapters : negated conditional → KILLED
2. joinAdapters : negated conditional → KILLED
        while (availableAdapters.any { it.value == null }) {
28 1 1. joinAdapters : negated conditional → KILLED
            val adapterToUse = findMinimalAdapterToPlugWith(joltage) ?: rateJolts
29 1 1. joinAdapters : Replaced integer subtraction with addition → KILLED
            availableAdapters[adapterToUse] = JoltDifferences.forDiff(adapterToUse - joltage)
30
            joltage = adapterToUse
31
        }
32
        return availableAdapters.map { it.value }.groupBy { it }.map { it.key to it.value.size }.toMap()
33
    }
34
35
    private fun findMinimalAdapterToPlugWith(joltage: Int): Adapter? {
36
        val adaptersToUse = findAdaptersToPlugWith(joltage, adaptersJolts)
37 1 1. findMinimalAdapterToPlugWith : replaced Integer return value with 0 for com/adventofcode/day10/HomeMadeAdapter::findMinimalAdapterToPlugWith → KILLED
        return adaptersToUse.min()
38
    }
39
40
    private fun findAdaptersToPlugWith(joltage: Int, adapters: Adapters): Adapters {
41 1 1. findAdaptersToPlugWith : Replaced integer addition with subtraction → KILLED
        val authorizedJolts = 1.rangeTo(3).map { joltage + it }.toList()
42 1 1. findAdaptersToPlugWith : negated conditional → KILLED
        return adapters.filter { it in authorizedJolts }
43
    }
44
45
    fun findAllValidArrangements(): Long {
46
        val allAdapters = adaptersJolts.map { it.toLong() }.sorted()
47
        val validPaths = mutableMapOf(0L to 1L)
48
        allAdapters.forEach {
49
            adapterIndex ->
50 1 1. findAllValidArrangements : Replaced long subtraction with addition → KILLED
            validPaths[adapterIndex] = (1..3).map { previousAdapterIndex -> validPaths.getOrDefault(adapterIndex-previousAdapterIndex, 0) }.sum()
51
        }
52 1 1. findAllValidArrangements : replaced long return with 0 for com/adventofcode/day10/HomeMadeAdapter::findAllValidArrangements → KILLED
        return validPaths.getValue(allAdapters.last())
53
    }
54
55
56
57
}
58

Mutations

11

1.1
Location : forDiff
Killed by : com.adventofcode.day10.JoltDifferencesTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.JoltDifferencesTest]/[method:shouldRetriedMemberAccordingToTheGivenDifferential()]
Changed increment from 1 to -1 → KILLED

2.2
Location : forDiff
Killed by : com.adventofcode.day10.JoltDifferencesTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.JoltDifferencesTest]/[method:shouldRetriedMemberAccordingToTheGivenDifferential()]
negated conditional → KILLED

3.3
Location : forDiff
Killed by : com.adventofcode.day10.JoltDifferencesTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.JoltDifferencesTest]/[method:shouldRetriedMemberAccordingToTheGivenDifferential()]
negated conditional → KILLED

27

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

2.2
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

28

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

29

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
Replaced integer subtraction with addition → KILLED

37

1.1
Location : findMinimalAdapterToPlugWith
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
replaced Integer return value with 0 for com/adventofcode/day10/HomeMadeAdapter::findMinimalAdapterToPlugWith → KILLED

41

1.1
Location : findAdaptersToPlugWith
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
Replaced integer addition with subtraction → KILLED

42

1.1
Location : findAdaptersToPlugWith
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

50

1.1
Location : findAllValidArrangements
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldReturnAllValidArrangementAsExpected()]
Replaced long subtraction with addition → KILLED

52

1.1
Location : findAllValidArrangements
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldReturnAllValidArrangementAsExpected()]
replaced long return with 0 for com/adventofcode/day10/HomeMadeAdapter::findAllValidArrangements → KILLED

60

1.1
Location : forDiff
Killed by : com.adventofcode.day10.JoltDifferencesTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.JoltDifferencesTest]/[method:shouldRetriedMemberAccordingToTheGivenDifferential()]
changed conditional boundary → KILLED

2.2
Location : forDiff
Killed by : com.adventofcode.day10.JoltDifferencesTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.JoltDifferencesTest]/[method:shouldRetriedMemberAccordingToTheGivenDifferential()]
negated conditional → KILLED

64

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

66

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

76

1.1
Location : joinAdapters
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
negated conditional → KILLED

95

1.1
Location : findAdaptersToPlugWith
Killed by : com.adventofcode.day10.HomeMadeAdapterTest.[engine:junit-jupiter]/[class:com.adventofcode.day10.HomeMadeAdapterTest]/[method:shouldFindDifferencesAfterJoiningAdapters()]
replaced return value with Collections.emptyList for com/adventofcode/day10/HomeMadeAdapter::findAdaptersToPlugWith → KILLED

Active mutators

Tests examined


Report generated by PIT 1.6.1