CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 10:16:07 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=dcd5ee29923868f7f0e2b6605a13aa6091f91b4fa7b338d6a17f5c24b61a680fa%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22SVTBsJeN3Uaf2PW_7KnMFM0V8YK_PMjw%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d5d7057a721eef-BLR
AoC 2024 day 12 (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 Math::Vector::Real;
- my ($vy,$vx) = Math::Vector::Real->canonical_base(2);
- my @Dirs = ($vy, $vx, -$vy, -$vx);
- # 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]]) }
- sub print_grid { say "\t", join( '', @$_ ) foreach (@Grid); }
- my $part1 = 0;
- my $part2 = 0;
- my %visited;
- foreach my $y (0 .. $#Grid - 1) {
- foreach my $x (0 .. $Grid[0]->$#* - 1) {
- my $start = V($y,$x);
- next if ($visited{$start});
- my $plant = grid_at($start);
- my $area = 0;
- my $inner = 0;
- my @queue = ($start);
- my %neigh;
- while (my $pos = shift @queue) {
- next if ($visited{$pos});
- my @field;
- foreach my $d (@Dirs) {
- my $p = $pos + $d;
- if (grid_at($p) eq $plant) {
- push( @field, $p);
- } else {
- push( $neigh{$p}->@*, $d );
- }
- }
- $inner += scalar @field;
- $area++;
- $visited{$pos}++;
- push( @queue, @field);
- }
- my $perm = 4 * $area - $inner;
- $part1 += $area * $perm;
- my %corners;
- foreach my $n (keys %neigh) {
- my $pos = V($n =~ m#([-0-9]+)#g);
- foreach my $d ($neigh{$n}->@*) {
- my $left = V( -$d->[1], $d->[0] );
- my $corn = $pos;
- $corn += $left while (exists $neigh{$corn} and grid_at($corn - $d) eq $plant);
- $corn -= $left;
- if (!exists $corners{$corn,$d}) {
- $corners{$corn,$d}++;
- }
- }
- }
- my $sides = scalar keys %corners;
- $part2 += $area * $sides;
- }
- }
- say "Part 1: $part1";
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐MAKE $9OO INSTANTLY D M⭐⭐
Java | 1 sec ago | 0.10 KB
-
⭐⭐⭐Exploit 500$ in 15 Minutes⭐⭐
Java | 5 sec ago | 0.10 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 6 sec ago | 0.25 KB
-
⭐⭐⭐MAKE $9OO INSTANTLY D G⭐⭐
Java | 7 sec ago | 0.10 KB
-
⭐⭐⭐MAKE $900 INSTANTLY⭐⭐
Java | 11 sec ago | 0.10 KB
-
⭐⭐⭐Exploit 500$ in 15 Minutes⭐⭐
Java | 13 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ F
JavaScript | 16 sec ago | 0.25 KB
-
⭐⭐⭐Profit Method⭐⭐
Java | 17 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