aboutsummaryrefslogtreecommitdiff
path: root/challenge-148
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-148')
-rw-r--r--challenge-148/colin-crain/blog.txt1
-rw-r--r--challenge-148/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-148/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-148/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-148/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-148/luca-ferrari/postgresql/ch-1.sql18
-rw-r--r--challenge-148/luca-ferrari/postgresql/ch-2.sql31
-rwxr-xr-xchallenge-148/luca-ferrari/raku/ch-1.p617
-rwxr-xr-xchallenge-148/luca-ferrari/raku/ch-2.p628
-rwxr-xr-xchallenge-148/mattneleigh/perl/ch-1.pl44
-rwxr-xr-xchallenge-148/mattneleigh/perl/ch-2.pl130
-rw-r--r--challenge-148/roger-bell-west/blog.txt1
-rw-r--r--challenge-148/steven-wilson/perl/ch-1.pl18
13 files changed, 292 insertions, 0 deletions
diff --git a/challenge-148/colin-crain/blog.txt b/challenge-148/colin-crain/blog.txt
new file mode 100644
index 0000000000..ec46c0edd7
--- /dev/null
+++ b/challenge-148/colin-crain/blog.txt
@@ -0,0 +1 @@
+https://colincrain.com/2022/01/19/numrs-without-th-lttr/
diff --git a/challenge-148/luca-ferrari/blog-1.txt b/challenge-148/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..15a54284d3
--- /dev/null
+++ b/challenge-148/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task1
diff --git a/challenge-148/luca-ferrari/blog-2.txt b/challenge-148/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..0b026a41b4
--- /dev/null
+++ b/challenge-148/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task2
diff --git a/challenge-148/luca-ferrari/blog-3.txt b/challenge-148/luca-ferrari/blog-3.txt
new file mode 100644
index 0000000000..4f5dffef8a
--- /dev/null
+++ b/challenge-148/luca-ferrari/blog-3.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task1pg
diff --git a/challenge-148/luca-ferrari/blog-4.txt b/challenge-148/luca-ferrari/blog-4.txt
new file mode 100644
index 0000000000..eda8245158
--- /dev/null
+++ b/challenge-148/luca-ferrari/blog-4.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/01/19/PerlWeeklyChallenge148.html#task2pg
diff --git a/challenge-148/luca-ferrari/postgresql/ch-1.sql b/challenge-148/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..a1782662de
--- /dev/null
+++ b/challenge-148/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,18 @@
+ SELECT v
+ FROM generate_series( 1, 10 ) v
+ WHERE
+ v IN ( 2, 4, 6 )
+
+ UNION
+
+ SELECT v
+ FROM generate_series( 11, 19 ) v
+ WHERE v IN ( 12 )
+
+ UNION
+
+ SELECT v
+ FROM generate_series( 20, 100 ) v
+ WHERE
+ v % 10 IN ( 2, 4, 6 )
+ AND ( v / 10 )::int IN ( 3, 4, 5, 6 );
diff --git a/challenge-148/luca-ferrari/postgresql/ch-2.sql b/challenge-148/luca-ferrari/postgresql/ch-2.sql
new file mode 100644
index 0000000000..5d178955a1
--- /dev/null
+++ b/challenge-148/luca-ferrari/postgresql/ch-2.sql
@@ -0,0 +1,31 @@
+WITH RECURSIVE
+triplets AS
+(
+ SELECT a::numeric, b::numeric, c::numeric
+ FROM generate_series( 1, 30 ) a
+ , generate_series( 1, 30 ) b
+ , generate_series( 1, 30 ) c
+ ORDER BY a, b, c
+)
+, cardano_sum AS
+(
+ SELECT a, b, c,
+ ( a + b * sqrt( c ) ) AS l
+ ,( a - b * sqrt( c ) ) AS r
+ FROM triplets
+)
+, cardano AS
+(
+ SELECT a, b, c, l, r
+ , CASE WHEN l < 0 THEN -1 ELSE 1 END * pow( abs( l )::numeric, 1/3::numeric )
+ + CASE WHEN r < 0 THEN -1 ELSE 1 END * pow( abs( r )::numeric, 1/3::numeric )
+ AS triplet_sum
+ FROM cardano_sum
+)
+
+SELECT *
+FROM cardano
+WHERE
+abs( 1 - triplet_sum::numeric ) <= 0.0000000001
+LIMIT 5
+;
diff --git a/challenge-148/luca-ferrari/raku/ch-1.p6 b/challenge-148/luca-ferrari/raku/ch-1.p6
new file mode 100755
index 0000000000..615f92f91f
--- /dev/null
+++ b/challenge-148/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,17 @@
+#!raku
+
+
+
+
+
+sub MAIN() {
+
+ my @eban-units = 2, 4, 6;
+ my @eban-teens = 12;
+ my @eban-tens = 3, 4, 5, 6;
+
+ $_.say if @eban-units.grep( $_ ) for 1 .. 10;
+ $_.say if @eban-teens.grep( $_ ) for 11 .. 19;
+ $_.say if @eban-tens.grep( ( $_ / 10 ).Int ) && @eban-units.grep( $_ % 10 ) for 20 .. 100;
+
+}
diff --git a/challenge-148/luca-ferrari/raku/ch-2.p6 b/challenge-148/luca-ferrari/raku/ch-2.p6
new file mode 100755
index 0000000000..453adc5583
--- /dev/null
+++ b/challenge-148/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,28 @@
+#!raku
+
+multi sub is-cardano-triplet( $a, $b, $c ) {
+
+ my $left = .sign * .abs**( 1 / 3 ) given ( $a + $b * $c.sqrt );
+ my $right = .sign * .abs**( 1 / 3 ) given ( $a - $b * $c.sqrt );
+ return 1 =~= ( $left + $right );
+}
+
+
+multi sub is-cardano-triplet( @triplet ) {
+ return is-cardano-triplet( @triplet[ 0 ], @triplet[ 1 ], @triplet[ 2 ] );
+}
+
+sub MAIN( Int $limit = 5 ) {
+ my @triplets = lazy gather {
+ for 1 .. Inf -> $a {
+ for 1 ..^ $a -> $b {
+ for 1 ..^ $b -> $c {
+ $_.take if is-cardano-triplet( $_ ) for ( $a, $b, $c ).permutations;
+
+ }
+ }
+ }
+ };
+
+ @triplets[ 0 .. $limit ].join( "\n" ).say;
+}
diff --git a/challenge-148/mattneleigh/perl/ch-1.pl b/challenge-148/mattneleigh/perl/ch-1.pl
new file mode 100755
index 0000000000..d3bea6ecc2
--- /dev/null
+++ b/challenge-148/mattneleigh/perl/ch-1.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use English;
+
+################################################################################
+# Begin main execution
+################################################################################
+
+# Tens-place and ones-place numbers that do
+# not have an 'e' in them; numbers from
+# sixty six to one hundred all have an 'e'
+# so just use a limited subset of digits
+my @tens = ( 0, 3, 4, 5, 6 );
+my @ones = ( 0, 2, 4, 6 );
+my @ebans;
+my $tens_digit;
+my $ones_digit;
+
+# Loop over the tens place digits
+foreach $tens_digit (@tens){
+ # Loop over the ones place digits
+ foreach $ones_digit (@ones){
+ if($tens_digit){
+ # Tens digit is not zero...
+ push(@ebans, $tens_digit . $ones_digit);
+ } else{
+ # Tens digit is zero...
+ push(@ebans, $ones_digit) if($ones_digit);
+ }
+ }
+}
+
+print("\nThe Eban numbers below 100 are:\n");
+print(join(", ", @ebans), "\n\n");
+
+exit(0);
+################################################################################
+# End main execution; subroutines follow
+################################################################################
+
+
+
diff --git a/challenge-148/mattneleigh/perl/ch-2.pl b/challenge-148/mattneleigh/perl/ch-2.pl
new file mode 100755
index 0000000000..36baaa45bd
--- /dev/null
+++ b/challenge-148/mattneleigh/perl/ch-2.pl
@@ -0,0 +1,130 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use English;
+
+################################################################################
+# Begin main execution
+################################################################################
+
+my $count = 5;
+my @cardanos;
+
+@cardanos = calculate_first_cardano_triplets($count);
+
+printf("\nThe first %d Cardano Triplets are:\n", scalar(@cardanos));
+foreach(@cardanos){
+ printf(" (%s)\n", join(", ", @{$_}));
+}
+print("\n");
+
+
+exit(0);
+################################################################################
+# End main execution; subroutines follow
+################################################################################
+
+
+
+################################################################################
+# Find a specified number of the first Cardano Triplets, numbers (A, B, C) that
+# meet specified parameters (see link below)
+# Takes two arguments:
+# * The number of Triplets to find; if this number is zero (0), ALL Cardano
+# Triplets whose members' sum is less than or equal to the maximum sum value
+# (see below) will be found; if there aren't that many triplets within the
+# search range, the returned list (see farther below) will be shorter than
+# specified but will contain all Triplets within the range
+# * The maximum sum of A, B, and C up to which we'll search for Triplets; if
+# this argument is omitted or is false a default of 1000 will be used
+# Returns:
+# * A list of refs to the Cardano Triplets found, e.g.:
+# (
+# [ 2, 1, 5 ],
+# [ 5, 1, 52 ],
+# [ 5, 2, 13 ],
+# ...
+# )
+# NOTES: Cardano Triplets are described here:
+# https://projecteuler.net/problem=251
+# Which particular triplets you get will depend on the value of the maximum
+# sum.
+################################################################################
+sub calculate_first_cardano_triplets{
+ my $count = int(shift());
+ my $max = shift();
+
+ my @cardanos = ();
+ my $a;
+ my $b;
+ my $c;
+
+ if(defined($max) && $max){
+ $max = int($max);
+ } else{
+ $max = 1000;
+ }
+
+ # Traditionally this is done with the
+ # variables adding up to some
+ # particular maximum value...
+ for($a=1; $a<=($max - 2); $a++){
+ for($b=1; $b<=($max - $a - 1); $b++){
+ for($c=1; $c<=($max - $a - $b); $c++){
+ my $b_sqrt_c = $b * sqrt($c);
+
+ # The calculated value should be zero
+ # if we have a Cardano Triplet, but it
+ # could be slightly off because of
+ # round-off error
+ if(
+ abs(cbrt($a + $b_sqrt_c) + cbrt($a - $b_sqrt_c) - 1)
+ <
+ 0.000000001
+ ){
+ # We have a Cardano Triplet
+ push(@cardanos, [ $a, $b, $c ]);
+
+ # Break out of all loops if there's a
+ # count defined and we've hit it
+ $max = 0
+ if($count && (scalar(@cardanos) == $count));
+ }
+
+ }
+ }
+ }
+
+ return(@cardanos);
+
+}
+
+
+
+################################################################################
+# Compute the cube root of a number
+# Takes one argument:
+# * The number whose cube root is desired
+# Returns:
+# * The cube root
+################################################################################
+sub cbrt{
+ my $x = shift();
+
+ if($x < 0){
+
+ # $x is negative; play some sign games
+ return(-((-$x) ** (1 / 3)));
+
+ } else{
+
+ # $x is positive; very straightforward
+ return($x ** (1 / 3));
+
+ }
+
+}
+
+
+
diff --git a/challenge-148/roger-bell-west/blog.txt b/challenge-148/roger-bell-west/blog.txt
new file mode 100644
index 0000000000..654d75d169
--- /dev/null
+++ b/challenge-148/roger-bell-west/blog.txt
@@ -0,0 +1 @@
+https://blog.firedrake.org/archive/2022/01/The_Weekly_Challenge_148__Eban__Cardano.html
diff --git a/challenge-148/steven-wilson/perl/ch-1.pl b/challenge-148/steven-wilson/perl/ch-1.pl
new file mode 100644
index 0000000000..28e7f90674
--- /dev/null
+++ b/challenge-148/steven-wilson/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# Week 148 Task 1
+# Eban Numbers
+# Write a script to generate all Eban Numbers <= 100.
+# An Eban number is a number that has no letter ā€˜e’ in it
+# when the number is spelled in English (American or British).
+
+use strict;
+use warnings;
+use feature qw/ say /;
+use Lingua::EN::Numbers qw/ num2en /;
+
+my $max = 100;
+
+say "Eban Numbers <= $max:";
+for ( 1 .. $max ) {
+ ( num2en($_) =~ /e/i ) ? next : say $_;
+}