CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 05:25:27 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=6419cfea06dba1b525b5715263677612ddff25fc96fc93f3d78479f4a9917a6da%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%221aJHibz3dp-HugGwcI8c-HxsqZ4yoqYt%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cbefdcdd50b155-BLR
AoC 2024, day 18, part 1 (Perl) - Pastebin.com
SHARE
TWEET

AoC 2024, day 18, part 1 (Perl)
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 constant GRID_SIZE => 7;
- #use constant TIME => 12;
- use constant GRID_SIZE => 71;
- use constant TIME => 1024;
- use Math::Vector::Real;
- my ($vy,$vx) = Math::Vector::Real->canonical_base(2);
- my @Dirs = ($vy, $vx, -$vy, -$vx);
- # Make grid, adding sentinel ~s to right and bottom
- my @Grid = map { [('.') x GRID_SIZE, '~'] } (1 .. GRID_SIZE);
- push( @Grid, [('~') x GRID_SIZE] );
- sub grid_at ($) { my $p = shift; return ($Grid[$p->[1]][$p->[0]]) }
- sub print_grid { say "\t", join( '', @$_ ) foreach (@Grid); }
- # Read list of points:
- my @input = map { V(split /,/) } <>;
- # Drop up to TIME
- $Grid[$_->[1]][$_->[0]] = '#' foreach (splice( @input, 0, TIME ));
- my %visit;
- my @queue = ([V(0,0), 0]);
- my $end = V(GRID_SIZE - 1, GRID_SIZE - 1);
- while (my $state = shift @queue) {
- my ($pos, $time) = @$state;
- if ($pos == $end) {
- say "Part 1: $time";
- last;
- }
- next if ($visit{$pos}++);
- # Add legal moves to queue
- push(@queue, [$_, $time + 1]) foreach (grep {grid_at($_) eq '.'} map {$pos + $_} @Dirs);
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐Exchange Exploit⭐⭐ T
JavaScript | 1 sec ago | 0.24 KB
-
⭐⭐⭐MAKE $500 IN 15 MIN⭐⭐
Java | 2 sec ago | 0.10 KB
-
⭐ G2A Bug ⭐ (Get more on BTC swaps) ✅ NEVER S...
JavaScript | 4 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ⭐⭐ E
JavaScript | 13 sec ago | 0.24 KB
-
⭐✅ Jack's Profit Method ✅ NEVER SEEN BEF...
JavaScript | 14 sec ago | 0.24 KB
-
⭐⭐⭐Make $15OO in 2O minutesV E⭐⭐
Java | 14 sec ago | 0.10 KB
-
⭐✅ Online Marketplace Exploit ✅ NEVER SEEN BE...
JavaScript | 23 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ O
JavaScript | 24 sec 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