ShuttleBusService.kt

1
package com.adventofcode.day13
2
3
4
class ShuttleBusService(private val actualTimeStamp: Long, private vararg val busIds: Int) {
5
6
7
    companion object {
8
        fun readFrom(actualTimeStamp: String, busIds: String): ShuttleBusService {
9
            return ShuttleBusService(actualTimeStamp.toLong(), *busIds.split(',').filterNot { it == "x" }.map { it.toInt() }.toIntArray())
10
        }
11
    }
12
13
    fun findEarliestDeparture(): Pair<Int, Long>? {
14
        return busIds.map { it to foundNextTimeStamp(it) }.minBy { it.second }
15
    }
16
17 4 1. foundNextTimeStamp : Replaced long modulus with multiplication → KILLED
2. foundNextTimeStamp : Replaced long subtraction with addition → KILLED
3. foundNextTimeStamp : Replaced long addition with subtraction → KILLED
4. foundNextTimeStamp : replaced long return with 0 for com/adventofcode/day13/ShuttleBusService::foundNextTimeStamp → KILLED
    private fun foundNextTimeStamp(it: Int) = actualTimeStamp - actualTimeStamp.rem(it) + it
18
19
    fun findEarliestIdByWaitingTime(): Long {
20
        val earliestDeparture = findEarliestDeparture()
21
        return earliestDeparture!!.first.times(earliestDeparture.second - actualTimeStamp)
22
    }
23
}
24
25
class ShuttleBusServicePart02(vararg val busIds: String) {
26
27
    fun findEarliestTimeStampThatMatchesWithTheBusDeparturePosition(): Long {
28
29
        val busIdWithIndexReduces = busIds
30
                .mapIndexed { index, id -> id to index.toLong() }
31
                .filterNot { it.first == "x" }
32
                .map { it.first.toLong() to it.second }
33
                .sortedBy { it.second }
34
                .toMap()
35
                .toMutableMap()
36
37
        var minimalBusId = busIdWithIndexReduces.minBy { it.value }!!.key
38
        busIdWithIndexReduces.remove(minimalBusId)
39
40
        var timestamp = 0L
41
        busIdWithIndexReduces.forEach { (busId, busIndex) ->
42 3 1. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : Replaced long modulus with multiplication → TIMED_OUT
2. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : Replaced long addition with subtraction → KILLED
3. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : negated conditional → KILLED
            while ((timestamp + busIndex) % busId != 0L) {
43 1 1. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : Replaced long addition with subtraction → KILLED
                timestamp += minimalBusId
44
            }
45 1 1. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : Replaced long multiplication with division → TIMED_OUT
            minimalBusId = minimalBusId.times(busId)
46
        }
47 1 1. findEarliestTimeStampThatMatchesWithTheBusDeparturePosition : replaced long return with 0 for com/adventofcode/day13/ShuttleBusServicePart02::findEarliestTimeStampThatMatchesWithTheBusDeparturePosition → KILLED
        return timestamp
48
49
    }
50
}

Mutations

17

1.1
Location : foundNextTimeStamp
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
Replaced long modulus with multiplication → KILLED

2.2
Location : foundNextTimeStamp
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
Replaced long subtraction with addition → KILLED

3.3
Location : foundNextTimeStamp
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
Replaced long addition with subtraction → KILLED

4.4
Location : foundNextTimeStamp
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
replaced long return with 0 for com/adventofcode/day13/ShuttleBusService::foundNextTimeStamp → KILLED

42

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
Replaced long addition with subtraction → KILLED

2.2
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : none
Replaced long modulus with multiplication → TIMED_OUT

3.3
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
negated conditional → KILLED

43

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
Replaced long addition with subtraction → KILLED

45

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : none
Replaced long multiplication with division → TIMED_OUT

47

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
replaced long return with 0 for com/adventofcode/day13/ShuttleBusServicePart02::findEarliestTimeStampThatMatchesWithTheBusDeparturePosition → KILLED

52

1.1
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
changed conditional boundary → KILLED

2.2
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
Changed increment from 1 to -1 → KILLED

3.3
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
negated conditional → KILLED

54

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
Changed increment from 1 to -1 → KILLED

56

1.1
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
negated conditional → KILLED

59

1.1
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyOneBus()]
negated conditional → KILLED

62

1.1
Location : findEarliestDeparture
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
negated conditional → KILLED

67

1.1
Location : findEarliestDeparture
Killed by : com.adventofcode.day13.ShuttleBusServiceTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.ShuttleBusServiceTest]/[method:shouldFindEarliestTimeStampWithOnyTwoBus()]
replaced return value with null for com/adventofcode/day13/ShuttleBusService::findEarliestDeparture → KILLED

69

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : none
negated conditional → SURVIVED

72

1.1
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : findEarliestTimeStampThatMatchesWithTheBusDeparturePosition
Killed by : com.adventofcode.day13.Day13KtTest.[engine:junit-jupiter]/[class:com.adventofcode.day13.Day13KtTest]/[method:shouldFindExpectedResultWithGivenInputForPart02()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.6.1