aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-01-20 07:13:35 +0000
committerdrbaggy <js5@sanger.ac.uk>2022-01-20 07:13:35 +0000
commit07a74309ecd5a7d8bb1da5f3bbe6773568504d37 (patch)
treee8122afff80917aa324e1536a7a8e25993056e35
parent9f29efbb117c84cb8d7276a7e99ac368a9b798f2 (diff)
parentf3478e19ce01285dda27ee5d01db2006b49e4965 (diff)
downloadperlweeklychallenge-club-07a74309ecd5a7d8bb1da5f3bbe6773568504d37.tar.gz
perlweeklychallenge-club-07a74309ecd5a7d8bb1da5f3bbe6773568504d37.tar.bz2
perlweeklychallenge-club-07a74309ecd5a7d8bb1da5f3bbe6773568504d37.zip
Merge remote-tracking branch 'upstream/master'
-rw-r--r--challenge-147/conor-hoekstra/bqn/ch-1.bqn5
-rw-r--r--challenge-147/conor-hoekstra/bqn/ch-2.bqn13
-rwxr-xr-xchallenge-148/2colours/raku/ch-1.raku9
-rwxr-xr-xchallenge-148/2colours/raku/ch-2.raku17
-rw-r--r--challenge-148/dave-jacoby/blog.txt1
-rw-r--r--challenge-148/dave-jacoby/perl/ch-1.pl19
-rw-r--r--challenge-148/dave-jacoby/perl/ch-2.pl48
-rwxr-xr-xchallenge-148/e-choroba/perl/ch-1.pl26
-rwxr-xr-xchallenge-148/e-choroba/perl/ch-2.pl45
-rwxr-xr-xchallenge-148/eric-cheung/excel-vba/Challenge_148.xlsmbin0 -> 26830 bytes
-rwxr-xr-xchallenge-148/eric-cheung/excel-vba/ch-1.bas131
-rwxr-xr-xchallenge-148/eric-cheung/python/ch-2.py44
-rw-r--r--challenge-148/mark-anderson/raku/ch-1.raku5
-rwxr-xr-xchallenge-148/perlboy1967/perl/ch-1.pl59
-rwxr-xr-xchallenge-148/perlboy1967/perl/ch-2.pl51
-rw-r--r--challenge-148/polettix/blog.txt1
-rw-r--r--challenge-148/polettix/blog1.txt1
-rwxr-xr-xchallenge-148/polettix/perl/ch-1-alt.pl7
-rwxr-xr-xchallenge-148/polettix/perl/ch-1.pl10
-rwxr-xr-xchallenge-148/polettix/perl/ch-2.pl18
-rw-r--r--challenge-148/polettix/perl/cpanfile1
-rw-r--r--challenge-148/polettix/perl/cpanfile.snapshot13
-rwxr-xr-xchallenge-148/polettix/raku/ch-1.raku5
-rwxr-xr-xchallenge-148/polettix/raku/ch-2.raku15
-rw-r--r--challenge-148/robert-dicicco/perl/ch-1.pl20
-rw-r--r--challenge-148/robert-dicicco/perl/ch-2.pl45
-rw-r--r--challenge-148/robert-dicicco/ruby/ch-1.rb19
-rwxr-xr-xchallenge-148/roger-bell-west/javascript/ch-1.js50
-rwxr-xr-xchallenge-148/roger-bell-west/javascript/ch-2.js69
-rw-r--r--challenge-148/roger-bell-west/kotlin/ch-1.kt21
-rw-r--r--challenge-148/roger-bell-west/kotlin/ch-2.kt40
-rwxr-xr-xchallenge-148/roger-bell-west/lua/ch-1.lua48
-rwxr-xr-xchallenge-148/roger-bell-west/lua/ch-2.lua73
-rwxr-xr-xchallenge-148/roger-bell-west/perl/ch-1.pl22
-rwxr-xr-xchallenge-148/roger-bell-west/perl/ch-2.pl42
-rw-r--r--challenge-148/roger-bell-west/postscript/ch-1.ps45
-rw-r--r--challenge-148/roger-bell-west/postscript/ch-2.ps34
-rwxr-xr-xchallenge-148/roger-bell-west/python/ch-1.py21
-rwxr-xr-xchallenge-148/roger-bell-west/python/ch-2.py38
-rwxr-xr-xchallenge-148/roger-bell-west/raku/ch-1.p620
-rwxr-xr-xchallenge-148/roger-bell-west/raku/ch-2.p640
-rwxr-xr-xchallenge-148/roger-bell-west/ruby/ch-1.rb23
-rwxr-xr-xchallenge-148/roger-bell-west/ruby/ch-2.rb48
-rwxr-xr-xchallenge-148/roger-bell-west/rust/ch-1.rs22
-rwxr-xr-xchallenge-148/roger-bell-west/rust/ch-2.rs48
-rw-r--r--challenge-148/ulrich-rieke/cpp/ch-1.cpp31
-rw-r--r--challenge-148/ulrich-rieke/perl/ch-1.pl29
-rw-r--r--challenge-148/ulrich-rieke/raku/ch-1.raku26
-rw-r--r--challenge-148/ulrich-rieke/raku/ch-2.raku45
-rw-r--r--challenge-148/walt-mankowski/README.md63
-rw-r--r--challenge-148/walt-mankowski/blog.txt1
-rw-r--r--challenge-148/walt-mankowski/perl/.perl-version1
-rw-r--r--challenge-148/walt-mankowski/perl/ch-1.pl10
-rw-r--r--challenge-148/walt-mankowski/perl/ch-2.pl21
-rw-r--r--challenge-148/wlmb/blog.txt1
-rwxr-xr-xchallenge-148/wlmb/perl/ch-1.pl14
-rwxr-xr-xchallenge-148/wlmb/perl/ch-2.pl24
-rw-r--r--stats/pwc-current.json266
-rw-r--r--stats/pwc-language-breakdown-summary.json58
-rw-r--r--stats/pwc-language-breakdown.json1038
-rw-r--r--stats/pwc-leaders.json826
-rw-r--r--stats/pwc-summary-1-30.json90
-rw-r--r--stats/pwc-summary-121-150.json106
-rw-r--r--stats/pwc-summary-151-180.json48
-rw-r--r--stats/pwc-summary-181-210.json60
-rw-r--r--stats/pwc-summary-211-240.json32
-rw-r--r--stats/pwc-summary-241-270.json66
-rw-r--r--stats/pwc-summary-31-60.json106
-rw-r--r--stats/pwc-summary-61-90.json60
-rw-r--r--stats/pwc-summary-91-120.json42
-rw-r--r--stats/pwc-summary.json556
71 files changed, 3319 insertions, 1633 deletions
diff --git a/challenge-147/conor-hoekstra/bqn/ch-1.bqn b/challenge-147/conor-hoekstra/bqn/ch-1.bqn
new file mode 100644
index 0000000000..31f11f3496
--- /dev/null
+++ b/challenge-147/conor-hoekstra/bqn/ch-1.bqn
@@ -0,0 +1,5 @@
+# Eban Numbers
+⥊0‿30‿40‿50‿60 +⌜ 2‿4‿6
+
+# Output
+⟨ 2 4 6 32 34 36 42 44 46 52 54 56 62 64 66 ⟩
diff --git a/challenge-147/conor-hoekstra/bqn/ch-2.bqn b/challenge-147/conor-hoekstra/bqn/ch-2.bqn
new file mode 100644
index 0000000000..ba8c41a414
--- /dev/null
+++ b/challenge-147/conor-hoekstra/bqn/ch-2.bqn
@@ -0,0 +1,13 @@
+CubeRoot ← {
+ 𝕩<0 ? -3√-𝕩 ; 3√𝕩
+}
+
+IsCardano ← {
+ a‿b‿c ← 𝕩
+ 1=a(++○CubeRoot-)b×√c
+}
+
+IsCardano¨⊸/⥊1+↕45‿45‿45
+
+# Output
+⟨ ⟨ 2 1 5 ⟩ ⟨ 8 3 21 ⟩ ⟨ 11 4 29 ⟩ ⟨ 14 5 37 ⟩ ⟨ 44 45 13 ⟩ ⟩
diff --git a/challenge-148/2colours/raku/ch-1.raku b/challenge-148/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..a88dd8841e
--- /dev/null
+++ b/challenge-148/2colours/raku/ch-1.raku
@@ -0,0 +1,9 @@
+#!/usr/bin/env raku
+
+constant @small-contains-e = 1, 3, 5, 7, 8, 9, 10, 11, 12;
+constant @xties-contains-e = 2, 7, 8, 9;
+multi is-eban($num where 0 < * <= 12) { $num !(elem) @small-contains-e }
+multi is-eban($num where 13 <= * < 20) { False }
+multi is-eban($num where 20 <= * < 100) { $num div 10 !(elem) @xties-contains-e and $num%%10 || is-eban($num%10) }
+
+say (1..^100).grep(&is-eban);
diff --git a/challenge-148/2colours/raku/ch-2.raku b/challenge-148/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..8fb3b5e51d
--- /dev/null
+++ b/challenge-148/2colours/raku/ch-2.raku
@@ -0,0 +1,17 @@
+#!/usr/bin/env raku
+
+sub cardano-sum($a, $b, $c) {
+ ($a+$b*$c**0.5 andthen .sign*.abs**(1/3))+($a-$b*$c**0.5 andthen .sign*.abs**(1/3))
+}
+
+
+my $cardano-triplets = gather {
+ for 1..Inf -> $biggest {
+ for 1..$biggest -> $mid {
+ for 1..$mid -> $smallest {
+ .take if cardano-sum(|$_) =~= 1 for permutations(($biggest, $mid, $smallest));
+ }
+ }
+ }
+}
+.join(" ").say for $cardano-triplets.head(5);
diff --git a/challenge-148/dave-jacoby/blog.txt b/challenge-148/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..73299f8ca6
--- /dev/null
+++ b/challenge-148/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2022/01/19/its-triplets-weekly-challenge-148.html
diff --git a/challenge-148/dave-jacoby/perl/ch-1.pl b/challenge-148/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..bf62ab2981
--- /dev/null
+++ b/challenge-148/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental };
+
+use Lingua::EN::Numbers qw( num2en );
+
+# You COULD try to make up a way to do this, but this wheel has been
+# invented already and is sufficiently round.
+
+my @numbers;
+for my $i ( 0 .. 100 ) {
+ my $e = num2en $i;
+ next if $e =~ /e/mx;
+ push @numbers, $i;
+}
+say join ', ', @numbers;
diff --git a/challenge-148/dave-jacoby/perl/ch-2.pl b/challenge-148/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..330ce7e8d0
--- /dev/null
+++ b/challenge-148/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say postderef signatures state };
+no warnings qw{ experimental };
+
+use Algorithm::Permute;
+
+my @triplets;
+
+my $i = 0;
+while ( scalar @triplets < 5 ) {
+ for my $j ( 1 .. $i ) {
+ for my $k ( 1 .. $j ) {
+ my $p = Algorithm::Permute->new( [ $i, $j, $k ] );
+ while ( my @res = $p->next ) {
+ my $t = test_cardano(@res);
+ if ( $t == 1 ) {
+ push @triplets, \@res;
+ }
+ }
+ }
+ }
+ $i++;
+ last if $i > 1000;
+}
+
+for my $ct (@triplets) {
+ my ( $a, $b, $c ) = $ct->@*;
+ print <<"END";
+ A: $a\tB: $b\tC: $c
+END
+}
+
+sub test_cardano ( $a, $b, $c ) {
+ my $sqrtc = sqrt $c;
+
+ # not necessary for the first five
+ if ( $a > $b * $sqrtc ) {
+ return cuberoot( $a + $b * $sqrtc ) + cuberoot( $a - $b * $sqrtc );
+ }
+
+ return cuberoot( $a + $b * $sqrtc ) +
+ -1 * cuberoot( abs( $a - $b * $sqrtc ) );
+}
+
+sub cuberoot ($n ) { return $n**( 1 / 3 ) }
diff --git a/challenge-148/e-choroba/perl/ch-1.pl b/challenge-148/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..1fcada37b9
--- /dev/null
+++ b/challenge-148/e-choroba/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+my $is_eban;
+if (eval { require Lingua::EN::Numbers }) {
+ $is_eban = sub { Lingua::EN::Numbers::num2en($_[0]) !~ /e/ };
+
+} elsif (eval { require Number::Spell }) {
+ $is_eban = sub { Number::Spell::spell_number($_[0]) !~ /e/ };
+
+} else {
+ $is_eban = sub {
+ my ($n) = @_;
+ return if $n =~ /[12789].$/
+ || $n =~ /[135789]$/
+ || $n == 0
+ || $n =~ /[^0]..$/;
+ return $is_eban->(substr $n, 0, -3)
+ if 3 < length $n; # thousand .. nonillion
+ return 1
+ };
+}
+
+say join ', ', grep $is_eban->($_), 0 .. 100;
diff --git a/challenge-148/e-choroba/perl/ch-2.pl b/challenge-148/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..e453b21073
--- /dev/null
+++ b/challenge-148/e-choroba/perl/ch-2.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+# https://stackoverflow.com/a/70414782/1030675
+sub cardano_triplets {
+ my ($count) = @_;
+ for (my $u = 1; $count--; $u += 2) {
+ my $A = (1 + 3 * $u) / 2;
+ my $t = $u * $u * $u + $A * $A;
+
+ my $B = int sqrt $t;
+ --$B while $t % ($B * $B);
+
+ my $C = $t / ($B * $B);
+
+ say "$A $B $C";
+ }
+}
+
+# This finds all the triplets, but they aren't sorted so nicely.
+sub cardano_triplets_all {
+ my ($count) = @_;
+ for (my $u = 1;; $u += 2) {
+ my $A = (1 + 3 * $u) / 2;
+ my $t = $u * $u * $u + $A * $A;
+
+ my $B = int sqrt $t;
+ while (1) {
+ --$B while $B && $t % ($B * $B);
+ last unless $B;
+
+ my $C = $t / ($B * $B);
+ say "$A $B $C";
+ return unless --$count;
+
+ --$B;
+ }
+ }
+}
+
+cardano_triplets(5);
+say '-' x 10;
+cardano_triplets_all(5);
diff --git a/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm b/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm
new file mode 100755
index 0000000000..04b2bf80f2
--- /dev/null
+++ b/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm
Binary files differ
diff --git a/challenge-148/eric-cheung/excel-vba/ch-1.bas b/challenge-148/eric-cheung/excel-vba/ch-1.bas
new file mode 100755
index 0000000000..230fb4f7d5
--- /dev/null
+++ b/challenge-148/eric-cheung/excel-vba/ch-1.bas
@@ -0,0 +1,131 @@
+Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Function ConvUnitDigitToWord(ByVal nUnitDigit As Integer) As String
+
+ Select Case nUnitDigit
+ Case 1
+ ConvUnitDigitToWord = "One"
+ Case 2
+ ConvUnitDigitToWord = "Two"
+ Case 3
+ ConvUnitDigitToWord = "Three"
+ Case 4
+ ConvUnitDigitToWord = "Four"
+ Case 5
+ ConvUnitDigitToWord = "Five"
+ Case 6
+ ConvUnitDigitToWord = "Six"
+ Case 7
+ ConvUnitDigitToWord = "Seven"
+ Case 8
+ ConvUnitDigitToWord = "Eight"
+ Case 9
+ ConvUnitDigitToWord = "Nine"
+ End Select
+
+End Function
+
+Function ConvElevenToNineteenWord(ByVal nInput As Integer) As String
+
+ Select Case nInput
+ Case 11
+ ConvElevenToNineteenWord = "Eleven"
+ Case 12
+ ConvElevenToNineteenWord = "Twelve"
+ Case 13
+ ConvElevenToNineteenWord = "Thirteen"
+ Case 14
+ ConvElevenToNineteenWord = "Forteen"
+ Case 15
+ ConvElevenToNineteenWord = "Fifteen"
+ Case 16
+ ConvElevenToNineteenWord = "Sixteen"
+ Case 17
+ ConvElevenToNineteenWord = "Seventeen"
+ Case 18
+ ConvElevenToNineteenWord = "Eighteen"
+ Case 19
+ ConvElevenToNineteenWord = "Nineteen"
+ End Select
+
+End Function
+
+Function ConvTenDigitToWord(ByVal nTenDigit As Integer) As String
+
+ Select Case nTenDigit
+ Case 2
+ ConvTenDigitToWord = "Twenty"
+ Case 3
+ ConvTenDigitToWord = "Thirty"
+ Case 4
+ ConvTenDigitToWord = "Forty"
+ Case 5
+ ConvTenDigitToWord = "Fifty"
+ Case 6
+ ConvTenDigitToWord = "Sixty"
+ Case 7
+ ConvTenDigitToWord = "Seventy"
+ Case 8
+ ConvTenDigitToWord = "Eighty"
+ Case 9
+ ConvTenDigitToWord = "Ninety"
+ End Select
+
+End Function
+
+Function ConvNumToWord(ByVal nInput As Integer) As String
+
+ If nInput > 100 Then
+ ConvNumToWord = ""
+ Exit Function
+ End If
+
+ If nInput = 0 Then
+ ConvNumToWord = "Zero"
+ Exit Function
+ End If
+
+ If nInput < 0 Then
+ ConvNumToWord = ""
+ Exit Function
+ End If
+
+ If nInput = 100 Then
+ ConvNumToWord = "One Hundred"
+ ElseIf nInput < 10 Then
+ ConvNumToWord = ConvUnitDigitToWord(nInput)
+ ElseIf nInput = 10 Then
+ ConvNumToWord = "Ten"
+ ElseIf nInput < 20 Then
+ ConvNumToWord = ConvElevenToNineteenWord(nInput)
+ ElseIf nInput Mod 10 = 0 Then
+ ConvNumToWord = ConvTenDigitToWord(nInput / 10)
+ Else
+ ConvNumToWord = ConvTenDigitToWord(Int(nInput / 10)) & " " & ConvUnitDigitToWord(nInput Mod 10)
+ End If
+
+End Function
+
+Sub Task_01()
+
+ '' Remarks
+ '' https://en.wikipedia.org/wiki/Ban_number#:~:text=The%20first%20few%20eban%20numbers,in%20the%20sequence%20are%20even.
+
+ Dim strMsg As String
+ Dim nLoop As Integer
+
+ For nLoop = 1 To 100
+ If InStr(1, LCase(ConvNumToWord(nLoop)), "e") = 0 Then
+ If strMsg <> "" Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & nLoop
+ End If
+ Next nLoop
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-148/eric-cheung/python/ch-2.py b/challenge-148/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..1e1311e7d4
--- /dev/null
+++ b/challenge-148/eric-cheung/python/ch-2.py
@@ -0,0 +1,44 @@
+## Credit:
+## https://theweeklychallenge.org/blog/perl-weekly-challenge-148/
+## https://github.com/Anshumanmahan/Cardano-Triplets/blob/master/CardanoTriplets.py
+## https://medium.com/swift-programming/cardano-triplets-in-swift-114692293795
+
+import math
+
+nCount = 0
+nCountMax = 5
+
+nNumMax = 200
+
+for nNum_01 in range(1, nNumMax):
+ for nNum_02 in range(1, nNumMax):
+ for nNum_03 in range(1, nNumMax):
+ x = nNum_01 - nNum_02 * math.sqrt(nNum_03)
+
+ if (x > 0):
+ y = math.pow(x, float(1) / 3)
+ else:
+ y = - math.pow(abs(x), float(1) / 3)
+
+ z = math.pow(nNum_01 + nNum_02 * math.sqrt(nNum_03), float(1) / 3.0) + y
+
+ ## Floating Point Rounding Errors
+ if (z > 0.999999 and z < 1.000001):
+ nCount = nCount + 1
+ print(nNum_01, nNum_02, nNum_03)
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+## Results
+## 2 1 5
+## 5 1 52
+## 5 2 13
+## 8 1 189
+## 8 3 21
diff --git a/challenge-148/mark-anderson/raku/ch-1.raku b/challenge-148/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..8d3b7989ea
--- /dev/null
+++ b/challenge-148/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/usr/bin/env raku
+
+use Lingua::EN::Numbers;
+
+.say for (^101).grep({ not cardinal($_).contains('e') });
diff --git a/challenge-148/perlboy1967/perl/ch-1.pl b/challenge-148/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..8a3e2fff54
--- /dev/null
+++ b/challenge-148/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,59 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 148
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-148/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › Eban Numbers
+Submitted by: Mohammad S Anwar
+
+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).
+
+NOTE:
+ Oops, misread the challenge. I thought it was: "generate the first 100".
+ (which is more fun to do efficiently and not bute force)
+
+ The challenge can be done by:
+
+ use Lingua::EN::Numbers qw(num2en);
+ say join',',grep/\d/,map{num2en($_)=~/e/?'':$_}(2..100);
+
+=cut
+
+use v5.16;
+
+# Eban is just a funny 20 base number system with
+# some odd encoding of each 20 numbers :-)
+
+my @e = (0,2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,64,66);
+
+my %en = map { (substr('00'.$e[$_],-3,3), $_) } (0 .. scalar(@e)-1);
+
+my @eban = @e[1..scalar(@e)-1];
+
+my $len = shift // 100;
+
+while (scalar(@eban) < $len) {
+ my @f = map {$en{$_}} reverse unpack('(A3)*','0'x(3-length($eban[-1])%3).$eban[-1]);
+
+ $f[0]++;
+ $f[0] %= scalar(@e);
+ my $carry = ($f[0] == 0 ? 1 : 0);
+ foreach my $i (1 .. scalar(@f)-1) {
+ $f[$i] += $carry;
+ $f[$i] %= scalar(@e);
+ $carry = ($f[$i] == 0 ? 1 : 0);
+ }
+ push(@f,1) if ($carry);
+