diff --git a/lib/day1/README.txt b/lib/day1/README.txt index 0f8fcbb..4ea52ef 100644 --- a/lib/day1/README.txt +++ b/lib/day1/README.txt @@ -3,13 +3,11 @@ Advent of Code [About][Events][Shop][Settings][Log Out] -Bearmine 1* - 0.0.0.0:2025 +Bearmine 4* + {year=>2025} [Calendar][AoC++][Sponsors][Leaderboards][Stats] -Our sponsors help make Advent of Code possible: -Jane Street - We're a research-driven trading firm where curious people work together to solve the puzzle of global markets, with offices in NYC, London, Hong Kong, and Singapore. Check out our new JS Advent of FPGA Challenge! --- Day 1: Secret Entrance --- The Elves have good news and bad news. @@ -72,8 +70,6 @@ Because the dial points at 0 a total of three times during this process, the pas Analyze the rotations in your attached document. What's the actual password to open the door? Your puzzle answer was 964. - -The first half of this puzzle is complete! It provides one gold star: * --- Part Two --- You're sure that's the right password, but the door won't open. You knock, but nobody answers. You build a snowman while you think. @@ -104,8 +100,12 @@ Be careful: if the dial were pointing at 50, a single rotation like R1000 would Using password method 0x434C49434B, what is the password to open the door? -Answer: +Your puzzle answer was 5872. -Although it hasn't changed, you can still get your puzzle input. +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. You can also [Shareon Bluesky Twitter Mastodon] this puzzle. diff --git a/lib/day2/README.txt b/lib/day2/README.txt index c0b604d..189ec73 100644 --- a/lib/day2/README.txt +++ b/lib/day2/README.txt @@ -3,13 +3,11 @@ Advent of Code [About][Events][Shop][Settings][Log Out] -Bearmine 2* - λy.2025 +Bearmine 4* + 0.0.0.0: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. @@ -48,8 +46,37 @@ 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. +Your puzzle answer was 44854383294. +--- Part Two --- -Answer: +The clerk quickly discovers that there are still invalid IDs in the ranges in your list. Maybe the young Elf was doing other silly patterns as well? + +Now, an ID is invalid if it is made only of some sequence of digits repeated at least twice. So, 12341234 (1234 two times), 123123123 (123 three times), 1212121212 (12 five times), and 1111111 (1 seven times) are all invalid IDs. + +From the same example as before: + + 11-22 still has two invalid IDs, 11 and 22. + 95-115 now has two invalid IDs, 99 and 111. + 998-1012 now has two invalid IDs, 999 and 1010. + 1188511880-1188511890 still has one invalid ID, 1188511885. + 222220-222224 still has one invalid ID, 222222. + 1698522-1698528 still contains no invalid IDs. + 446443-446449 still has one invalid ID, 446446. + 38593856-38593862 still has one invalid ID, 38593859. + 565653-565659 now has one invalid ID, 565656. + 824824821-824824827 now has one invalid ID, 824824824. + 2121212118-2121212124 now has one invalid ID, 2121212121. + +Adding up all the invalid IDs in this example produces 4174379265. + +What do you get if you add up all of the invalid IDs using these new rules? + +Your puzzle answer was 55647141923. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. You can also [Shareon Bluesky Twitter Mastodon] this puzzle. diff --git a/lib/day2/command.dart b/lib/day2/command.dart index 8e02731..52baa02 100644 --- a/lib/day2/command.dart +++ b/lib/day2/command.dart @@ -1,4 +1,3 @@ -import "dart:convert"; import "dart:io"; import "package:args/command_runner.dart"; @@ -34,7 +33,10 @@ class Day2Command extends Command { var inputFile = File(filePath); var openFile = await inputFile.readAsString(); - var part1Answer = openFile + + RegExp exp = RegExp(r'^([0-9]+)\1+$'); + + var ids = openFile .trim() .split(',') .expand((range) { @@ -49,15 +51,26 @@ class Day2Command extends Command { List.generate(to - from + 1, (i) => i + from); return createRange(numRange[0], numRange[1]); }) - .map((id) => id.toString()) + .map((id) => id.toString()); + + var part1Answer = ids .where((id) => id.length.isEven) .where((id) { - var first_half = id.substring(0, (id.length / 2).floor()); - var second_half = id.substring((id.length / 2).floor(), id.length); - return first_half == second_half; + var firstHalf = id.substring(0, (id.length / 2).floor()); + var secondHalf = id.substring((id.length / 2).floor(), id.length); + return firstHalf == secondHalf; }) .map((id) => int.parse(id)) .reduce((id1, id2) => id1 + id2); print("Part 1 Answer: $part1Answer"); + + var part2Answer = ids + .where((id) => exp.hasMatch(id)) + .map((id) { + //print(id); + return int.parse(id); + }) + .reduce((id1, id2) => id1 + id2); + print("Part 2 Answer: $part2Answer"); } }