CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 08:48:08 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=df02197d7cc2bf996949115c22b23dd27488cacf9839bda0a425473f4c21c63ca%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%223CaBzmBL9AVW3JbgjWQ8WhcZaK8H2eVG%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d55625be89af3d-BLR
AoC 2024 day 13 (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 constant X => 0;
- use constant Y => 1;
- use constant A_COST => 3;
- use constant B_COST => 1;
- sub solve_cost {
- my ($a, $b, $target) = @_;
- my $a_numer = $target->[X] * $b->[Y] - $target->[Y] * $b->[X];
- my $b_numer = $target->[Y] * $a->[X] - $target->[X] * $a->[Y];
- my $denom = $a->[X] * $b->[Y] - $a->[Y] * $b->[X];
- # Test for integer solution
- if ($a_numer % $denom == 0 and $b_numer % $denom == 0) {
- return (A_COST * $a_numer / $denom + B_COST * $b_numer / $denom);
- }
- return (0);
- }
- my $part1 = 0;
- my $part2 = 0;
- $/ = ''; # Paragraph mode, 1 machine per paragraph
- foreach my $machine (map {[split /\n/]} <>) {
- my @a_move = ($machine->[0] =~ m#(\d+)#g);
- my @b_move = ($machine->[1] =~ m#(\d+)#g);
- my @target = ($machine->[2] =~ m#(\d+)#g);
- my @target2 = map { $_ + 10_000_000_000_000 } @target;
- $part1 += &solve_cost( \@a_move, \@b_move, \@target );
- $part2 += &solve_cost( \@a_move, \@b_move, \@target2 );
- }
- say "Part 1: $part1";
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐MAKE $9OO INSTANTLY D G⭐⭐
Java | 6 sec ago | 0.10 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ Z
JavaScript | 9 sec ago | 0.25 KB
-
⭐⭐⭐MAKE $9OO INSTANTLY D M⭐⭐
Java | 11 sec ago | 0.10 KB
-
⭐⭐⭐Make $1500 in 20 minutes⭐⭐
Java | 17 sec ago | 0.10 KB
-
📌 Swapzone +37% glitch ⭐ P
JavaScript | 18 sec ago | 0.25 KB
-
⭐⭐⭐Exchange Exploit T 3⭐⭐
Java | 22 sec ago | 0.10 KB
-
✅⭐ Make huge profits on trading ⭐⭐ R
JavaScript | 28 sec ago | 0.25 KB
-
⭐⭐⭐Instant Profit Method⭐⭐
Java | 28 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