import "dart:convert"; import "dart:io"; import "package:args/command_runner.dart"; enum Direction { left, right } class Rotation { Direction direction; int amount; Rotation(this.direction, this.amount); @override String toString() { return '{ direction: ${direction.name}, amount: $amount }'; } } Future> parseInputFile(String filePath) async { var inputFile = File(filePath); var openFile = inputFile.openRead(); var lines = openFile.transform(utf8.decoder).transform(LineSplitter()); List inputList = []; await for (var line in lines) { var dir = line.substring(0, 1); var amount = int.parse(line.substring(1, line.length)); inputList.add( Rotation(dir == 'L' ? Direction.left : Direction.right, amount), ); } return inputList; } class Day1Command extends Command { // The [name] and [description] properties must be defined by every // subclass. @override final name = "day1"; @override final description = "Run Advent of Code 2025 Day 1"; Day1Command() { // we can add command specific arguments here. // [argParser] is automatically created by the parent class. } // [run] may also return a Future. @override Future 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 fileName = argResults!.rest[0]; print("Parsing file: $fileName"); var list = await parseInputFile(fileName); int dialValue = 50; int combinationPart1 = 0; int combinationPart2 = 0; for (var instruction in list) { switch (instruction.direction) { case Direction.left: // Count full rotations combinationPart2 += (instruction.amount / 100).floor(); // Count additive rotations (remainder + previous value) if (dialValue != 0 && (dialValue - (instruction.amount % 100)) <= 0) { combinationPart2++; } // Dial counter-clockwise by amount dialValue -= instruction.amount; case Direction.right: // Dial clockwise by amount dialValue += instruction.amount; combinationPart2 += (dialValue / 100).floor(); } dialValue = dialValue % 100; if (dialValue == 0) { combinationPart1++; } } print("Combination - part 1: $combinationPart1"); print("Combination - part 2: $combinationPart2"); } }