aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-173/lubos-kolouch/perl/ch-1.pl22
-rw-r--r--challenge-173/lubos-kolouch/perl/ch-2.pl34
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-173/lubos-kolouch/perl/ch-1.pl b/challenge-173/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..ee8763e6cd
--- /dev/null
+++ b/challenge-173/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+sub is_esthetic_number {
+ my $what = shift;
+
+ # where is enumerate when you need it
+
+ my @arr = split //, $what;
+ for my $elem ( 0 .. scalar @arr - 2 ) {
+ return 0 unless abs( $arr[$elem] - $arr[ $elem + 1 ] ) == 1;
+ }
+
+ return 1;
+}
+
+use Test::More;
+
+is( is_esthetic_number(5456), 1, 'Test 5456' );
+is( is_esthetic_number(120), 0, 'Test 120' );
+
+done_testing;
diff --git a/challenge-173/lubos-kolouch/perl/ch-2.pl b/challenge-173/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..43359e0c4b
--- /dev/null
+++ b/challenge-173/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use Math::BigInt;
+
+sub generate_sylvestver_numbers {
+ my $limit = shift;
+
+ my @items = ( Math::BigInt->new(2) );
+ my $product = $items[0];
+
+ while ( scalar @items < $limit ) {
+ push @items, Math::BigInt->new( $product + 1 );
+ $product *= $items[-1];
+ }
+
+ return \@items;
+}
+
+use Test::More;
+
+is_deeply(
+ generate_sylvestver_numbers(10),
+ [
+ 2, 3, 7, 43, 1807, 3263443,
+ Math::BigInt->new('10650056950807'),
+ Math::BigInt->new('113423713055421844361000443'),
+ Math::BigInt->new('12864938683278671740537145998360961546653259485195807'),
+ Math::BigInt->new(
+'165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443'
+ )
+ ]
+);
+
+done_testing;