diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2024-03-16 21:07:16 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2024-03-16 21:07:16 +0100 |
| commit | 630135a3c453711b03bfe44976daf1a53cf8a57f (patch) | |
| tree | 131805b248ccb32ea3b0279ebaa2e927fc49b84a | |
| parent | c332d451e86cc8bd09c8e9746359a3085fcc3a0e (diff) | |
| download | perlweeklychallenge-club-630135a3c453711b03bfe44976daf1a53cf8a57f.tar.gz perlweeklychallenge-club-630135a3c453711b03bfe44976daf1a53cf8a57f.tar.bz2 perlweeklychallenge-club-630135a3c453711b03bfe44976daf1a53cf8a57f.zip | |
feat(challenge-260/lubos-kolouch/perl,python/): Code and style cleanups for challenge 260
| -rw-r--r-- | challenge-260/lubos-kolouch/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-260/lubos-kolouch/perl/ch-2.pl | 3 |
2 files changed, 12 insertions, 5 deletions
diff --git a/challenge-260/lubos-kolouch/perl/ch-1.pl b/challenge-260/lubos-kolouch/perl/ch-1.pl index 791a3dc77c..0d8d759c79 100644 --- a/challenge-260/lubos-kolouch/perl/ch-1.pl +++ b/challenge-260/lubos-kolouch/perl/ch-1.pl @@ -1,5 +1,7 @@ +package ch1; use strict; use warnings; + use Data::Dumper; sub unique_occurrences { @@ -11,22 +13,24 @@ sub unique_occurrences { # Check if the number of occurrences is unique my %occurrences_count; - foreach my $value (values %count) { + foreach my $value ( values %count ) { $occurrences_count{$value}++; } # Return 1 if all occurrences are unique, 0 otherwise - return (scalar keys %occurrences_count == scalar values %count) ? 1 : 0; + return ( scalar keys %occurrences_count == scalar values %count ) ? 1 : 0; } # Example 1 -my @ints1 = (1,2,2,1,1,3); +my @ints1 = ( 1, 2, 2, 1, 1, 3 ); print "Example 1: " . unique_occurrences(@ints1) . "\n"; # Example 2 -my @ints2 = (1,2,3); +my @ints2 = ( 1, 2, 3 ); print "Example 2: " . unique_occurrences(@ints2) . "\n"; # Example 3 -my @ints3 = (-2,0,1,-2,1,1,0,1,-2,9); +my @ints3 = ( -2, 0, 1, -2, 1, 1, 0, 1, -2, 9 ); print "Example 3: " . unique_occurrences(@ints3) . "\n"; + +1; diff --git a/challenge-260/lubos-kolouch/perl/ch-2.pl b/challenge-260/lubos-kolouch/perl/ch-2.pl index a33f112bb3..fc13687a33 100644 --- a/challenge-260/lubos-kolouch/perl/ch-2.pl +++ b/challenge-260/lubos-kolouch/perl/ch-2.pl @@ -1,3 +1,4 @@ +package ch2; use strict; use warnings; use List::Util qw(reduce); @@ -34,3 +35,5 @@ sub dictionary_rank { print dictionary_rank('CAT'), "\\n"; print dictionary_rank('GOOGLE'), "\\n"; print dictionary_rank('SECRET'), "\\n"; + +1; |
