1 | package com.adventofcode.day03 | |
2 | ||
3 | class TobogganTrajectory(private val gridWithTrees: Grid, private val slopesModel: SlopesModel) { | |
4 | ||
5 | constructor() : this(Grid(listOf("")), CheaperSlopesModel()) | |
6 | ||
7 | companion object { | |
8 | fun fromInputWithSlopeModel(inputGridWithTrees: String, slopesModel: SlopesModel): TobogganTrajectory { | |
9 | return TobogganTrajectory(Grid.fromInput(inputGridWithTrees), slopesModel) | |
10 | } | |
11 | } | |
12 | ||
13 | private var encounteredTrees: Int = 0 | |
14 | ||
15 | override fun toString(): String { | |
16 |
1
1. toString : replaced return value with "" for com/adventofcode/day03/TobogganTrajectory::toString → NO_COVERAGE |
return "Toboggan Trajectory: $encounteredTrees tree(s) encountered" |
17 | } | |
18 | ||
19 | fun treesEncountered(): Int { | |
20 |
1
1. treesEncountered : replaced int return with 0 for com/adventofcode/day03/TobogganTrajectory::treesEncountered → KILLED |
return encounteredTrees |
21 | } | |
22 | ||
23 | fun downTheSlope() { | |
24 | var position = Triple(0, 0, '.') | |
25 | val lastLineOnGrid = gridWithTrees.lastLine() | |
26 | ||
27 |
2
1. downTheSlope : changed conditional boundary → SURVIVED 2. downTheSlope : negated conditional → KILLED |
while (position.first < lastLineOnGrid){ |
28 | position = slopesModel.moveOn(gridWithTrees) | |
29 |
1
1. downTheSlope : negated conditional → KILLED |
if (position.third == '#') { |
30 |
1
1. downTheSlope : Replaced integer addition with subtraction → KILLED |
encounteredTrees += 1 |
31 | } | |
32 | } | |
33 | ||
34 | } | |
35 | ||
36 | } | |
Mutations | ||
16 |
1.1 |
|
20 |
1.1 |
|
27 |
1.1 2.2 |
|
29 |
1.1 |
|
30 |
1.1 |