Setup day 5
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:adventofcode2025/day1/command.dart' as day1;
|
|||||||
import 'package:adventofcode2025/day2/command.dart' as day2;
|
import 'package:adventofcode2025/day2/command.dart' as day2;
|
||||||
import 'package:adventofcode2025/day3/command.dart' as day3;
|
import 'package:adventofcode2025/day3/command.dart' as day3;
|
||||||
import 'package:adventofcode2025/day4/command.dart' as day4;
|
import 'package:adventofcode2025/day4/command.dart' as day4;
|
||||||
|
import 'package:adventofcode2025/day5/command.dart' as day5;
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
|
|
||||||
@@ -11,5 +12,6 @@ void main(List<String> arguments) {
|
|||||||
..addCommand(day2.Day2Command())
|
..addCommand(day2.Day2Command())
|
||||||
..addCommand(day3.Day3Command())
|
..addCommand(day3.Day3Command())
|
||||||
..addCommand(day4.Day4Command())
|
..addCommand(day4.Day4Command())
|
||||||
|
..addCommand(day5.Day5Command())
|
||||||
..run(arguments);
|
..run(arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
1193
inputs/day5/large.txt
Normal file
1193
inputs/day5/large.txt
Normal file
File diff suppressed because it is too large
Load Diff
11
inputs/day5/small.txt
Normal file
11
inputs/day5/small.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3-5
|
||||||
|
10-14
|
||||||
|
16-20
|
||||||
|
12-18
|
||||||
|
|
||||||
|
1
|
||||||
|
5
|
||||||
|
8
|
||||||
|
11
|
||||||
|
17
|
||||||
|
32
|
||||||
@@ -55,7 +55,7 @@ class Day4Command extends Command {
|
|||||||
final name = "day4";
|
final name = "day4";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final description = "Run Advent of Code 2025 Day 3";
|
final description = "Run Advent of Code 2025 Day 4";
|
||||||
|
|
||||||
Day4Command() {
|
Day4Command() {
|
||||||
// we can add command specific arguments here.
|
// we can add command specific arguments here.
|
||||||
|
|||||||
45
lib/day5/command.dart
Normal file
45
lib/day5/command.dart
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import "dart:convert";
|
||||||
|
import "dart:io";
|
||||||
|
|
||||||
|
import "package:args/command_runner.dart";
|
||||||
|
|
||||||
|
class Day5Command extends Command {
|
||||||
|
// The [name] and [description] properties must be defined by every
|
||||||
|
// subclass.
|
||||||
|
@override
|
||||||
|
final name = "day5";
|
||||||
|
|
||||||
|
@override
|
||||||
|
final description = "Run Advent of Code 2025 Day 5";
|
||||||
|
|
||||||
|
Day5Command() {
|
||||||
|
// we can add command specific arguments here.
|
||||||
|
// [argParser] is automatically created by the parent class.
|
||||||
|
}
|
||||||
|
|
||||||
|
// [run] may also return a Future.
|
||||||
|
@override
|
||||||
|
Future<void> run() async {
|
||||||
|
// [argResults] is set before [run()] is called and contains the flags/options
|
||||||
|
// passed to this command.
|
||||||
|
|
||||||
|
if (argResults!.rest.length != 1) {
|
||||||
|
print(
|
||||||
|
"Expected 1 positional arguments, found ${argResults!.rest.length}",
|
||||||
|
);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
var filePath = argResults!.rest[0];
|
||||||
|
|
||||||
|
print("Parsing file: $filePath");
|
||||||
|
var inputFile = File(filePath);
|
||||||
|
var result = await inputFile
|
||||||
|
.openRead()
|
||||||
|
.transform(utf8.decoder)
|
||||||
|
.transform(LineSplitter())
|
||||||
|
.map((line) {
|
||||||
|
return line;
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user