1 | package com.adventofcode.day14 | |
2 | ||
3 | ||
4 | typealias Memory = MutableMap<Long, Long> | |
5 | ||
6 | class MaskProgram(private val mask: String, private vararg val valuesToWriteInMemory: Pair<Long, Long>) { | |
7 | private var memory = mutableMapOf<Long, Long>() | |
8 | ||
9 | private val simplifiedMask = mask.toCharArray() | |
10 | .mapIndexed { index, it -> index to it } | |
11 |
2
1. <init> : negated conditional → KILLED 2. <init> : negated conditional → KILLED |
.filterNot { it.second == 'X' } |
12 | .toMap() | |
13 | ||
14 | private val simplifiedMaskForV2 = mask.toCharArray() | |
15 | .mapIndexed { index, it -> index to it } | |
16 |
2
1. <init> : negated conditional → KILLED 2. <init> : negated conditional → KILLED |
.filterNot { it.second == '0' } |
17 | .toMap() | |
18 | ||
19 | fun getMemory(): Memory { | |
20 | valuesToWriteInMemory.forEach { | |
21 | val valueTOWrite = longToString(it.second).toCharArray() | |
22 | simplifiedMask.forEach { | |
23 | valueTOWrite[it.key] = it.value | |
24 | } | |
25 | memory.put(it.first, stringToLong(valueTOWrite)) | |
26 | } | |
27 | ||
28 | return memory | |
29 | } | |
30 | ||
31 | fun longToString(toConvert: Long): String { | |
32 | return toConvert.toString(2).padStart(36, '0') | |
33 | } | |
34 | ||
35 | fun stringToLong(toConvert: CharArray): Long { | |
36 |
1
1. stringToLong : replaced long return with 0 for com/adventofcode/day14/MaskProgram::stringToLong → KILLED |
return toConvert.joinToString("").toLong(2) |
37 | } | |
38 | ||
39 | fun getMemoryV2(): MutableMap<Long, Long> { | |
40 | valuesToWriteInMemory.forEach { | |
41 | val memoryAdresse = it.first | |
42 | val valueToWrite = it.second | |
43 | val memoryAdresseAsString = longToString(memoryAdresse).toCharArray() | |
44 | simplifiedMaskForV2 | |
45 |
2
1. getMemoryV2 : negated conditional → SURVIVED 2. getMemoryV2 : negated conditional → SURVIVED |
.filter { it.value == '1' } |
46 | .forEach { memoryAdresseAsString[it.key] = '1' } | |
47 | ||
48 | getMemoryAdresses(memoryAdresse).forEach { | |
49 | memory[it] = valueToWrite | |
50 | } | |
51 | } | |
52 | return memory | |
53 | } | |
54 | ||
55 | fun getMemoryAdresses(memoryAddress: Long): List<Long> { | |
56 | val memoryAdresseAsString = longToString(memoryAddress).toCharArray() | |
57 | simplifiedMaskForV2 | |
58 |
2
1. getMemoryAdresses : negated conditional → KILLED 2. getMemoryAdresses : negated conditional → KILLED |
.filter { it.value == '1' } |
59 | .forEach { memoryAdresseAsString[it.key] = '1' } | |
60 | ||
61 | val XsToReplace = simplifiedMaskForV2 | |
62 |
2
1. getMemoryAdresses : negated conditional → KILLED 2. getMemoryAdresses : negated conditional → KILLED |
.filter { it.value == 'X' } |
63 | .keys | |
64 | .sorted() | |
65 | var values = listOf(memoryAdresseAsString) | |
66 | XsToReplace | |
67 | .forEach {index -> | |
68 | values | |
69 | .forEach { | |
70 | value -> | |
71 | val temp0 = value.clone() | |
72 | val temp1 = value.clone() | |
73 | temp0[index] = '0' | |
74 | temp1[index] = '1' | |
75 |
1
1. getMemoryAdresses : negated conditional → KILLED |
if(! values.contains(temp0)) { |
76 | values=values.plus(temp0).distinct() | |
77 | } | |
78 |
1
1. getMemoryAdresses : negated conditional → KILLED |
if(! values.contains(temp1)) { |
79 | values=values.plus(temp1).distinct() | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | ||
85 |
1
1. getMemoryAdresses : replaced return value with Collections.emptyList for com/adventofcode/day14/MaskProgram::getMemoryAdresses → KILLED |
return values.distinct().map { stringToLong(it) }.sorted() |
86 | } | |
87 | } | |
Mutations | ||
11 |
1.1 2.2 |
|
16 |
1.1 2.2 |
|
36 |
1.1 |
|
45 |
1.1 2.2 |
|
58 |
1.1 2.2 |
|
62 |
1.1 2.2 |
|
75 |
1.1 |
|
78 |
1.1 |
|
85 |
1.1 |
|
133 |
1.1 |
|
141 |
1.1 |