-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b96101
commit b418af8
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// --- Day 11: Plutonian Pebbles --- | ||
// https://adventofcode.com/2024/day/11 | ||
|
||
import 'dart:collection'; | ||
|
||
final class Stone extends LinkedListEntry<Stone> { | ||
int value; | ||
|
||
Stone(this.value); | ||
} | ||
|
||
int solveA(String input, {int blink = 25}) => solve(input, blink: blink); | ||
int solveB(String input) => solve(input, blink: 75); | ||
|
||
int solve(String input, {int blink = 25}) { | ||
final stones = LinkedList<Stone>(); | ||
|
||
for (final stoneValue in input.split(' ').map(int.parse)) { | ||
stones.add(Stone(stoneValue)); | ||
} | ||
|
||
for (var i = 0; i < blink; i++) { | ||
Stone? stone = stones.first; | ||
|
||
while (stone != null) { | ||
if (stone.value == 0) { | ||
stone.value = 1; | ||
} else if (stone.value.toString() case final numberString | ||
when numberString.length % 2 == 0) { | ||
stone.insertBefore(Stone( | ||
int.parse(numberString.substring(0, numberString.length ~/ 2)))); | ||
stone.value = | ||
int.parse(numberString.substring(numberString.length ~/ 2)); | ||
} else { | ||
stone.value *= 2024; | ||
} | ||
|
||
stone = stone.next; | ||
} | ||
} | ||
|
||
return stones.length; | ||
} |
Submodule data
updated
from 2a0a6b to 02ed5e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// --- Day 11: Plutonian Pebbles --- | ||
// https://adventofcode.com/2024/day/11 | ||
|
||
import 'dart:io'; | ||
import 'package:advent_of_code_2024/day11.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
final input = File('test/data/day11.txt').readAsLinesSync().first; | ||
|
||
void main() { | ||
group('Part One', () { | ||
test('Example 1', () { | ||
expect(solveA('0 1 10 99 999', blink: 1), equals(7)); | ||
}); | ||
test('Example 2', () { | ||
expect(solveA('125 17', blink: 1), equals(3)); | ||
}); | ||
test('Example 3', () { | ||
expect(solveA('125 17', blink: 6), equals(22)); | ||
}); | ||
test('Example 4', () { | ||
expect(solveA('125 17'), equals(55312)); | ||
}); | ||
test('Solution', () { | ||
expect(solveA(input), equals(193607)); | ||
}); | ||
}); | ||
group('Part Two', () { | ||
test('Solution', () { | ||
expect(solveB(input), equals(-1)); | ||
}); | ||
}, skip: true); | ||
} |