aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsher Harvey-Smith <asherharveysmith@gmail.com>2024-05-07 01:11:32 +0100
committerAsher Harvey-Smith <asherharveysmith@gmail.com>2024-05-07 01:11:32 +0100
commit7a348aca6231a5005c1e0c19de240d337f19d7ec (patch)
tree1520bf5843ae77cff7bab8e62e642e2c5ad7b7e0
parentc1756b0e7aed0ad70fa63feb2565c69215c9d426 (diff)
downloadperlweeklychallenge-club-7a348aca6231a5005c1e0c19de240d337f19d7ec.tar.gz
perlweeklychallenge-club-7a348aca6231a5005c1e0c19de240d337f19d7ec.tar.bz2
perlweeklychallenge-club-7a348aca6231a5005c1e0c19de240d337f19d7ec.zip
challenge 268
-rw-r--r--challenge-268/asherbhs/apl/ch-1.apl5
-rw-r--r--challenge-268/asherbhs/apl/ch-2.apl5
-rw-r--r--challenge-268/asherbhs/bqn/ch-1.bqn5
-rw-r--r--challenge-268/asherbhs/bqn/ch-2.bqn5
-rw-r--r--challenge-268/asherbhs/haskell/ch-1.hs8
-rw-r--r--challenge-268/asherbhs/haskell/ch-2.hs15
-rw-r--r--challenge-268/asherbhs/hy/ch-1.hy7
-rw-r--r--challenge-268/asherbhs/hy/ch-2.hy14
-rw-r--r--challenge-268/asherbhs/j/ch-1.ijs7
-rw-r--r--challenge-268/asherbhs/j/ch-2.ijs7
-rw-r--r--challenge-268/asherbhs/raku/ch-1.raku7
-rw-r--r--challenge-268/asherbhs/raku/ch-2.raku7
12 files changed, 92 insertions, 0 deletions
diff --git a/challenge-268/asherbhs/apl/ch-1.apl b/challenge-268/asherbhs/apl/ch-1.apl
new file mode 100644
index 0000000000..cf6cd71ee4
--- /dev/null
+++ b/challenge-268/asherbhs/apl/ch-1.apl
@@ -0,0 +1,5 @@
+MagicNumber←-⍨⍥(⌊/)
+
+⎕←3 7 5 MagicNumber 9 5 7
+⎕←1 2 1 MagicNumber 5 4 4
+⎕←2 MagicNumber 5
diff --git a/challenge-268/asherbhs/apl/ch-2.apl b/challenge-268/asherbhs/apl/ch-2.apl
new file mode 100644
index 0000000000..0826b24696
--- /dev/null
+++ b/challenge-268/asherbhs/apl/ch-2.apl
@@ -0,0 +1,5 @@
+NumberGame←,⍤⌽(⊂⍤⍋⌷⊢)⍴⍨2,⍨2÷⍨≢
+
+⎕←NumberGame 2 5 3 4
+⎕←NumberGame 9 4 1 3 6 4 6 1
+⎕←NumberGame 1 2 2 3
diff --git a/challenge-268/asherbhs/bqn/ch-1.bqn b/challenge-268/asherbhs/bqn/ch-1.bqn
new file mode 100644
index 0000000000..760c5a845a
--- /dev/null
+++ b/challenge-268/asherbhs/bqn/ch-1.bqn
@@ -0,0 +1,5 @@
+MagicNumber←-˜○(⌊´)
+
+•Show 3‿7‿5 MagicNumber 9‿5‿7
+•Show 1‿2‿1 MagicNumber 5‿4‿4
+•Show ⟨2⟩ MagicNumber ⟨5⟩
diff --git a/challenge-268/asherbhs/bqn/ch-2.bqn b/challenge-268/asherbhs/bqn/ch-2.bqn
new file mode 100644
index 0000000000..dc29b4c0be
--- /dev/null
+++ b/challenge-268/asherbhs/bqn/ch-2.bqn
@@ -0,0 +1,5 @@
+NumberGame←⥊·⌽˘∘‿2⥊∧
+
+•Show NumberGame 2‿5‿3‿4
+•Show NumberGame 9‿4‿1‿3‿6‿4‿6‿1
+•Show NumberGame 1‿2‿2‿3
diff --git a/challenge-268/asherbhs/haskell/ch-1.hs b/challenge-268/asherbhs/haskell/ch-1.hs
new file mode 100644
index 0000000000..e627573135
--- /dev/null
+++ b/challenge-268/asherbhs/haskell/ch-1.hs
@@ -0,0 +1,8 @@
+magicNumber :: [Int] -> [Int] -> Int
+magicNumber x y = minimum y - minimum x
+
+main :: IO ()
+main = do
+ print $ magicNumber [3, 7, 5] [9, 5, 7]
+ print $ magicNumber [1, 2, 1] [5, 4, 4]
+ print $ magicNumber [2] [5]
diff --git a/challenge-268/asherbhs/haskell/ch-2.hs b/challenge-268/asherbhs/haskell/ch-2.hs
new file mode 100644
index 0000000000..f6724f5cbc
--- /dev/null
+++ b/challenge-268/asherbhs/haskell/ch-2.hs
@@ -0,0 +1,15 @@
+import Data.List (sort)
+
+numberGame :: [Int] -> [Int]
+numberGame = flipAdjacent . sort
+ where
+ flipAdjacent :: [Int] -> [Int]
+ flipAdjacent [] = []
+ flipAdjacent (x : y : t) = y : x : flipAdjacent t
+
+main :: IO ()
+main = do
+ print $ numberGame [2, 5, 3, 4]
+ print $ numberGame [9, 4, 1, 3, 6, 4, 6, 1]
+ print $ numberGame [1, 2, 2, 3]
+
diff --git a/challenge-268/asherbhs/hy/ch-1.hy b/challenge-268/asherbhs/hy/ch-1.hy
new file mode 100644
index 0000000000..67a9aa6056
--- /dev/null
+++ b/challenge-268/asherbhs/hy/ch-1.hy
@@ -0,0 +1,7 @@
+(import hyrule *)
+
+(defn magic-number [x y] (- (min y) (min x)))
+
+(pprint (magic-number [3 7 5] [9 5 7]))
+(pprint (magic-number [1 2 1] [5 4 4]))
+(pprint (magic-number [2] [5]))
diff --git a/challenge-268/asherbhs/hy/ch-2.hy b/challenge-268/asherbhs/hy/ch-2.hy
new file mode 100644
index 0000000000..9bc23a468b
--- /dev/null
+++ b/challenge-268/asherbhs/hy/ch-2.hy
@@ -0,0 +1,14 @@
+(import
+ hyrule *
+ itertools *
+)
+
+(defn number-game [ints] (lfor
+ #(x y) (batched (sorted ints) 2)
+ z #(y x)
+ z
+))
+
+(print (number-game [2 5 3 4]))
+(print (number-game [9 4 1 3 6 4 6 1]))
+(print (number-game [1 2 2 3]))
diff --git a/challenge-268/asherbhs/j/ch-1.ijs b/challenge-268/asherbhs/j/ch-1.ijs
new file mode 100644
index 0000000000..0eb5606dc3
--- /dev/null
+++ b/challenge-268/asherbhs/j/ch-1.ijs
@@ -0,0 +1,7 @@
+MagicNumber=.-~&(<./)
+
+echo 3 7 5 MagicNumber 9 5 7
+echo 1 2 1 MagicNumber 5 4 4
+echo 2 MagicNumber 5
+
+exit ''
diff --git a/challenge-268/asherbhs/j/ch-2.ijs b/challenge-268/asherbhs/j/ch-2.ijs
new file mode 100644
index 0000000000..0da8626894
--- /dev/null
+++ b/challenge-268/asherbhs/j/ch-2.ijs
@@ -0,0 +1,7 @@
+NumberGame=.[:,[:|."1/:~$~2,~2%~#
+
+echo NumberGame 2 5 3 4
+echo NumberGame 9 4 1 3 6 4 6 1
+echo NumberGame 1 2 2 3
+
+exit ''
diff --git a/challenge-268/asherbhs/raku/ch-1.raku b/challenge-268/asherbhs/raku/ch-1.raku
new file mode 100644
index 0000000000..1a83b97bd3
--- /dev/null
+++ b/challenge-268/asherbhs/raku/ch-1.raku
@@ -0,0 +1,7 @@
+sub magic-number(Int:D @x, Int:D @y --> Int:D) {
+ @y.min - @x.min
+}
+
+say magic-number Array[Int:D].new(3, 7, 5), Array[Int:D].new(9, 5, 7);
+say magic-number Array[Int:D].new(1, 2, 1), Array[Int:D].new(5, 4, 4);
+say magic-number Array[Int:D].new(2), Array[Int:D].new(5);
diff --git a/challenge-268/asherbhs/raku/ch-2.raku b/challenge-268/asherbhs/raku/ch-2.raku
new file mode 100644
index 0000000000..bdefaff13c
--- /dev/null
+++ b/challenge-268/asherbhs/raku/ch-2.raku
@@ -0,0 +1,7 @@
+sub number-game(Int:D @ints --> Array:D[Int:D]) {
+ @ints.sort.map({ |($^b, $^a) }).Array
+}
+
+say number-game Array[Int:D].new: 2, 5, 3, 4;
+say number-game Array[Int:D].new: 9, 4, 1, 3, 6, 4, 6, 1;
+say number-game Array[Int:D].new: 1, 2, 2, 3;