Start day 2

This commit is contained in:
2025-12-04 09:41:32 -06:00
parent 47083ae033
commit 096d329457
5 changed files with 104 additions and 0 deletions

View File

@@ -1,9 +1,11 @@
import 'package:adventofcode2025/day1/command.dart' as day1; import 'package:adventofcode2025/day1/command.dart' as day1;
import 'package:adventofcode2025/day2/command.dart' as day2;
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
void main(List<String> arguments) { void main(List<String> arguments) {
CommandRunner("adventofcode2025", "Advent of Code 2025 solutions") CommandRunner("adventofcode2025", "Advent of Code 2025 solutions")
..addCommand(day1.Day1Command()) ..addCommand(day1.Day1Command())
..addCommand(day2.Day2Command())
..run(arguments); ..run(arguments);
} }

1
inputs/day2/large.txt Normal file
View File

@@ -0,0 +1 @@
2558912-2663749,1-19,72-85,82984-100358,86-113,193276-237687,51-69,779543-880789,13004-15184,2768-3285,4002-4783,7702278-7841488,7025-8936,5858546565-5858614010,5117615-5149981,4919-5802,411-466,126397-148071,726807-764287,7454079517-7454227234,48548-61680,67606500-67729214,9096-10574,9999972289-10000034826,431250-455032,907442-983179,528410-680303,99990245-100008960,266408-302255,146086945-146212652,9231222-9271517,32295166-32343823,32138-36484,4747426142-4747537765,525-652,333117-414840,13413537-13521859,1626-1972,49829276-50002273,69302-80371,8764571787-8764598967,5552410836-5552545325,660-782,859-1056

1
inputs/day2/small.txt Normal file
View File

@@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

55
lib/day2/README.txt Normal file
View File

@@ -0,0 +1,55 @@
Advent of Code
[About][Events][Shop][Settings][Log Out]
Bearmine 2*
λy.2025
[Calendar][AoC++][Sponsors][Leaderboards][Stats]
Our sponsors help make Advent of Code possible:
Honeycomb - The observability platform that helps teams solve problems they couldn't before, with unified telemetry and fast, powerful querying.
--- Day 2: Gift Shop ---
You get inside and take the elevator to its only other stop: the gift shop. "Thank you for visiting the North Pole!" gleefully exclaims a nearby sign. You aren't sure who is even allowed to visit the North Pole, but you know you can access the lobby through here, and from there you can access the rest of the North Pole base.
As you make your way through the surprisingly extensive selection, one of the clerks recognizes you and asks for your help.
As it turns out, one of the younger Elves was playing on a gift shop computer and managed to add a whole bunch of invalid product IDs to their gift shop database! Surely, it would be no trouble for you to identify the invalid product IDs for them, right?
They've even checked most of the product ID ranges already; they only have a few product ID ranges (your puzzle input) that you'll need to check. For example:
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,
1698522-1698528,446443-446449,38593856-38593862,565653-565659,
824824821-824824827,2121212118-2121212124
(The ID ranges are wrapped here for legibility; in your input, they appear on a single long line.)
The ranges are separated by commas (,); each range gives its first ID and last ID separated by a dash (-).
Since the young Elf was just doing silly patterns, you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice. So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.
None of the numbers have leading zeroes; 0101 isn't an ID at all. (101 is a valid ID that you would ignore.)
Your job is to find all of the invalid IDs that appear in the given ranges. In the above example:
11-22 has two invalid IDs, 11 and 22.
95-115 has one invalid ID, 99.
998-1012 has one invalid ID, 1010.
1188511880-1188511890 has one invalid ID, 1188511885.
222220-222224 has one invalid ID, 222222.
1698522-1698528 contains no invalid IDs.
446443-446449 has one invalid ID, 446446.
38593856-38593862 has one invalid ID, 38593859.
The rest of the ranges contain no invalid IDs.
Adding up all the invalid IDs in this example produces 1227775554.
What do you get if you add up all of the invalid IDs?
To begin, get your puzzle input.
Answer:
You can also [Shareon Bluesky Twitter Mastodon] this puzzle.

45
lib/day2/command.dart Normal file
View File

@@ -0,0 +1,45 @@
import "dart:convert";
import "dart:io";
import "package:args/command_runner.dart";
class Day2Command extends Command {
// The [name] and [description] properties must be defined by every
// subclass.
@override
final name = "day2";
@override
final description = "Run Advent of Code 2025 Day 2";
Day2Command() {
// 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}",
);
}
var filePath = argResults!.rest[0];
print("Parsing file: $filePath");
var inputFile = File(filePath);
var openFile = inputFile.openRead();
var lines = openFile.transform(utf8.decoder).transform(LineSplitter());
await for (var line in lines) {
print(line);
print('-------');
}
}
}