aboutsummaryrefslogtreecommitdiff
path: root/challenge-059
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-10 18:11:00 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-10 18:11:00 +0100
commit4165456c4177c2de758ec3caba003b615ab26b3b (patch)
treeadd36a00cb61b60172c03774056a7cb5439a20ff /challenge-059
parentaa268a15060ccd7d3eb0c04c4e50fe588e224a94 (diff)
downloadperlweeklychallenge-club-4165456c4177c2de758ec3caba003b615ab26b3b.tar.gz
perlweeklychallenge-club-4165456c4177c2de758ec3caba003b615ab26b3b.tar.bz2
perlweeklychallenge-club-4165456c4177c2de758ec3caba003b615ab26b3b.zip
- Added solutions by Richard Park.
Diffstat (limited to 'challenge-059')
-rw-r--r--challenge-059/richard-park/apl/BitSum.aplf8
-rw-r--r--challenge-059/richard-park/apl/LinkedList.aplf4
-rw-r--r--challenge-059/richard-park/apl/ch-1.aplf4
-rw-r--r--challenge-059/richard-park/apl/ch-2.aplf8
-rw-r--r--challenge-059/richard-park/raku/ch-1.raku13
5 files changed, 37 insertions, 0 deletions
diff --git a/challenge-059/richard-park/apl/BitSum.aplf b/challenge-059/richard-park/apl/BitSum.aplf
new file mode 100644
index 0000000000..b29788237a
--- /dev/null
+++ b/challenge-059/richard-park/apl/BitSum.aplf
@@ -0,0 +1,8 @@
+ BitSum←{
+⍝ ⍵: List of positive integers
+⍝ ←: Sum of differing bits between binary
+⍝ representations of all unique pairs in ⍵
+ BSP←{+⌿≠⌿⍉2⊥⍣¯1⊢⍺ ⍵} ⍝ Bit Sum of Pairs
+ bs←+/,∘.BSP⍨⍵ ⍝ The bit sum of all pairs in ⍵
+ bs÷2 ⍝ Outer product ∘.f double counts
+ }
diff --git a/challenge-059/richard-park/apl/LinkedList.aplf b/challenge-059/richard-park/apl/LinkedList.aplf
new file mode 100644
index 0000000000..6a54e28933
--- /dev/null
+++ b/challenge-059/richard-park/apl/LinkedList.aplf
@@ -0,0 +1,4 @@
+ LinkedList←{
+⍝ ⍵ with elements < ⍺ moved to the front
+ (⍵⌿⍨b),(⍵⌿⍨~b←⍵<⍺)
+ }
diff --git a/challenge-059/richard-park/apl/ch-1.aplf b/challenge-059/richard-park/apl/ch-1.aplf
new file mode 100644
index 0000000000..6a54e28933
--- /dev/null
+++ b/challenge-059/richard-park/apl/ch-1.aplf
@@ -0,0 +1,4 @@
+ LinkedList←{
+⍝ ⍵ with elements < ⍺ moved to the front
+ (⍵⌿⍨b),(⍵⌿⍨~b←⍵<⍺)
+ }
diff --git a/challenge-059/richard-park/apl/ch-2.aplf b/challenge-059/richard-park/apl/ch-2.aplf
new file mode 100644
index 0000000000..b29788237a
--- /dev/null
+++ b/challenge-059/richard-park/apl/ch-2.aplf
@@ -0,0 +1,8 @@
+ BitSum←{
+⍝ ⍵: List of positive integers
+⍝ ←: Sum of differing bits between binary
+⍝ representations of all unique pairs in ⍵
+ BSP←{+⌿≠⌿⍉2⊥⍣¯1⊢⍺ ⍵} ⍝ Bit Sum of Pairs
+ bs←+/,∘.BSP⍨⍵ ⍝ The bit sum of all pairs in ⍵
+ bs÷2 ⍝ Outer product ∘.f double counts
+ }
diff --git a/challenge-059/richard-park/raku/ch-1.raku b/challenge-059/richard-park/raku/ch-1.raku
new file mode 100644
index 0000000000..e4fe1fb0d4
--- /dev/null
+++ b/challenge-059/richard-park/raku/ch-1.raku
@@ -0,0 +1,13 @@
+use v6;
+sub LinkedList($k = 4, @array = (2,3,7,4,3,1)) {
+ # Returns elements in @array with those less than @k at front
+ # Ordering is otherwise retained
+ my @splitonk = ($_ if $_ < $k for @array);
+ @splitonk.append(($_ if $_ >= $k for @array));
+ @splitonk; # Default (2,3,3,1,7,4)
+}
+
+my @linked_list = (1,4,3,2,5,2);
+my $k = 3;
+say LinkedList();
+say LinkedList($k,@linked_list);