CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 18:31: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=c572da0dc002408dbc2b810caa70fe6bdca3c9109e3416a2a91cb2544e972d91a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22zpxsxARK3S71gpfm31eB-xaIy8rmC4v4%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d06f2deafdc537-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
-
✅⭐ Make huge profits on trading ⭐⭐ W
JavaScript | 6 sec ago | 0.24 KB
-
⭐✅ Jack's Profit Method ✅ NEVER SEEN BEF...
JavaScript | 8 sec ago | 0.24 KB
-
⭐⭐⭐Make $15OO in 2O minutesV E⭐⭐
Java | 11 sec ago | 0.10 KB
-
⭐⭐Exchange Exploit⭐⭐ 9
JavaScript | 12 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 16 sec ago | 0.24 KB
-
⭐✅ Online Marketplace Exploit ✅ NEVER SEEN BE...
JavaScript | 17 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ⭐⭐ 6
JavaScript | 22 sec ago | 0.24 KB
-
⭐⭐⭐Make $1500 in 20 minutes⭐⭐
Java | 22 sec ago | 0.10 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