diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-10-15 12:28:16 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-10-15 12:28:16 +0100 |
| commit | 9bdc1c2ddb76ce9b78a72d83f856f8d52ad7fb99 (patch) | |
| tree | 1d5919c559cad3737bf1646e3fbe6e7a7fdd0887 | |
| parent | 35251a48c41b394fe9017bdad1b04824fd340197 (diff) | |
| parent | 5365a29aecdece7055d66b81e19aad7d8ecfed61 (diff) | |
| download | perlweeklychallenge-club-9bdc1c2ddb76ce9b78a72d83f856f8d52ad7fb99.tar.gz perlweeklychallenge-club-9bdc1c2ddb76ce9b78a72d83f856f8d52ad7fb99.tar.bz2 perlweeklychallenge-club-9bdc1c2ddb76ce9b78a72d83f856f8d52ad7fb99.zip | |
Merge remote-tracking branch 'upstream/master'
vi ch-#
85 files changed, 3294 insertions, 1359 deletions
diff --git a/challenge-088/conor-hoekstra/apl/ch-1.apl b/challenge-088/conor-hoekstra/apl/ch-1.apl new file mode 100644 index 0000000000..1cafa31091 --- /dev/null +++ b/challenge-088/conor-hoekstra/apl/ch-1.apl @@ -0,0 +1,10 @@ +⍝ Two Suboptimal Solutions +solution ← ⊃×/∘(¯1↓⍳∘≢⌽¨⊂) ⍝ Using rotates +solution ← ×/¨((↓∘.≠⍨∘⍳∘≢)⊢⍤/¨⊂) ⍝ Using filters (compresses) + +⍝ The Actual Solution +solution ← ×/÷⊢ + +⍝ Tests +solution 5 2 1 4 3 ⍝ 24 60 120 30 40 +solution 2 1 4 3 ⍝ 12 24 6 8 diff --git a/challenge-088/conor-hoekstra/bqn/ch-1.bqn b/challenge-088/conor-hoekstra/bqn/ch-1.bqn new file mode 100644 index 0000000000..5bdeb4fe6a --- /dev/null +++ b/challenge-088/conor-hoekstra/bqn/ch-1.bqn @@ -0,0 +1,10 @@ +# Two Suboptimal Solutions +Solution ← ×´¨1↓¨(↕∘≠)⌽¨< # Using rotates +Solution ← ×´¨(<˘≠⌜˜∘↕∘≠)/¨< # Using filters (replicates) + +# The Actual Solution +Solution ← ×´÷⊢ + +# Tests +Solution 5‿2‿1‿4‿3 # ⟨ 24 60 120 30 40 ⟩ +Solution 2‿1‿4‿3 # ⟨ 12 24 6 8 ⟩ diff --git a/challenge-088/conor-hoekstra/cpp/ch-1.cpp b/challenge-088/conor-hoekstra/cpp/ch-1.cpp new file mode 100644 index 0000000000..722df1bf47 --- /dev/null +++ b/challenge-088/conor-hoekstra/cpp/ch-1.cpp @@ -0,0 +1,12 @@ +// Godbolt Link: https://godbolt.org/z/dGGKzdYhn + +#include <algorithm> +#include <numeric> +#include <vector> +#include <functional> + +auto array_product(std::vector<int> v) -> std::vector<int> { + auto const prod = std::accumulate(v.cbegin(), v.cend(), 1, std::multiplies{}); + std::transform(v.cbegin(), v.cend(), v.begin(), [=] (auto e) { return prod / e; }); + return v; +} diff --git a/challenge-088/conor-hoekstra/haskell/ch-1.hs b/challenge-088/conor-hoekstra/haskell/ch-1.hs new file mode 100644 index 0000000000..0d862cf94a --- /dev/null +++ b/challenge-088/conor-hoekstra/haskell/ch-1.hs @@ -0,0 +1,7 @@ +import Control.Monad (<*>) + +solution = flip (zipWith (div) . repeat) <*> product + +-- Tests +solution [5,2,1,4,3] -- [24,60,120,30,40] +solution [2,1,4,3] -- [12,24,6,8] diff --git a/challenge-088/conor-hoekstra/j/ch-1.ijs b/challenge-088/conor-hoekstra/j/ch-1.ijs new file mode 100644 index 0000000000..e4e66a2009 --- /dev/null +++ b/challenge-088/conor-hoekstra/j/ch-1.ijs @@ -0,0 +1,4 @@ +solution =. %~*/ + +solution 5 2 1 4 3 NB. 24 60 120 30 40 +solution 2 1 4 3 NB. 12 24 6 8 diff --git a/challenge-111/conor-hoekstra/apl/ch-1.apl b/challenge-111/conor-hoekstra/apl/ch-1.apl new file mode 100644 index 0000000000..258593d268 --- /dev/null +++ b/challenge-111/conor-hoekstra/apl/ch-1.apl @@ -0,0 +1,6 @@ +exists ← ∨/,⍤= + +⍝ Tests +input ← 4 4⍴⍳16 +10 exists input ⍝ 1 +20 exists input ⍝ 0 diff --git a/challenge-111/conor-hoekstra/apl/ch-2.apl b/challenge-111/conor-hoekstra/apl/ch-2.apl new file mode 100644 index 0000000000..30f113bd9b --- /dev/null +++ b/challenge-111/conor-hoekstra/apl/ch-2.apl @@ -0,0 +1,8 @@ +solution ← { + s ← ⍵/⍨(⊢≡⍳∘≢)∘⍋¨⍵ + ⊃s/⍨(⌈/=⊢)≢¨s +} + +⍝ Tests +solution 'ant' 'cat' 'dog' 'bee' 'deer' 'mouse' ⍝ deer +solution 'aNt' 'Cat' 'dog' 'bee' 'Deer' 'mouse' ⍝ Deer diff --git a/challenge-111/conor-hoekstra/bqn/ch-1.bqn b/challenge-111/conor-hoekstra/bqn/ch-1.bqn new file mode 100644 index 0000000000..75a1807ac3 --- /dev/null +++ b/challenge-111/conor-hoekstra/bqn/ch-1.bqn @@ -0,0 +1,6 @@ +Exists ← ∨´⥊∘= + +# Test +input ← 4‿4⥊↕16 +10 Exists input # 1 +20 Exists input # 0 diff --git a/challenge-111/conor-hoekstra/bqn/ch-2.bqn b/challenge-111/conor-hoekstra/bqn/ch-2.bqn new file mode 100644 index 0000000000..421257a3cd --- /dev/null +++ b/challenge-111/conor-hoekstra/bqn/ch-2.bqn @@ -0,0 +1,4 @@ +Solution ← {⊑(⊢/˜·(⌈´=⊢)≠¨)(⊢/˜∧≡⊢)¨𝕩} + +# Tests (not doesn't work for uppercase) +Solution "ant"‿"cat"‿"dog"‿"bee"‿"deer"‿"mouse" # "deer" diff --git a/challenge-111/conor-hoekstra/j/ch-1.ijs b/challenge-111/conor-hoekstra/j/ch-1.ijs new file mode 100644 index 0000000000..ca72766b1c --- /dev/null +++ b/challenge-111/conor-hoekstra/j/ch-1.ijs @@ -0,0 +1,6 @@ +exists =. [:+./,@:= + +NB. Tests +input =. i.4 4 +10 exists input NB. 1 +20 exists input NB. 0 diff --git a/challenge-131/peter-campbell-smith/perl/ch-1.pl b/challenge-131/peter-campbell-smith/perl/ch-1.pl index e7f902759b..17b15e8966 100755 --- a/challenge-131/peter-campbell-smith/perl/ch-1.pl +++ b/challenge-131/peter-campbell-smith/perl/ch-1.pl @@ -3,44 +3,42 @@ use strict; use warnings; use v5.10; -# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20 +# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20 -# You are given a string of delimiter pairs and a string to search. - -# Write a script to return two strings, the first with any characters matching -# the “opening character” set, the second with any matching the “closing character” set. +# You are given a sorted list of unique positive integers. +# Write a script to return list of arrays where the arrays are consecutive integers. my ($delimiter_pairs, $search_string, $openers, $closers); # loop over input values until (eof(DATA)) { - $delimiter_pairs = <DATA>;; - $search_string = <DATA>; - chop($delimiter_pairs, $search_string); - do_task(); + $delimiter_pairs = <DATA>;; + $search_string = <DATA>; + chop($delimiter_pairs, $search_string); + do_task(); } sub do_task { - - my ($openers, $closers, $opens, $closes); - - # copy the search string - $openers = $closers = $search_string; - - # pick off the delimiters in pairs and make strings of the opening and closing characters - while ($delimiter_pairs =~ m|(.)(.)|g) { - $opens .= $1; - $closes .= $2; - } - - # remove all but the opening characters from $openers and similarly with $closers - $openers =~ s|[^\Q$opens\E]||g; - $closers =~ s|[^\Q$closes\E]||g; - - say qq[\nDelimiter pairs: $delimiter_pairs]; - say qq[Search string: $search_string]; - say qq[Openers: $openers]; - say qq[Closers: $closers]; + + my ($openers, $closers, $opens, $closes); + + # copy the search string + $openers = $closers = $search_string; + + # pick off the delimiters in pairs and make strings of the opening and closing characters + while ($delimiter_pairs =~ m|(.)(.)|g) { + $opens .= $1; + $closes .= $2; + } + + # remove all but the opening characters from $openers and similarly with $closers + $openers =~ s|[^\Q$opens\E]||g; + $closers =~ s|[^\Q$closes\E]||g; + + say qq[\nDelimiter pairs: $delimiter_pairs]; + say qq[Search string: $search_string]; + say qq[Openers: $openers]; + say qq[Closers: $closers]; } __DATA__ diff --git a/challenge-131/peter-campbell-smith/perl/ch-2.pl b/challenge-131/peter-campbell-smith/perl/ch-2.pl index 1c364e87dc..bc22d0b343 100755 --- a/challenge-131/peter-campbell-smith/perl/ch-2.pl +++ b/challenge-131/peter-campbell-smith/perl/ch-2.pl @@ -3,32 +3,34 @@ use strict; use warnings; use v5.10; -# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20 +# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20 -# You are given a sorted list of unique positive integers. -# Write a script to return list of arrays where the arrays are consecutive integers. +# You are given a string of delimiter pairs and a string to search. + +# Write a script to return two strings, the first with any characters matching +# the “opening character” set, the second with any matching the “closing character” set. my $input; # loop over input examples until (eof(DATA)) { - $input = <DATA>; - chop $input; - do_task(); + $input = <DATA>; + chop $input; + do_task(); } sub do_task { - - my ($prev, $output); - - # loop over list - $prev = -1; - while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive - $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1"; - $prev = $1; - } - $output =~ s|...|(|; # tidy the start of $output - say "\nInput: ($input)\nOutput: $output])"; + + my ($prev, $output); + + # loop over list + $prev = -1; + while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive + $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1"; + $prev = $1; + } + $output =~ s|...|(|; # tidy the start of $output + say "\nInput: ($input)\nOutput: $output])"; } __DATA__ diff --git a/challenge-132/cheok-yin-fung/perl/ch-1.pl b/challenge-132/cheok-yin-fung/perl/ch-1.pl index 7bfe736e7d..ed95f49ea2 100644 --- a/challenge-132/cheok-yin-fung/perl/ch-1.pl +++ b/challenge-132/cheok-yin-fung/perl/ch-1.pl @@ -14,7 +14,6 @@ sub mirror { my $_today = timelocal(0, 0, 0, @arr_today); my @arr_birth = ($_[2], $_[1]-1, $_[0]); my $_birth = timelocal(0, 0, 0, @arr_birth); - my $sec_diff = $_today - $_birth; my $y1 = int (($_today - $_birth)/86400); my @d_senior = localtime timegm_nocheck 0, 0, 0, $arr_birth[0]-$y1, $arr_birth[1], $arr_birth[2]; my @d_junior = localtime timegm_nocheck 0, 0, 0, $arr_today[0]+$y1, $arr_today[1], $arr_today[2]; diff --git a/challenge-134/abigail/README.md b/challenge-134/abigail/README.md index d51d3d73e2..7cb7880ca3 100644 --- a/challenge-134/abigail/README.md +++ b/challenge-134/abigail/README.md @@ -2,9 +2,41 @@ ## Part 1 +* [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) +* [Basic](basic/ch-1.bas) +* [bc](bc/ch-1.bc) +* [Befunge-93](befunge-93/ch-1.bf93) +* [C](c/ch-1.c) +* [Erlang](erlang/ch-1.erl) +* [Go](go/ch-1.go) +* [Java](java/ch-1.java) +* [Lua](lua/ch-1.lua) +* [m4](m4/ch-1.m4) +* [Node.js](node/ch-1.js) +* [Pascal](pascal/ch-1.p) * [Perl](perl/ch-1.pl) +* [PHP](php/ch-1.php) +* [Python](python/ch-1.py) +* [R](r/ch-1.r) +* [Ruby](ruby/ch-1.rb) +* [Scheme](scheme/ch-1.scm) +* [Tcl](tcl/ch-1.tcl) ## Part 2 +* [AWK](awk/ch-2.awk) +* [Bash](bash/ch-2.sh) +* [bc](bc/ch-2.bc) * [C](c/ch-2.c) +* [Go](go/ch-2.go) +* [Java](java/ch-2.java) +* [Lua](lua/ch-2.lua) +* [Node.js](node/ch-2.js) +* [Pascal](pascal/ch-2.p) * [Perl](perl/ch-2.pl) +* [Python](python/ch-2.py) +* [R](r/ch-2.r) +* [Ruby](ruby/ch-2.rb) +* [Scheme](scheme/ch-2.scm) +* [Tcl](tcl/ch-2.tcl) diff --git a/challenge-134/abigail/awk/ch-1.awk b/challenge-134/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..e1bb7f9695 --- /dev/null +++ b/challenge-134/abigail/awk/ch-1.awk @@ -0,0 +1,16 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk +# + +BEGIN { < |
