Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
.dart_tool/package_config.json
.dart_tool/aoc
.packages
build/
build/

# Advent of Code FAQ states we shouldn't include our inputs in code repository,
# so we are ignoring the input textfiles
input/*

!input/aoc00.txt
1 change: 0 additions & 1 deletion day_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class Day$dayNumber extends GenericDay {
return 0;
}
}

''';
}

Expand Down
20 changes: 20 additions & 0 deletions input/aoc00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
5
7
9
2
7
6
9
4
6
6
9
3
3
5
9
1
6
9
2
8
Empty file removed input/aoc01.txt
Empty file.
2 changes: 1 addition & 1 deletion main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'tool/generic_day.dart';

/// List holding all the solution classes.
final days = <GenericDay>[
Day01(),
Day00(),
];

void main(List<String?> args) {
Expand Down
10 changes: 4 additions & 6 deletions solutions/day01.dart → solutions/day00.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import '../utils/index.dart';
/// Naming convention is set to pad any single-digit day with `0` to have proper
/// ordering of files and correct mapping between input for days and the day
/// files.
class Day01 extends GenericDay {
class Day00 extends GenericDay {
// call the superclass with an integer == today´s day
Day01() : super(1);
Day00() : super(0);

/// The [InputUtil] can be accessed through the superclass variable `input`. \
/// There are several methods in that class that parse the input in different
Expand All @@ -27,13 +27,11 @@ class Day01 extends GenericDay {
/// solution will be printed in main.
@override
int solvePart1() {
// TODO implement
return 0;
return parseInput().reduce((value, element) => value + element);
}

@override
int solvePart2() {
// TODO implement
return 0;
return parseInput().reduce((value, element) => value * element);
}
}
2 changes: 1 addition & 1 deletion solutions/index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is an index file for grouped exports of all solutions. It is used to
// avoid cluttering main with imports for every day. Additionally, it makes
// boilerplate code creation with the CLI easier.
export 'day01.dart';
export 'day00.dart';
87 changes: 87 additions & 0 deletions test/day00_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ignore_for_file: unnecessary_null_comparison

import 'package:test/test.dart';

import '../solutions/day00.dart';

// *******************************************************************
// Fill out the variables below according to the puzzle description!
// The test code should usually not need to be changed, apart from uncommenting
// the puzzle tests for regression testing.
// *******************************************************************

/// Paste in the small example that is given for the FIRST PART of the puzzle.
/// It will be evaluated again the `_exampleSolutionPart1` below.
/// Make sure to respect the multiline string format to avoid additional
/// newlines at the end.
const _exampleInput1 = '''
2
3
4''';

/// Paste in the small example that is given for the SECOND PART of the puzzle.
/// It will be evaluated against the `_exampleSolutionPart2` below.
///
/// In case the second part uses the same example, uncomment below line instead:
// const _exampleInput2 = _exampleInput1;
const _exampleInput2 = '''
2
3
4
5
''';

/// The solution for the FIRST PART's example, which is given by the puzzle.
const _exampleSolutionPart1 = 9;

/// The solution for the SECOND PART's example, which is given by the puzzle.
const _exampleSolutionPart2 = 120;

/// The actual solution for the FIRST PART of the puzzle, based on your input.
/// This can only be filled out after you have solved the puzzle and is used
/// for regression testing when refactoring.
/// As long as the variable is `null`, the tests will be skipped.
const _puzzleSolutionPart1 = 116;

/// The actual solution for the SECOND PART of the puzzle, based on your input.
/// This can only be filled out after you have solved the puzzle and is used
/// for regression testing when refactoring.
/// As long as the variable is `null`, the tests will be skipped.
const _puzzleSolutionPart2 = null;

void main() {
group(
'Day 00 - Example Input',
() {
test('Part 1', () {
final day = Day00()..inputForTesting = _exampleInput1;
expect(day.solvePart1(), _exampleSolutionPart1);
});
test('Part 2', () {
final day = Day00()..inputForTesting = _exampleInput2;
expect(day.solvePart2(), _exampleSolutionPart2);
});
},
);

group(
'Day 00 - Puzzle Input',
() {
final day = Day00();
test(
'Part 1',
skip: _puzzleSolutionPart1 == null
? 'Skipped because _puzzleSolutionPart1 is null'
: false,
() => expect(day.solvePart1(), _puzzleSolutionPart1),
);
test(
'Part 2',
skip: _puzzleSolutionPart2 == null
? 'Skipped because _puzzleSolutionPart2 is null'
: false,
() => expect(day.solvePart2(), _puzzleSolutionPart2),
);
},
);
}
3 changes: 2 additions & 1 deletion utils/input_util.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert' show LineSplitter;
import 'dart:io';

/// Automatically reads reads the contents of the input file for given `day`. \
Expand All @@ -23,7 +24,7 @@ class InputUtil {
/// final lines = input.getPerLine();
InputUtil.fromMultiLineString(String input)
: _inputAsString = input,
_inputAsList = input.split('\n');
_inputAsList = const LineSplitter().convert(input);

final String _inputAsString;
final List<String> _inputAsList;
Expand Down