aboutsummaryrefslogtreecommitdiff
path: root/challenge-153
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2022-02-27 18:32:33 -0500
committerAdam Russell <ac.russell@live.com>2022-02-27 18:32:33 -0500
commitba5ba7520792ff44cdff46d91da7cf5d8530e4db (patch)
treeccdfc3d9d55580f7ebfe1508d4fba48c9eb1d5d3 /challenge-153
parentc4e3b2a7e8db74784a52e62402ef90d0e7e9f0a8 (diff)
downloadperlweeklychallenge-club-ba5ba7520792ff44cdff46d91da7cf5d8530e4db.tar.gz
perlweeklychallenge-club-ba5ba7520792ff44cdff46d91da7cf5d8530e4db.tar.bz2
perlweeklychallenge-club-ba5ba7520792ff44cdff46d91da7cf5d8530e4db.zip
initial commit
Diffstat (limited to 'challenge-153')
-rw-r--r--challenge-153/adam-russell/blog.txt1
-rw-r--r--challenge-153/adam-russell/perl/ch-1.pl25
-rw-r--r--challenge-153/adam-russell/perl/ch-2.pl22
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-153/adam-russell/blog.txt b/challenge-153/adam-russell/blog.txt
new file mode 100644
index 0000000000..3e0711da3f
--- /dev/null
+++ b/challenge-153/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2022/02/27
diff --git a/challenge-153/adam-russell/perl/ch-1.pl b/challenge-153/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..3e5b1e9a27
--- /dev/null
+++ b/challenge-153/adam-russell/perl/ch-1.pl
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+##
+# Write a script to determine the first ten members of the Left Factorials sequence.
+##
+use POSIX;
+use constant UPPER_BOUND => INT_MAX/1000;
+
+sub left_factorials_sieve{
+ my($n) = @_;
+ my @sieve = (0 .. UPPER_BOUND);
+ my @left_factorials;
+ my $x = 2;
+ {
+ my @sieve_indices = grep { $_ <= $x || $_ % $x == 0 } 0 .. @sieve - 1;
+ @sieve = map{ $sieve[$_] } @sieve_indices;
+ $x++;
+ redo if $x <= $n;
+ }
+ return @sieve[1 .. @sieve - 1];
+}
+
+MAIN:{
+ print join(", ", left_factorials_sieve(10)) . "\n";
+} \ No newline at end of file
diff --git a/challenge-153/adam-russell/perl/ch-2.pl b/challenge-153/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..7ab9492746
--- /dev/null
+++ b/challenge-153/adam-russell/perl/ch-2.pl
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+##
+# Write a script to figure out if the given integer is a factorion.
+##
+use boolean;
+
+sub factorial{
+ my($n) = @_;
+ return 1 if $n == 1;
+ $n * factorial($n - 1);
+}
+
+sub is_factorion{
+ my($n) = @_;
+ return boolean($n == unpack("%32I*", pack("I*", map {factorial($_)} split(//, $n))));
+}
+
+MAIN:{
+ print is_factorion(145) . "\n";
+ print is_factorion(123) . "\n";
+} \ No newline at end of file