diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-10-17 12:00:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-17 12:00:57 +0100 |
| commit | ef0456cc4ea5048424a53426151a4ed393fb301e (patch) | |
| tree | e8b0548bba2d0deb11a4b1edfa727b5c52f7df63 | |
| parent | 06a01638dc17bb70d0ffe5d4c8f7110072107e0c (diff) | |
| parent | f0c370d55e316544dc388f1548e947cca01ae538 (diff) | |
| download | perlweeklychallenge-club-ef0456cc4ea5048424a53426151a4ed393fb301e.tar.gz perlweeklychallenge-club-ef0456cc4ea5048424a53426151a4ed393fb301e.tar.bz2 perlweeklychallenge-club-ef0456cc4ea5048424a53426151a4ed393fb301e.zip | |
Merge pull request #5038 from LubosKolouch/master
Task 2 Challenge 134 LK Perl
| -rw-r--r-- | challenge-134/lubos-kolouch/perl/ch-2.pl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-134/lubos-kolouch/perl/ch-2.pl b/challenge-134/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..7e697a8118 --- /dev/null +++ b/challenge-134/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,50 @@ +use strict; +use warnings; +use feature qw/say/; + +sub print_table_get_items { + my ( $m, $n ) = @_; + + # TODO : proper formatting, counting of digits etc. + # TODO : split to two functions, one function printing AND returning the items is ugly + + my %items; + + print "x | "; + print "$_ " for ( 1 .. $m ); + say ""; + say "---------"; + + for my $i ( 1 .. $n ) { + print "$i | "; + + for my $j ( 1 .. $m ) { + print $i * $j . " "; + $items{ $i * $j } = 1; + } + say ""; + } + + return %items; +} + +sub print_results_get_count { + my $what = shift; + + # TODO : split to two functions, one function printing AND returning count is ugly + + print "Distinct counts: "; + for my $key ( sort { $a <=> $b } keys %$what ) { + print "$key "; + } + say ""; + + return scalar keys %$what; +} + +my %result = print_table_get_items( 3, 3 ); +my $elem_count = print_results_get_count( \%result ); + +use Test::More; +is( $elem_count, 6 ); +done_testing; |
