| 1 | package com.roxoft.aoc.y2015.Day4; | |
| 2 | ||
| 3 | import com.roxoft.lib.Analyse; | |
| 4 | import com.roxoft.lib.From; | |
| 5 | ||
| 6 | import java.security.NoSuchAlgorithmException; | |
| 7 | ||
| 8 | public final class Day4 { | |
| 9 | /** The problem value being run. */ | |
| 10 | private final String value; | |
| 11 | ||
| 12 | private Day4(final String input) { | |
| 13 | value = input; | |
| 14 | } | |
| 15 | ||
| 16 | /** | |
| 17 | * @param input the problem value to run the solution against. | |
| 18 | * @return A new {@link Day4} object for running the solution. | |
| 19 | */ | |
| 20 | public static Day4 with(final String input) { | |
| 21 |
1
1. with : replaced return value with null for com/roxoft/aoc/y2015/Day4/Day4::with → KILLED |
return new Day4(input); |
| 22 | } | |
| 23 | ||
| 24 | /** | |
| 25 | * @return The solution to problem A given the current setup. | |
| 26 | * @throws NoSuchAlgorithmException if MD5 algorithm is not present. | |
| 27 | */ | |
| 28 | public String solutionA() throws NoSuchAlgorithmException { | |
| 29 |
1
1. solutionA : replaced return value with "" for com/roxoft/aoc/y2015/Day4/Day4::solutionA → KILLED |
return solution(5); |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * @return The solution to problem A given the current setup. | |
| 34 | * @throws NoSuchAlgorithmException if MD5 algorithm is not present. | |
| 35 | */ | |
| 36 | public String solutionB() throws NoSuchAlgorithmException { | |
| 37 |
1
1. solutionB : replaced return value with "" for com/roxoft/aoc/y2015/Day4/Day4::solutionB → KILLED |
return solution(6); |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * XXX This is a very slow implementation, worth looking at optimisations. | |
| 42 | * | |
| 43 | * @param characterRepetitions number of character repetitions to look for. | |
| 44 | * @return The solution to problem given the current setup. | |
| 45 | * @throws NoSuchAlgorithmException if MD5 algorithm is not present. | |
| 46 | */ | |
| 47 | private String solution(final int characterRepetitions) throws NoSuchAlgorithmException { | |
| 48 |
3
1. solution : Replaced integer addition with subtraction → SURVIVED 2. solution : negated conditional → SURVIVED 3. solution : Replaced integer modulus with multiplication → SURVIVED |
final int requiredHexCharacters = characterRepetitions % 2 == 0 ? characterRepetitions : characterRepetitions + 1; |
| 49 | int i = 0; | |
| 50 | while (true) { | |
| 51 | final String testValue = value + i; | |
| 52 | final String md5Hex = From.string(testValue).toMD5Hex(requiredHexCharacters); | |
| 53 | ||
| 54 |
1
1. solution : negated conditional → KILLED |
if (Analyse.string(md5Hex).startsWith(characterRepetitions, '0')) { |
| 55 |
1
1. solution : replaced return value with "" for com/roxoft/aoc/y2015/Day4/Day4::solution → KILLED |
return testValue; |
| 56 | } | |
| 57 |
1
1. solution : Changed increment from 1 to -1 → KILLED |
i++; |
| 58 | } | |
| 59 | } | |
| 60 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 29 |
1.1 |
|
| 37 |
1.1 |
|
| 48 |
1.1 2.2 3.3 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 57 |
1.1 |