aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-134/lubos-kolouch/perl/ch-2.pl50
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;