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

  • mykl@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    19 days ago

    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);
    
    • janAkali@lemmy.one
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      19 days ago

      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?