aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-15 01:57:55 +0000
committerGitHub <noreply@github.com>2022-12-15 01:57:55 +0000
commite2b33f546bda365fe677e14e725bb53a5f23798c (patch)
treea99ca3ed8e82e367b0aba5acd5cec50e5b48757f
parent2b99b6e28c2a3b672e50d7b22cd3e1c6998670c7 (diff)
parentc1d3932971f399789d4ee01cb886bb1e984f2563 (diff)
downloadperlweeklychallenge-club-e2b33f546bda365fe677e14e725bb53a5f23798c.tar.gz
perlweeklychallenge-club-e2b33f546bda365fe677e14e725bb53a5f23798c.tar.bz2
perlweeklychallenge-club-e2b33f546bda365fe677e14e725bb53a5f23798c.zip
Merge branch 'manwar:master' into master
-rw-r--r--challenge-195/0rir/raku/ch-1.raku52
-rw-r--r--challenge-195/0rir/raku/ch-2.raku59
-rw-r--r--challenge-195/carlos-oliveira/README1
-rw-r--r--challenge-195/carlos-oliveira/perl/ch-1.pl11
-rw-r--r--challenge-195/carlos-oliveira/perl/ch-2.pl30
-rw-r--r--challenge-195/dave-jacoby/perl/ch-1.pl26
-rw-r--r--challenge-195/dave-jacoby/perl/ch-2.pl29
-rwxr-xr-xchallenge-195/eric-cheung/python/ch-1.py30
-rwxr-xr-xchallenge-195/eric-cheung/python/ch-2.py20
-rwxr-xr-xchallenge-195/jeanluc2020/perl/ch-1.pl31
-rwxr-xr-xchallenge-195/jeanluc2020/perl/ch-2.pl30
-rw-r--r--challenge-195/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-195/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-195/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-195/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-195/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-195/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-195/luca-ferrari/postgresql/ch-1.plperl40
-rw-r--r--challenge-195/luca-ferrari/postgresql/ch-1.sql31
-rw-r--r--challenge-195/luca-ferrari/postgresql/ch-2.plperl29
-rw-r--r--challenge-195/luca-ferrari/postgresql/ch-2.sql42
-rw-r--r--challenge-195/luca-ferrari/raku/ch-1.p613
-rw-r--r--challenge-195/luca-ferrari/raku/ch-2.p615
-rw-r--r--challenge-195/mark-anderson/raku/ch-1.raku22
-rw-r--r--challenge-195/mark-anderson/raku/ch-2.raku11
-rw-r--r--challenge-195/olivier-delouya/perl/ch-1.sh5
-rw-r--r--challenge-195/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-195/peter-campbell-smith/perl/ch-1.pl76
-rwxr-xr-xchallenge-195/peter-campbell-smith/perl/ch-2.pl47
-rw-r--r--challenge-195/pip/README1
-rwxr-xr-xchallenge-195/pip/perl/ch-1.pl23
-rwxr-xr-xchallenge-195/pip/perl/ch-2.pl44
-rw-r--r--challenge-195/robert-dicicco/julia/ch-1.jl79
-rw-r--r--challenge-195/robert-dicicco/perl/ch-1.pl77
-rw-r--r--challenge-195/robert-dicicco/python/ch-1.py63
-rw-r--r--challenge-195/robert-dicicco/raku/ch-1.raku63
-rw-r--r--challenge-195/robert-dicicco/ruby/ch-1.rb63
-rwxr-xr-xchallenge-195/roger-bell-west/javascript/ch-1.js37
-rwxr-xr-xchallenge-195/roger-bell-west/javascript/ch-2.js45
-rw-r--r--challenge-195/roger-bell-west/kotlin/ch-1.kt30
-rw-r--r--challenge-195/roger-bell-west/kotlin/ch-2.kt38
-rwxr-xr-xchallenge-195/roger-bell-west/lua/ch-1.lua34
-rwxr-xr-xchallenge-195/roger-bell-west/lua/ch-2.lua51
-rwxr-xr-xchallenge-195/roger-bell-west/perl/ch-1.pl26
-rwxr-xr-xchallenge-195/roger-bell-west/perl/ch-2.pl30
-rw-r--r--challenge-195/roger-bell-west/postscript/ch-1.ps66
-rw-r--r--challenge-195/roger-bell-west/postscript/ch-2.ps180
-rwxr-xr-xchallenge-195/roger-bell-west/python/ch-1.py28
-rwxr-xr-xchallenge-195/roger-bell-west/python/ch-2.py30
-rwxr-xr-xchallenge-195/roger-bell-west/raku/ch-1.p622
-rwxr-xr-xchallenge-195/roger-bell-west/raku/ch-2.p626
-rwxr-xr-xchallenge-195/roger-bell-west/ruby/ch-1.rb29
-rwxr-xr-xchallenge-195/roger-bell-west/ruby/ch-2.rb34
-rwxr-xr-xchallenge-195/roger-bell-west/rust/ch-1.rs34
-rwxr-xr-xchallenge-195/roger-bell-west/rust/ch-2.rs38
-rw-r--r--challenge-195/ulrich-rieke/cpp/ch-1.cpp35
-rw-r--r--challenge-195/ulrich-rieke/cpp/ch-2.cpp54
-rw-r--r--challenge-195/ulrich-rieke/haskell/ch-1.hs11
-rw-r--r--challenge-195/ulrich-rieke/haskell/ch-2.hs21
-rw-r--r--challenge-195/ulrich-rieke/perl/ch-1.pl30
-rw-r--r--challenge-195/ulrich-rieke/perl/ch-2.pl33
-rw-r--r--challenge-195/ulrich-rieke/raku/ch-1.raku26
-rw-r--r--challenge-195/ulrich-rieke/raku/ch-2.raku25
-rw-r--r--challenge-195/ulrich-rieke/rust/ch-1.rs34
-rw-r--r--challenge-195/ulrich-rieke/rust/ch-2.rs33
-rw-r--r--challenge-195/wlmb/blog.txt1
-rwxr-xr-xchallenge-195/wlmb/perl/ch-1.pl48
-rwxr-xr-xchallenge-195/wlmb/perl/ch-2.pl10
-rwxr-xr-xchallenge-195/zapwai/perl/ch-1.pl28
-rwxr-xr-xchallenge-195/zapwai/perl/ch-2.pl27
-rw-r--r--challenge-195/ziameraj16/java/MostFrequentEven.java31
-rw-r--r--members.json2
-rw-r--r--stats/pwc-challenge-194.json631
-rw-r--r--stats/pwc-current.json595
-rw-r--r--stats/pwc-language-breakdown-summary.json70
-rw-r--r--stats/pwc-language-breakdown.json1385
-rw-r--r--stats/pwc-leaders.json404
-rw-r--r--stats/pwc-summary-1-30.json40
-rw-r--r--stats/pwc-summary-121-150.json68
-rw-r--r--stats/pwc-summary-151-180.json40
-rw-r--r--stats/pwc-summary-181-210.json60
-rw-r--r--stats/pwc-summary-211-240.json130
-rw-r--r--stats/pwc-summary-241-270.json136
-rw-r--r--stats/pwc-summary-271-300.json56
-rw-r--r--stats/pwc-summary-31-60.json116
-rw-r--r--stats/pwc-summary-61-90.json110
-rw-r--r--stats/pwc-summary-91-120.json128
-rw-r--r--stats/pwc-summary.json644
88 files changed, 4764 insertions, 2146 deletions
diff --git a/challenge-195/0rir/raku/ch-1.raku b/challenge-195/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..2c7de79d23
--- /dev/null
+++ b/challenge-195/0rir/raku/ch-1.raku
@@ -0,0 +1,52 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅ ≡ ∩ ≢ ∈ «␤»
+use v6.d;
+use Test;
+
+=begin comment
+195-1: Special Integers Submitted by: Mohammad S Anwar
+
+An integer is special when all of its digits are unique.
+Given a positive integer, $n > 0, print the count of all special integers
+between 1 and $n.
+
+Example 1:
+Input: $n = 15
+Output: 14 as except 11 all other integers between 1 and 15 are spcial.
+Example 2:
+Input: $n = 35
+Output: 32 as except 11, 22, 33 all others are special.
+=end comment
+
+constant @special-int-ct = gather {
+ take Nil;
+ loop {
+ state ( $i, $prev) = 0, 0;
+ ++$i;
+ take $i.Str.comb.elems == $i.Str.comb.unique.elems ?? ++$prev !! $prev;
+ }
+}
+
+multi MAIN ( 'test' ) {
+ my @Test =
+ { in => 15, exp => 14, },
+ { in => 35, exp => 32, },
+ { in => 99, exp => 90, },
+ { in => 200, exp => 162, },
+ { in => 180, exp => 147, },
+ { in => 1_000, exp => 738, },
+ { in => 10_000, exp => 5_274, },
+ { in => 100_000, exp => 32_490, },
+ { in => 1_000_000, exp => 168_570, },
+ ;
+ plan +@Test;
+ for @Test -> %t {
+ is @special-int-ct[%t<in>], %t<exp>, " %t<exp> <- 1..%t<in>";
+ }
+ done-testing;
+ exit;
+}
+
+multi MAIN( $n = 180) {
+ say "Input: \$n = 180\nOutput: @special-int-ct[$n]";
+}
diff --git a/challenge-195/0rir/raku/ch-2.raku b/challenge-195/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..2356b48bec
--- /dev/null
+++ b/challenge-195/0rir/raku/ch-2.raku
@@ -0,0 +1,59 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅ ≡ ∩ ≢ ∈ «␤»
+use v6.d;
+use Test;
+
+=begin comment
+195-2: Most Frequent Even Submitted by: Mohammad S Anwar
+
+Given a list of numbers, @list, find the most frequent even numbers in the
+list. In case you get more than one even number then return the smallest
+even integer. For all other case, return -1.
+
+Example 1
+Input: @list = (1,1,2,6,2)
+Output: 2 as there are only 2 even numbers 2 and 6 and of those 2 appears the most.
+Example 2
+Input: @list = (1,3,5,7)
+Output: -1 since no even numbers found in the list
+Example 3
+Input: @list = (6,4,4,6,1)
+Output: 4 since there are only two even numbers 4 and 6. They both appears the equal number of times, so pick the smallest.
+=end comment
+
+sub most-freqy-even( @l where * !~~ () --> Int) {
+ my %h = Bag.new( @l.grep( * %% 2));
+ %h = grep { .key == %h.keys.min}, %h.grep( { .value ~~ %h.values.max});
+ return (Int) if %h ~~ {};
+ %h.keys[0].Int;
+}
+
+multi MAIN ( 'test' ) {
+ my @Die = { in => (), exp => (Int), }, ;
+
+ my @Test =
+ { in => (1,1,2,2,6,6), exp => 2, },
+ { in => (1,1,2,6,2), exp => 2, },
+ { in => (1,3,5,7), exp => (Int), },
+ { in => (6,4,4,6,1), exp => 4, },
+ { in => (6,6,6,6,6), exp => 6, },
+ { in => (1,2,3,4,5), exp => 2, },
+ { in => (2,2,3,3,6,6), exp => 2, },
+ ;
+ plan +@Test + @Die;
+ for @Die -> %t {
+ dies-ok { most-freqy-even( @(%t<in>))},
+ "most-freqy-even("~ (%t<exp>//"(Int)") ~") dies.";
+ }
+ for @Test -> %t {
+ quietly is most-freqy-even( @(%t<in>) ), %t<exp>,
+ (%t<exp> // '(Int)') ~" <- %t<in>";
+ }
+ done-testing;
+}
+
+multi MAIN() {
+ my @list = (1,2,2,2,2,2,3,6,6,6,6,6);
+ say "Input: \@list = @list.join(', ');\nOutput: ",
+ &most-freqy-even(@list) // -1;
+}
diff --git a/challenge-195/carlos-oliveira/README b/challenge-195/carlos-oliveira/README
new file mode 100644
index 0000000000..f8182f8301
--- /dev/null
+++ b/challenge-195/carlos-oliveira/README
@@ -0,0 +1 @@
+Solution by Carlos Eduardo de Oliveira.
diff --git a/challenge-195/carlos-oliveira/perl/ch-1.pl b/challenge-195/carlos-oliveira/perl/ch-1.pl
new file mode 100644
index 0000000000..eb1c905189
--- /dev/null
+++ b/challenge-195/carlos-oliveira/perl/ch-1.pl
@@ -0,0 +1,11 @@
+use strict;
+use warnings;
+
+sub specialIntegers {
+ my ($limit) = @_;
+ return scalar grep { $_ !~ /(.).*\1/; } 1..$limit;
+}
+
+print specialIntegers(15), "\n"; # Output: 14
+print specialIntegers(35), "\n"; # Output: 32
+
diff --git a/challenge-195/carlos-oliveira/perl/ch-2.pl b/challenge-195/carlos-oliveira/perl/ch-2.pl
new file mode 100644
index 0000000000..c0a63c7f94
--- /dev/null
+++ b/challenge-195/carlos-oliveira/perl/ch-2.pl
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+sub mostFrequentEven {
+ my @numbers = sort @_;
+ my $currentNumber = $numbers[0];
+ my $maxEven = -1;
+ my $maxCount = 0;
+ my $currentCount = 0;
+ for my $elem (@numbers) {
+ next if $elem % 2;
+ if ($currentNumber == $elem) {
+ $currentCount++;
+ } else {
+ $currentCount = 1;
+ $currentNumber = $elem;
+ }
+ if ($currentCount > $maxCount) {
+ $maxEven = $elem;
+ $maxCount = $currentCount;
+ }
+ }
+ return $maxEven;
+}
+
+print mostFrequentEven(1,1,2,6,2), "\n";
+print mostFrequentEven(1,3,5,7), "\n";
+print mostFrequentEven(6,4,4,6,1), "\n";
+print mostFrequentEven(6,4,4,6,1,8,8,8), "\n";
+
diff --git a/challenge-195/dave-jacoby/perl/ch-1.pl b/challenge-195/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..189613873e
--- /dev/null
+++ b/challenge-195/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+my @examples = ( 15, 35 );
+for my $n (@examples) {
+ my $o = special_list($n);
+ say <<"END";
+ Input: \$n = $n
+ Output: $o
+END
+}
+
+sub special_list ( $n ) {
+ return scalar grep { is_special($_) } 1 .. $n;
+}
+
+sub is_special ( $n ) {
+ my %hash;
+ for my $i ( split //, $n ) {
+ return 0 if ++$hash{$i} > 1;
+ }
+ return 1;
+}
diff --git a/challenge-195/dave-jacoby/perl/ch-2.pl b/challenge-195/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..9a704a2c63
--- /dev/null
+++ b/challenge-195/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw{ min max };
+
+my @examples = ( [ 1, 1, 2, 6, 2 ], [ 1, 3, 5, 7 ], [ 6, 4, 4, 6, 1 ] );
+
+for my $e (@examples) {
+ my $list = join ',', $e->@*;
+ my $o = most_frequent_even( $e->@* );
+ say <<"END";
+ Input: \@list = $list
+ Output: $o
+END
+}
+
+sub most_frequent_even( @list ) {
+ my %hash;
+ map { $hash{$_}++ } grep { 0 == $_ % 2 } @list;
+ if ( scalar keys %hash ) {
+ my $max = max values %hash;
+ return min grep { $hash{$_} == $max } keys %hash;
+ }
+ return -1;
+}
+
diff --git a/challenge-195/eric-cheung/python/ch-1.py b/challenge-195/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..4839f6f0fc
--- /dev/null
+++ b/challenge-195/eric-cheung/python/ch-1.py
@@ -0,0 +1,30 @@
+
+def IsNumSpecial(nInput):
+
+ if nInput < 11:
+ return True
+
+ arrList = list(map(int, str(nInput)))
+ arrUniqList = list(set(arrList))
+
+ for nLoop in arrUniqList:
+ if arrList.count(nLoop) > 1:
+ return False
+
+ return True
+
+def nCountNumSpecial(nNum):
+
+ arrOutputList = []
+
+ for nVar in range(1, nNum + 1):
+ if IsNumSpecial(nVar):
+ arrOutputList.append(nVar)
+
+ return len(arrOutputList)
+
+
+## nGivenInput = 15 ## Example 1
+nGivenInput = 35 ## Example 2
+
+print (nCountNumSpecial(nGivenInput))
diff --git a/challenge-195/eric-cheung/python/ch-2.py b/challenge-195/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..b141abef13
--- /dev/null
+++ b/challenge-195/eric-cheung/python/ch-2.py
@@ -0,0 +1,20 @@
+
+nArrList = [1, 1, 2, 6, 2] ## Example 1
+## nArrList = [1, 3, 5, 7] ## Example 2
+## nArrList = [6, 4, 4, 6, 1] ## Example 3
+
+nArrEvenList = [nLoop for nLoop in nArrList if nLoop % 2 == 0]
+nArrUniqEvenList = list(set(nArrEvenList))
+
+nSmallEvenNum = -1
+nEvenNumCount = 0
+
+for nLoop in nArrUniqEvenList:
+
+ nCount = nArrEvenList.count(nLoop)
+
+ if nCount > nEvenNumCount and (nLoop < nSmallEvenNum or nSmallEvenNum < 0):
+ nSmallEvenNum = nLoop
+ nEvenNumCount = nCount
+
+print (nSmallEvenNum)
diff --git a/challenge-195/jeanluc2020/perl/ch-1.pl b/challenge-195/jeanluc2020/perl/ch-1.pl
new file mode 100755
index 0000000000..79573aa3fc
--- /dev/null
+++ b/challenge-195/jeanluc2020/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+foreach my $input (1..40) {
+ print "Input $input, output " . count_specials($input) . "\n";
+}
+
+sub count_specials {
+ my $number = shift;
+ my $specials = 0;
+ foreach my $i (1..$number) {
+ $specials += is_special($i);
+ }
+ return $specials;
+}
+
+sub is_special {
+ my $number = shift;
+ my $map;
+ # count all digits by adding 1 to the corresponding key in %$map for each digit
+ # the count is the value
+ map { $map->{$_}++ } split //, $number;
+ # sort values descen