Skip to content

Commit f81c8ca

Browse files
committed
added simpler switch between parts 1 and 2
1 parent 5c2fae8 commit f81c8ca

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

d06.pl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
}
1919

2020
### CODE
21-
21+
# change value of $part for part 2
22+
my $part = 1;
2223
my $data;
2324
foreach my $line (@input) {
2425
my @chars = split( //, $line );
@@ -27,9 +28,10 @@
2728

2829
my $answer;
2930
foreach my $hash ( @{$data} ) {
31+
my $sortings = { 1 => sub { $hash->{$a} <=> $hash->{$b} },
32+
2 => sub { $hash->{$b} <=> $hash->{$a} }, };
3033

31-
# reverse the position of $a and $b below for part 1
32-
my @freq = sort { $hash->{$b} <=> $hash->{$a} } keys %{$hash};
34+
my @freq = sort { &{ $sortings->{$part} } } keys %{$hash};
3335
$answer .= pop @freq;
3436
}
3537
say $answer;

0 commit comments

Comments
 (0)