From 9868c13eb66ea8c7c43bebedfca0f30ca3f002dd Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Wed, 12 Feb 2025 18:33:02 +0000 Subject: - Added solutions by Robert McIntosh. - Added solutions by Richard Park. - Added solutions by Andreas Mahnke. - Added solutions by Lubos Kolouch. - Added solutions by Steven Wilson. - Added solutions by Peter Campbell Smith. - Added solutions by Conor Hoekstra. - Added solutions by Robbie Hatley. --- challenge-308/conor-hoekstra/bqn/ch-1.bqn | 11 +++++++++++ challenge-308/conor-hoekstra/bqn/ch-2.bqn | 11 +++++++++++ challenge-308/conor-hoekstra/ch-1.bqn | 11 ----------- challenge-308/conor-hoekstra/ch-2.bqn | 11 ----------- challenge-308/richard-park/apl/CountCommon.aplf | 10 ++++++++++ challenge-308/richard-park/apl/DecodeXOR.aplf | 15 +++++++++++++++ challenge-308/robert-mcintosh/blog.txt | 1 + challenge-308/robert-mcintosh/blog1.txt | 1 + challenge-308/robert-mcintosh/python/ch-1.py | 2 ++ challenge-308/robert-mcintosh/python/ch-2.py | 8 ++++++++ challenge-308/robert-mcintosh/raku/ch-1.raku | 5 +++++ 11 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 challenge-308/conor-hoekstra/bqn/ch-1.bqn create mode 100644 challenge-308/conor-hoekstra/bqn/ch-2.bqn delete mode 100644 challenge-308/conor-hoekstra/ch-1.bqn delete mode 100644 challenge-308/conor-hoekstra/ch-2.bqn create mode 100644 challenge-308/richard-park/apl/CountCommon.aplf create mode 100644 challenge-308/richard-park/apl/DecodeXOR.aplf create mode 100644 challenge-308/robert-mcintosh/blog.txt create mode 100644 challenge-308/robert-mcintosh/blog1.txt create mode 100644 challenge-308/robert-mcintosh/python/ch-1.py create mode 100644 challenge-308/robert-mcintosh/python/ch-2.py create mode 100644 challenge-308/robert-mcintosh/raku/ch-1.raku (limited to 'challenge-308') diff --git a/challenge-308/conor-hoekstra/bqn/ch-1.bqn b/challenge-308/conor-hoekstra/bqn/ch-1.bqn new file mode 100644 index 0000000000..2e986bd207 --- /dev/null +++ b/challenge-308/conor-hoekstra/bqn/ch-1.bqn @@ -0,0 +1,11 @@ +# For up to date code: +# https://github.com/codereport/bqn-code/blob/main/pwc/308-1.bqn + +u ⇐ •Import "/home/cph/bqn-test/test.bqn" + +CommonCount ← +´∊ + +# Tests +u.UnitTest (⟨"perl", "weekly", "challenge"⟩ CommonCount ⟨"raku", "weekly", "challenge"⟩) ≡ 2 +u.UnitTest (⟨"perl", "raku", "python"⟩ CommonCount ⟨"python", "java"⟩) ≡ 1 +u.UnitTest (⟨"guest", "contribution"⟩ CommonCount ⟨"fun", "weekly", "challenge"⟩) ≡ 0 diff --git a/challenge-308/conor-hoekstra/bqn/ch-2.bqn b/challenge-308/conor-hoekstra/bqn/ch-2.bqn new file mode 100644 index 0000000000..695c1b53f3 --- /dev/null +++ b/challenge-308/conor-hoekstra/bqn/ch-2.bqn @@ -0,0 +1,11 @@ +# For up to date code: +# https://github.com/codereport/bqn-code/blob/main/pwc/308-2.bqn + +u ⇐ •Import "/home/cph/bqn-test/test.bqn" + +Xor ← { ⊑𝕨⟨32⟩•bit._xor⟨𝕩⟩ } # TODO: has to be a better way to do this +DecodeXor ← { Xor`𝕨∾𝕩 } + +# Tests +u.UnitTest (1 DecodeXor ⟨1, 2, 3⟩) ≡ ⟨1, 0, 2, 1⟩ +u.UnitTest (4 DecodeXor ⟨6, 2, 7, 3⟩) ≡ ⟨4, 2, 0, 7, 4⟩ diff --git a/challenge-308/conor-hoekstra/ch-1.bqn b/challenge-308/conor-hoekstra/ch-1.bqn deleted file mode 100644 index 2e986bd207..0000000000 --- a/challenge-308/conor-hoekstra/ch-1.bqn +++ /dev/null @@ -1,11 +0,0 @@ -# For up to date code: -# https://github.com/codereport/bqn-code/blob/main/pwc/308-1.bqn - -u ⇐ •Import "/home/cph/bqn-test/test.bqn" - -CommonCount ← +´∊ - -# Tests -u.UnitTest (⟨"perl", "weekly", "challenge"⟩ CommonCount ⟨"raku", "weekly", "challenge"⟩) ≡ 2 -u.UnitTest (⟨"perl", "raku", "python"⟩ CommonCount ⟨"python", "java"⟩) ≡ 1 -u.UnitTest (⟨"guest", "contribution"⟩ CommonCount ⟨"fun", "weekly", "challenge"⟩) ≡ 0 diff --git a/challenge-308/conor-hoekstra/ch-2.bqn b/challenge-308/conor-hoekstra/ch-2.bqn deleted file mode 100644 index 695c1b53f3..0000000000 --- a/challenge-308/conor-hoekstra/ch-2.bqn +++ /dev/null @@ -1,11 +0,0 @@ -# For up to date code: -# https://github.com/codereport/bqn-code/blob/main/pwc/308-2.bqn - -u ⇐ •Import "/home/cph/bqn-test/test.bqn" - -Xor ← { ⊑𝕨⟨32⟩•bit._xor⟨𝕩⟩ } # TODO: has to be a better way to do this -DecodeXor ← { Xor`𝕨∾𝕩 } - -# Tests -u.UnitTest (1 DecodeXor ⟨1, 2, 3⟩) ≡ ⟨1, 0, 2, 1⟩ -u.UnitTest (4 DecodeXor ⟨6, 2, 7, 3⟩) ≡ ⟨4, 2, 0, 7, 4⟩ diff --git a/challenge-308/richard-park/apl/CountCommon.aplf b/challenge-308/richard-park/apl/CountCommon.aplf new file mode 100644 index 0000000000..ac2d5a17e2 --- /dev/null +++ b/challenge-308/richard-park/apl/CountCommon.aplf @@ -0,0 +1,10 @@ + CountCommon←{ +⍝ Can be defined as the 2-train atop + CountCommon←≢∩ +⍝ Literally "count the intersection" +⍝ ≢ ∩ +⍝ Example +⍝ 'perl' 'weekly' 'challenge' (≢∩) 'raku' 'weekly' 'challenge' +⍝ 2 + ≢⍺∩⍵ + } diff --git a/challenge-308/richard-park/apl/DecodeXOR.aplf b/challenge-308/richard-park/apl/DecodeXOR.aplf new file mode 100644 index 0000000000..a2c2cb7b2b --- /dev/null +++ b/challenge-308/richard-park/apl/DecodeXOR.aplf @@ -0,0 +1,15 @@ + DecodeXOR←{ +⍝ ⍺: initial +⍝ ⍵: encoded sequence +⍝ ←: original array that produced ⍵ +⍝ ⍵ ← 2{2⊥≠/2⊥⍣¯1⊢⍵}/original + 0∊⍴⍵:⍺ + nxt←2⊥≠/2⊥⍣¯1⊢⍺,⊃⍵ + ⍺,nxt ∇ 1↓⍵ + +⍝ Examples: +⍝ 1 DecodeXOR 1 2 3 +⍝ 1 0 2 1 +⍝ 4 DecodeXOR 6 2 7 3 +⍝ 4 2 0 7 4 + } diff --git a/challenge-308/robert-mcintosh/blog.txt b/challenge-308/robert-mcintosh/blog.txt new file mode 100644 index 0000000000..e41850ae6d --- /dev/null +++ b/challenge-308/robert-mcintosh/blog.txt @@ -0,0 +1 @@ +https://dev.to/rcmcintosh/my-python-and-raku-language-solutions-to-task-1-count-common-from-the-weekly-challenge-308-3a2b diff --git a/challenge-308/robert-mcintosh/blog1.txt b/challenge-308/robert-mcintosh/blog1.txt new file mode 100644 index 0000000000..3b56b91d9b --- /dev/null +++ b/challenge-308/robert-mcintosh/blog1.txt @@ -0,0 +1 @@ +https://dev.to/rcmcintosh/my-python-language-solution-to-task-2-decode-xor-from-the-weekly-challenge-308-3a3i diff --git a/challenge-308/robert-mcintosh/python/ch-1.py b/challenge-308/robert-mcintosh/python/ch-1.py new file mode 100644 index 0000000000..4e746d6562 --- /dev/null +++ b/challenge-308/robert-mcintosh/python/ch-1.py @@ -0,0 +1,2 @@ +def count_common(str1: [str], str2: [str]) -> int: + return len(set(str1).intersection(set(str2))) diff --git a/challenge-308/robert-mcintosh/python/ch-2.py b/challenge-308/robert-mcintosh/python/ch-2.py new file mode 100644 index 0000000000..050fe8c30c --- /dev/null +++ b/challenge-308/robert-mcintosh/python/ch-2.py @@ -0,0 +1,8 @@ +def decode(encoded: list[int], initial: int) -> [int]: + original = [ + initial, + ] + for encoded_element in encoded: + original_element = original[-1] ^ encoded_element + original.append(original_element) + return original diff --git a/challenge-308/robert-mcintosh/raku/ch-1.raku b/challenge-308/robert-mcintosh/raku/ch-1.raku new file mode 100644 index 0000000000..a1f54bb29d --- /dev/null +++ b/challenge-308/robert-mcintosh/raku/ch-1.raku @@ -0,0 +1,5 @@ +sub count_common (@str1, @str2) { + my $set1 = set @str1; + my $set2 = set @str2; + return ($set1 (&) $set2).elems; +} -- cgit