CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 23:34:47 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=0360d4f832e13d4046c38bf5e7f8c49effbaa2f1f450a64b01c7c50c98f4e8eba%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22uqrHRcHN6QTpNcC3EusSjE3aT-MOmJcx%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d22b917ea1c7d3-BLR
AoC day 16, part 1 (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 Array::Heap::PriorityQueue::Numeric;
- use Math::Vector::Real;
- my ($vy,$vx) = Math::Vector::Real->canonical_base(2);
- my @Dirs = ($vx, -$vy, -$vx, $vy);
- my @Grid = map { chomp; [split(//)] } <>;
- sub grid_at ($) { my $p = shift; return ($Grid[$p->[0]][$p->[1]]) }
- sub print_grid { say "\t", join( '', @$_ ) foreach (@Grid); }
- my ($start, $end);
- foreach my $y (0 .. $#Grid) {
- foreach my $x (0 .. $Grid[0]->$#*) {
- $start = V($x,$y) if ($Grid[$x][$y] eq 'S');
- $end = V($x,$y) if ($Grid[$x][$y] eq 'E');
- }
- }
- my %visit;
- my $queue = new Array::Heap::PriorityQueue::Numeric;
- $queue->add( [$start, 0, 0, 0], 0 );
- QUEUE:
- while (my $state = $queue->get) {
- my ($pos, $face, $turn, $moves) = @$state;
- if (grid_at($pos) eq 'E') {
- say "Part 1: $moves";
- last QUEUE;
- }
- next QUEUE if (exists $visit{$pos,$face});
- $visit{$pos,$face} = $moves;
- # Try straight if valid
- if (grid_at( $pos + $Dirs[$face] ) ne '#') {
- $queue->add( [$pos + $Dirs[$face], $face, 0, $moves + 1], $moves + 1);
- }
- # Try turns (if we didn't just turn the other way)
- foreach my $t (grep {$turn != -$_} (1,-1)) {
- $queue->add( [$pos, ($face+$t) % 4, $t, $moves + 1000], $moves + 1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 6 sec ago | 0.25 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ W
JavaScript | 15 sec ago | 0.25 KB
-
📝 EASY MONEY GUIDE ✅ Working
JavaScript | 15 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ W
JavaScript | 23 sec ago | 0.25 KB
-
📌 ChangeNOW Exploit
JavaScript | 25 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working ⭐⭐ X
JavaScript | 33 sec ago | 0.25 KB
-
📌 Instant BTC Profit Method ✅ Working
JavaScript | 37 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ R
JavaScript | 43 sec ago | 0.25 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