pretty
This commit is contained in:
parent
482ae97ee6
commit
046cb8f538
1
2023/.gitignore
vendored
Normal file
1
2023/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.bak
|
@ -37,7 +37,8 @@ sub handify($str) {
|
|||||||
A => 14
|
A => 14
|
||||||
);
|
);
|
||||||
|
|
||||||
my @cards = map { chr( ord('a') + $_ - 2 )} map { $map{$_} // $_ } split '', $str;
|
my @cards =
|
||||||
|
map { chr( ord('a') + $_ - 2 ) } map { $map{$_} // $_ } split '', $str;
|
||||||
|
|
||||||
return \@cards;
|
return \@cards;
|
||||||
}
|
}
|
||||||
@ -46,7 +47,8 @@ sub parse_input($input) {
|
|||||||
my @lines = split "\n", $input;
|
my @lines = split "\n", $input;
|
||||||
my @hand_score = pairmap {
|
my @hand_score = pairmap {
|
||||||
[ handify($a), $b ]
|
[ handify($a), $b ]
|
||||||
} map { split " " } @lines;
|
}
|
||||||
|
map { split " " } @lines;
|
||||||
return @hand_score;
|
return @hand_score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ sub score(@hand) {
|
|||||||
sub solution_1 ($input) {
|
sub solution_1 ($input) {
|
||||||
my @hand_score = sort_by { score( $_->[0]->@* ) } parse_input($input);
|
my @hand_score = sort_by { score( $_->[0]->@* ) } parse_input($input);
|
||||||
my $rank = 0;
|
my $rank = 0;
|
||||||
|
|
||||||
# use DDP; p @hand_score;
|
# use DDP; p @hand_score;
|
||||||
return sum map { ++$rank * $_->[1] } @hand_score;
|
return sum map { ++$rank * $_->[1] } @hand_score;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ sub handify($str) {
|
|||||||
A => 14
|
A => 14
|
||||||
);
|
);
|
||||||
|
|
||||||
my @cards = map { chr( ord('a') + $_ - 2 )} map { $map{$_} // $_ } split '', $str;
|
my @cards =
|
||||||
|
map { chr( ord('a') + $_ - 2 ) } map { $map{$_} // $_ } split '', $str;
|
||||||
|
|
||||||
return \@cards;
|
return \@cards;
|
||||||
}
|
}
|
||||||
@ -51,7 +52,8 @@ sub parse_input($input) {
|
|||||||
my @lines = split "\n", $input;
|
my @lines = split "\n", $input;
|
||||||
my @hand_score = pairmap {
|
my @hand_score = pairmap {
|
||||||
[ handify($a), $b ]
|
[ handify($a), $b ]
|
||||||
} map { split " " } @lines;
|
}
|
||||||
|
map { split " " } @lines;
|
||||||
return @hand_score;
|
return @hand_score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ is Part1::rank_hand( '23432') => 3;
|
|||||||
is Part1::rank_hand('A23A4') => 2;
|
is Part1::rank_hand('A23A4') => 2;
|
||||||
is Part1::rank_hand('23456') => 1;
|
is Part1::rank_hand('23456') => 1;
|
||||||
|
|
||||||
is [ Part1::parse_input( '2345A 123') ] => [
|
is [ Part1::parse_input('2345A 123') ] => [ [ [qw/ a b c d m /], 123 ] ];
|
||||||
[ [qw/ a b c d m /], 123 ]
|
|
||||||
];
|
|
||||||
|
|
||||||
is Part1::solution_1($example) => 6440;
|
is Part1::solution_1($example) => 6440;
|
||||||
is Part1::solution_1($input) => 'TODO';
|
is Part1::solution_1($input) => 'TODO';
|
||||||
|
Loading…
Reference in New Issue
Block a user