CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 07:25:12 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=612b928a0822cbc1c1402b423b6e6279b3acb01a6212f3791dd7e3a1bda16f59a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22_uQsJogie-ZPgwvI4jZT9_CUrXQ0KXq-%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc9f48fdcec1a6-BLR
AoC 2024, day 6 (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(firstidx);
- use Math::Vector::Real;
- my ($y,$x) = Math::Vector::Real->canonical_base(2);
- my @Dirs = ($y, -$x, -$y, $x);
- # Read in grid, adding sentinel ~s to right and bottom
- my @Grid = map { chomp; [split(//), '~'] } <>;
- push( @Grid, [('~') x $Grid[0]->@*] );
- sub grid_at ($) { my $p = shift; return ($Grid[$p->[0]][$p->[1]]) }
- my $start_pos;
- my $face = 2;
- foreach my $y (0 .. $#Grid) {
- my $x = firstidx { $_ eq '^' } $Grid[$y]->@*;
- if ($x != -1) {
- $start_pos = V($y,$x);
- last;
- }
- }
- sub test_block {
- my ($block, $pos, $face, $path) = @_;
- my %visit;
- $Grid[$block->[0]][$block->[1]] = '#';
- while (&grid_at( $pos ) ne '~') {
- my $ahead = $pos + $Dirs[$face];
- if (&grid_at( $ahead ) eq '#') {
- $face = ($face + 1) % 4;
- } else {
- last if ($visit{$ahead}{$face} or ($path->{$ahead} and $path->{$ahead}{$face}));
- $pos = $ahead;
- }
- $visit{$pos}{$face}++;
- }
- $Grid[$block->[0]][$block->[1]] = '.';
- return (&grid_at( $pos ) ne '~');
- }
- my %path;
- my %block;
- my $pos = $start_pos;
- my $count = 0;
- $path{$pos}{$face}++;
- while (&grid_at( $pos ) ne '~') {
- my $ahead = $pos + $Dirs[$face];
- print ::stderr "$count\r" if (++$count % 500 == 0);
- if (&grid_at( $ahead ) eq '#') {
- $face = ($face + 1) % 4;
- } else {
- if (&grid_at( $ahead ) eq '.' and !$block{$ahead} and !$path{$ahead}) {
- $block{$ahead}++ if (&test_block( $ahead, $pos, $face, \%path ));
- }
- $pos = $ahead;
- }
- $path{$pos}{$face}++;
- }
- say "Part 1: ", (scalar keys %path) - 1;
- say "Part 2: ", (scalar keys %block);
Advertisement
Add Comment
Please, Sign In to add comment
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 1 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ⭐⭐ 8
JavaScript | 4 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ X
JavaScript | 6 sec ago | 0.24 KB
-
⭐⭐⭐ G2A Payment Exploit ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 13 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ P
JavaScript | 17 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ K
JavaScript | 17 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 23 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ N
JavaScript | 28 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