aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsher Harvey-Smith <asherharveysmith@gmail.com>2024-05-13 21:58:04 +0100
committerAsher Harvey-Smith <asherharveysmith@gmail.com>2024-05-13 21:58:04 +0100
commitdc632388f15e4f5f9fdfd5806de3f621fd3d7a12 (patch)
tree14277c56f29d0f7ab1c207845244d2b67c5a9ae4
parent41729a1f195643c2e70f76894080fba89076ede7 (diff)
downloadperlweeklychallenge-club-dc632388f15e4f5f9fdfd5806de3f621fd3d7a12.tar.gz
perlweeklychallenge-club-dc632388f15e4f5f9fdfd5806de3f621fd3d7a12.tar.bz2
perlweeklychallenge-club-dc632388f15e4f5f9fdfd5806de3f621fd3d7a12.zip
ch-2
-rw-r--r--challenge-269/asherbhs/apl/ch-2.apl6
-rw-r--r--challenge-269/asherbhs/bqn/ch-2.bqn5
-rw-r--r--challenge-269/asherbhs/hy/ch-2.hy20
-rw-r--r--challenge-269/asherbhs/j/ch-2.ijs15
-rw-r--r--challenge-269/asherbhs/nu/ch-1.nu2
-rw-r--r--challenge-269/asherbhs/nu/ch-2.nu16
-rw-r--r--challenge-269/asherbhs/raku/ch-2.raku11
7 files changed, 72 insertions, 3 deletions
diff --git a/challenge-269/asherbhs/apl/ch-2.apl b/challenge-269/asherbhs/apl/ch-2.apl
index 8b13789179..69411bdf96 100644
--- a/challenge-269/asherbhs/apl/ch-2.apl
+++ b/challenge-269/asherbhs/apl/ch-2.apl
@@ -1 +1,7 @@
+⎕IO←0
+DistributeElements←{⊃,/⊃{(⊂⍺,⍨⊃)@(≤/⊃⍤⌽¨⍵)⊢⍵}/(⌽2↓⍵),⊂,¨2↑⍵}
+
+⎕←DistributeElements 2 1 3 4 5
+⎕←DistributeElements 3 2 4
+⎕←DistributeElements 5 4 3 8
diff --git a/challenge-269/asherbhs/bqn/ch-2.bqn b/challenge-269/asherbhs/bqn/ch-2.bqn
new file mode 100644
index 0000000000..a56bfe267e
--- /dev/null
+++ b/challenge-269/asherbhs/bqn/ch-2.bqn
@@ -0,0 +1,5 @@
+DistributeElements←{∾´(⋈¨2↑𝕩){∾⟜𝕨⌾((≤´¯1⊑¨𝕩)⊸⊑)𝕩}´⌽2↓𝕩}
+
+•Show DistributeElements 2‿1‿3‿4‿5
+•Show DistributeElements 3‿2‿4
+•Show DistributeElements 5‿4‿3‿8
diff --git a/challenge-269/asherbhs/hy/ch-2.hy b/challenge-269/asherbhs/hy/ch-2.hy
new file mode 100644
index 0000000000..86c01386ec
--- /dev/null
+++ b/challenge-269/asherbhs/hy/ch-2.hy
@@ -0,0 +1,20 @@
+(import hyrule [pprint])
+
+(defn distribute-elements [ints] (do
+ (setv
+ arr1 [(get ints 0)]
+ arr2 [(get ints 1)]
+ )
+ (for [n (cut ints 2 None)]
+ (if (> (get arr1 -1) (get arr2 -1))
+ (arr1.append n)
+ (arr2.append n)
+ )
+ )
+ (+ arr1 arr2)
+))
+
+(pprint (distribute-elements [2 1 3 4 5]))
+(pprint (distribute-elements [3 2 4]))
+(pprint (distribute-elements [5 4 3 8]))
+
diff --git a/challenge-269/asherbhs/j/ch-2.ijs b/challenge-269/asherbhs/j/ch-2.ijs
new file mode 100644
index 0000000000..775341a468
--- /dev/null
+++ b/challenge-269/asherbhs/j/ch-2.ijs
@@ -0,0 +1,15 @@
+DistributeElements=.{{
+ F=.{{
+ NB. couldn't get structural under to work :(
+ a=.>y
+ i=.<:/{:@>a
+ <a i}~<(>x),~>i{a
+ }}
+ ,&>/>F/(<"0|.2}.y),<<"0]2{.y
+}}
+
+echo DistributeElements 2 1 3 4 5
+echo DistributeElements 3 2 4
+echo DistributeElements 5 4 3 8
+
+exit ''
diff --git a/challenge-269/asherbhs/nu/ch-1.nu b/challenge-269/asherbhs/nu/ch-1.nu
index 56c5a86066..b4cfa52c7f 100644
--- a/challenge-269/asherbhs/nu/ch-1.nu
+++ b/challenge-269/asherbhs/nu/ch-1.nu
@@ -1,4 +1,4 @@
-def bitwise-or [ints: list<int>] {
+def bitwise-or [ints: list<int>] -> bool {
($ints | where { 0 == $in mod 2 } | length) >= 2
}
diff --git a/challenge-269/asherbhs/nu/ch-2.nu b/challenge-269/asherbhs/nu/ch-2.nu
new file mode 100644
index 0000000000..5babaf4244
--- /dev/null
+++ b/challenge-269/asherbhs/nu/ch-2.nu
@@ -0,0 +1,16 @@
+def distribute-elements [ints: list<int>] -> list<int> {
+ mut arr1 = [$ints.0]
+ mut arr2 = [$ints.1]
+ for n in ($ints | skip 2) {
+ if ($arr1 | last) > ($arr2 | last) {
+ $arr1 ++= $n
+ } else {
+ $arr2 ++= $n
+ }
+ }
+ $arr1 ++ $arr2
+}
+
+print (distribute-elements [2 1 3 4 5])
+print (distribute-elements [3 2 4])
+print (distribute-elements [5 4 3 8])
diff --git a/challenge-269/asherbhs/raku/ch-2.raku b/challenge-269/asherbhs/raku/ch-2.raku
index 60cd8401f7..05acbb0884 100644
--- a/challenge-269/asherbhs/raku/ch-2.raku
+++ b/challenge-269/asherbhs/raku/ch-2.raku
@@ -1,7 +1,14 @@
-sub distribute-elements(Int:D @ints) {
+sub distribute-elements(Int:D @ints --> Array:D[Int:D]) {
my @arr1 = @ints[0];
my @arr2 = @ints[1];
-
+ for @ints.tail(* - 2) -> $n {
+ if @arr1[* - 1] > @arr2[* - 1] {
+ @arr1.push($n)
+ } else {
+ @arr2.push($n)
+ }
+ }
+ (|@arr1, |@arr2).Array
}
say distribute-elements Array[Int:D].new: 2, 1, 3, 4, 5;