aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-262/asherbhs/apl/ch-1.apl5
-rw-r--r--challenge-262/asherbhs/apl/ch-2.apl6
-rw-r--r--challenge-262/asherbhs/bqn/ch-1.bqn5
-rw-r--r--challenge-262/asherbhs/bqn/ch-2.bqn4
-rw-r--r--challenge-262/asherbhs/haskell/ch-1.hs21
-rw-r--r--challenge-262/asherbhs/haskell/ch-2.hs18
-rw-r--r--challenge-262/asherbhs/j/ch-1.ijs7
-rw-r--r--challenge-262/asherbhs/j/ch-2.ijs6
-rw-r--r--challenge-262/asherbhs/raku/ch-1.raku13
-rw-r--r--challenge-262/asherbhs/raku/ch-2.raku12
10 files changed, 97 insertions, 0 deletions
diff --git a/challenge-262/asherbhs/apl/ch-1.apl b/challenge-262/asherbhs/apl/ch-1.apl
new file mode 100644
index 0000000000..63974de53f
--- /dev/null
+++ b/challenge-262/asherbhs/apl/ch-1.apl
@@ -0,0 +1,5 @@
+MaxPositiveNegative←{⌈/+/1 ¯1∘.=×⍵}
+
+⎕←MaxPositiveNegative ¯3 1 2 ¯1 3 ¯2 4
+⎕←MaxPositiveNegative ¯1 ¯2 ¯3 1
+⎕←MaxPositiveNegative 1 2
diff --git a/challenge-262/asherbhs/apl/ch-2.apl b/challenge-262/asherbhs/apl/ch-2.apl
new file mode 100644
index 0000000000..b17cd9bee1
--- /dev/null
+++ b/challenge-262/asherbhs/apl/ch-2.apl
@@ -0,0 +1,6 @@
+⎕IO←0
+
+CountEqualDivisible←{+/,(∘.=⍨⍵)∧(∘.(0=⍺|×)∧∘.<)⍨⍳≢⍵}
+
+⎕←2 CountEqualDivisible 3 1 2 2 2 1 3
+⎕←1 CountEqualDivisible 1 2 3
diff --git a/challenge-262/asherbhs/bqn/ch-1.bqn b/challenge-262/asherbhs/bqn/ch-1.bqn
new file mode 100644
index 0000000000..ab21b4a503
--- /dev/null
+++ b/challenge-262/asherbhs/bqn/ch-1.bqn
@@ -0,0 +1,5 @@
+MaxPositiveNegative←{⌈´+´˘1‿¯1=⌜×𝕩}
+
+•Show MaxPositiveNegative ¯3‿1‿2‿¯1‿3‿¯2‿4
+•Show MaxPositiveNegative ¯1‿¯2‿¯3‿1
+•Show MaxPositiveNegative 1‿2
diff --git a/challenge-262/asherbhs/bqn/ch-2.bqn b/challenge-262/asherbhs/bqn/ch-2.bqn
new file mode 100644
index 0000000000..9e132b8160
--- /dev/null
+++ b/challenge-262/asherbhs/bqn/ch-2.bqn
@@ -0,0 +1,4 @@
+CountEqualDivisible←{+´⥊(=⌜˜𝕩)∧((0=𝕨|×)⌜∧<⌜)˜↕≠𝕩}
+
+•Show 2 CountEqualDivisible 3‿1‿2‿2‿2‿1‿3
+•Show 1 CountEqualDivisible 1‿2‿3
diff --git a/challenge-262/asherbhs/haskell/ch-1.hs b/challenge-262/asherbhs/haskell/ch-1.hs
new file mode 100644
index 0000000000..54ef77e16c
--- /dev/null
+++ b/challenge-262/asherbhs/haskell/ch-1.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE MultiWayIf #-}
+
+maxPositiveNegative :: [Int] -> Int
+maxPositiveNegative ints =
+ let
+ (pos, neg) = foldr
+ (\n (pos, neg) -> if
+ | n > 0 -> (pos + 1, neg )
+ | n < 0 -> (pos, neg + 1)
+ | otherwise -> (pos, neg )
+ )
+ (0, 0)
+ ints
+ in
+ max pos neg
+
+main :: IO ()
+main = do
+ print $ maxPositiveNegative [-3, 1, 2, -1, 3, -2, 4]
+ print $ maxPositiveNegative [-1, -2, -3, 1]
+ print $ maxPositiveNegative [1, 2]
diff --git a/challenge-262/asherbhs/haskell/ch-2.hs b/challenge-262/asherbhs/haskell/ch-2.hs
new file mode 100644
index 0000000000..c4c37ee179
--- /dev/null
+++ b/challenge-262/asherbhs/haskell/ch-2.hs
@@ -0,0 +1,18 @@
+countEqualDivisible :: [Int] -> Int -> Int
+countEqualDivisible ints k =
+ let
+ help :: [(Int, Int)] -> Int
+ help [] = 0
+ help ((x, i) : rest)
+ = help rest
+ + (length $ filter
+ (\(y, j) -> x == y && (i `mod` k == 0 || j `mod` k == 0))
+ rest
+ )
+ in
+ help $ zip ints [0 ..]
+
+main :: IO ()
+main = do
+ print $ countEqualDivisible [3, 1, 2, 2, 2, 1, 3] 2
+ print $ countEqualDivisible [1, 2, 3] 1
diff --git a/challenge-262/asherbhs/j/ch-1.ijs b/challenge-262/asherbhs/j/ch-1.ijs
new file mode 100644
index 0000000000..ce70b24a6e
--- /dev/null
+++ b/challenge-262/asherbhs/j/ch-1.ijs
@@ -0,0 +1,7 @@
+MaxPositiveNegative=.{{>./+/"1]1 _1=/*y}}
+
+echo MaxPositiveNegative _3 1 2 _1 3 _2 4
+echo MaxPositiveNegative _1 _2 _3 1
+echo MaxPositiveNegative 1 2
+
+exit''
diff --git a/challenge-262/asherbhs/j/ch-2.ijs b/challenge-262/asherbhs/j/ch-2.ijs
new file mode 100644
index 0000000000..9823b9a118
--- /dev/null
+++ b/challenge-262/asherbhs/j/ch-2.ijs
@@ -0,0 +1,6 @@
+CountEqualDivisible=.{{+/,(=/~y)*.((0=x|*)"0 1*.</)~i.#y}}
+
+echo 2 CountEqualDivisible 3 1 2 2 2 1 3
+echo 1 CountEqualDivisible 1 2 3
+
+exit ''
diff --git a/challenge-262/asherbhs/raku/ch-1.raku b/challenge-262/asherbhs/raku/ch-1.raku
new file mode 100644
index 0000000000..445d684a92
--- /dev/null
+++ b/challenge-262/asherbhs/raku/ch-1.raku
@@ -0,0 +1,13 @@
+sub max-positive-negative(Int:D @ints --> Int:D) {
+ my $pos = 0;
+ my $neg = 0;
+ for @ints {
+ $pos++ when $_ > 0;
+ $neg++ when $_ < 0;
+ }
+ return max $pos, $neg
+}
+
+say max-positive-negative Array[Int].new: -3, 1, 2, -1, 3, -2, 4;
+say max-positive-negative Array[Int].new: -1, -2, -3, 1;
+say max-positive-negative Array[Int].new: 1, 2;
diff --git a/challenge-262/asherbhs/raku/ch-2.raku b/challenge-262/asherbhs/raku/ch-2.raku
new file mode 100644
index 0000000000..2edea29706
--- /dev/null
+++ b/challenge-262/asherbhs/raku/ch-2.raku
@@ -0,0 +1,12 @@
+sub count-equal-divisible(Int:D @ints, Int:D $k --> Int:D) {
+ my $n = 0;
+ for 0 ..^ @ints -> $i {
+ for $i + 1 ..^ @ints -> $j {
+ $n++ if @ints[$i] == @ints[$j] && ($i mod $k == 0 || $j mod $k == 0)
+ }
+ }
+ return $n
+}
+
+say count-equal-divisible Array[Int].new(3, 1, 2, 2, 2, 1, 3), 2;
+say count-equal-divisible Array[Int].new(1, 2, 3), 1;