Day 8: Resonant Collinearity
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
Dart
This really does feel like a weekend break this year, maybe Eric and co have begun to realise that family time is more precious than work time :-)
import 'dart:math'; import 'package:more/more.dart'; solve(List<String> lines, int min, int max) { var map = ListMultimap<String, Point<int>>(); for (var r in lines.indices()) { for (var ci in lines[r].split('').indexed()) { if (ci.value != '.') map[ci.value].add(Point(ci.index, r)); } } var anti = <Point<int>>{}; for (var k in map.keys) { for (var p in map[k].combinations(2, repetitions: false)) { var diff = p.last - p.first; for (var m in min.to(max)) { anti.addAll([p.first - diff * m, p.last + diff * m]); } } } return anti.count((e) => e.x.between(0, lines.first.length - 1) && e.y.between(0, lines.length - 1)); } part1(List<String> lines) => solve(lines, 1, 2); part2(List<String> lines) => solve(lines, 0, 50);
Last year the difficulty was fluctuating from 0 to 100 each day.
This year all problems so far are suspiciously easy. Maybe the second half of the month will be extra hard?
Maybe we’ve been good all year :-)