We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c2fae8 commit f81c8caCopy full SHA for f81c8ca
d06.pl
@@ -18,7 +18,8 @@
18
}
19
20
### CODE
21
-
+# change value of $part for part 2
22
+my $part = 1;
23
my $data;
24
foreach my $line (@input) {
25
my @chars = split( //, $line );
@@ -27,9 +28,10 @@
27
28
29
my $answer;
30
foreach my $hash ( @{$data} ) {
31
+ my $sortings = { 1 => sub { $hash->{$a} <=> $hash->{$b} },
32
+ 2 => sub { $hash->{$b} <=> $hash->{$a} }, };
33
- # reverse the position of $a and $b below for part 1
- my @freq = sort { $hash->{$b} <=> $hash->{$a} } keys %{$hash};
34
+ my @freq = sort { &{ $sortings->{$part} } } keys %{$hash};
35
$answer .= pop @freq;
36
37
say $answer;
0 commit comments