CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 06:14:14 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=9a7f8021bbc3f95c5ba28f4ab0d99991f55f23486b4d62ba7c8d21dcc38a942ba%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22c7oLZvq5G8nLHoO0vS51z3XA9Xvyww8A%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc37512dadf473-BLR
AoC 2024, day 23, part 2 (Perl) - Pastebin.com
SHARE
TWEET

AoC 2024, day 23, part 2 (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 List::Util qw(reduce);
- # Build undirected graph from input:
- my %graph;
- foreach my $conx (map {[m/(\w{2})-(\w{2})/]} <>) {
- push( $graph{$conx->[0]}->@*, $conx->[1] );
- push( $graph{$conx->[1]}->@*, $conx->[0] );
- }
- # Quick and dirty intersection of two lists (ASSUME: sets, so no repeats):
- sub intersect ($$) {
- my ($a, $b) = @_;
- return (grep {my $av = $_; grep {$_ eq $av} @$b} @$a);
- }
- # Find cliques (complete subgraphs) using Bron-Kerbosch
- sub recurse_bk {
- my ($r, $p, $x) = @_; # result, possibles, excludes
- my @ret;
- return ([@$r]) if (!@$p and !@$x); # P and X both empty => clique
- # Try each possible vertex:
- foreach my $v (@$p) {
- my @ruv = (@$r, $v); # Union of R with v
- my @pnNv = intersect( $p, $graph{$v} ); # Intersect of P with Neighbours of v
- my @xnNv = intersect( $x, $graph{$v} ); # Intersect of X with Neighbours of v
- push( @ret, &recurse_bk(\@ruv, \@pnNv, \@xnNv) ); # recurse and collect
- @$p = grep {$_ ne $v} @$p; # symmetric difference: P \ v
- @$x = (@$x, $v); # Union v into eXcludes
- }
- return (@ret);
- }
- my $max_clique = reduce {(@$b > @$a) ? $b : $a} &recurse_bk([], [keys %graph], []);
- say "Part 2: ", join( ',', sort @$max_clique );
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 2 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 11 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 24 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 31 sec ago | 0.24 KB
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 40 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 49 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 59 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 1 min 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