this post was submitted on 08 Dec 2024
23 points (96.0% liked)

Advent Of Code

985 readers
28 users here now

An unofficial home for the advent of code community on programming.dev!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 1 year ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 2 weeks ago (1 children)

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);
[โ€“] [email protected] 4 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

maybe Eric and co have begun to realise that family time is more precious than work time

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?

[โ€“] [email protected] 4 points 2 weeks ago

Maybe we've been good all year :-)