CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 06:14:25 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=096f39f968e0cd2f24d9f7fad51f1e2d0d4c998f7251f13a9ab5fe05ac0cdf54a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22x-lbCAIyeEUvHC6MQptB7BUuM2KmXEHk%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc3797993fd3d4-BLR
AoC 2024, day 10 (Perl) - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- use List::AllUtils qw(sum indexes);
- use Math::Vector::Real;
- my ($y,$x) = Math::Vector::Real->canonical_base(2);
- my @Dirs = ($y, $x, -$y, -$x);
- # Read in grid, adding sentinel 99s to right and bottom
- my @Grid = map { chomp; [map {int} split(//), 99] } <>;
- push( @Grid, [(99) x $Grid[0]->@*] );
- sub grid_at ($) { my $p = shift; return ($Grid[$p->[0]][$p->[1]]) }
- # Get trailheads
- my @trailheads;
- foreach my $y (0 .. @Grid - 2) {
- push( @trailheads, map {V($y,$_)} indexes {$_ == 0} $Grid[$y]->@* );
- }
- # Recurse on pos, return is hash of trail ends => number of routes
- sub recurse {
- my ($pos) = @_;
- my $next = grid_at($pos) + 1;
- return ($pos => 1) if ($next == 10); # found 1 route to pos
- my %ret;
- foreach my $dir (@Dirs) {
- my $npos = $pos + $dir;
- if (grid_at($npos) == $next) {
- my %routes = &recurse( $npos );
- $ret{$_} += $routes{$_} foreach (keys %routes); # accumulate routes
- }
- }
- return (%ret);
- }
- my $part1 = 0;
- my $part2 = 0;
- foreach my $head (@trailheads) {
- my %res = &recurse( $head );
- $part1 += scalar keys %res;
- $part2 += sum values %res;
- }
- say "Part 1: $part1";
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 2 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 11 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 24 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 31 sec ago | 0.24 KB
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 40 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 49 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 59 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 1 min ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand