aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-10-19 02:42:49 +0100
committerGitHub <noreply@github.com>2025-10-19 02:42:49 +0100
commit60f44cff092565ae53cc346fdff03d869d62c650 (patch)
tree96e0224f759f803082add779b5eca62702458843
parent9f63589dca339bd6b420df2f397aba971a9a4fb5 (diff)
parenta6e254d5397b0b177cc94bd16d9a79b3ffa6484a (diff)
downloadperlweeklychallenge-club-60f44cff092565ae53cc346fdff03d869d62c650.tar.gz
perlweeklychallenge-club-60f44cff092565ae53cc346fdff03d869d62c650.tar.bz2
perlweeklychallenge-club-60f44cff092565ae53cc346fdff03d869d62c650.zip
Merge pull request #12861 from asherbhs/challenge-343
Challenge 343
-rw-r--r--challenge-343/asherbhs/apl/ch-1.apl7
-rw-r--r--challenge-343/asherbhs/apl/ch-2.apl31
-rw-r--r--challenge-343/asherbhs/hy/ch-1.hy9
-rw-r--r--challenge-343/asherbhs/raku/ch-1.raku9
4 files changed, 56 insertions, 0 deletions
diff --git a/challenge-343/asherbhs/apl/ch-1.apl b/challenge-343/asherbhs/apl/ch-1.apl
new file mode 100644
index 0000000000..c89b1c05b4
--- /dev/null
+++ b/challenge-343/asherbhs/apl/ch-1.apl
@@ -0,0 +1,7 @@
+ZeroFriend←⌊/|
+
+⎕←ZeroFriend 4 2 ¯1 3 ¯2
+⎕←ZeroFriend ¯5 5 ¯3 3 ¯1 1
+⎕←ZeroFriend 7 ¯3 0 2 ¯8
+⎕←ZeroFriend ¯2 ¯5 ¯1 ¯8
+⎕←ZeroFriend ¯2 2 ¯4 4 ¯1 1
diff --git a/challenge-343/asherbhs/apl/ch-2.apl b/challenge-343/asherbhs/apl/ch-2.apl
new file mode 100644
index 0000000000..2507c522f9
--- /dev/null
+++ b/challenge-343/asherbhs/apl/ch-2.apl
@@ -0,0 +1,31 @@
+⎕IO←0
+
+ChampionTeam←{
+ grid←⍵
+
+ ⍝ get dag of just champions
+ champs←⍸(⊢=⌈/)+/grid
+ grid←grid[champs;champs]
+
+ ⍝ toposort
+ n←≢grid
+ sorted←⍬ ⍝ stores *reversed* toposort
+ visited←n⍴0
+ DFS←{
+ visited[⍵]: 1
+ visited[⍵]←1
+ _←DFS¨⍸grid[⍵;]
+ sorted,←⍵
+ 1
+ }
+ _←DFS¨⍳n
+
+ ⍝ take the strongest champion
+ champs[⊃⌽sorted]
+}
+
+⎕←ChampionTeam↑(0 1 1)(0 0 1)(0 0 0)
+⎕←ChampionTeam↑(0 1 0 0)(0 0 0 0)(1 1 0 0)(1 1 1 0)
+⎕←ChampionTeam↑(0 1 0 1)(0 0 1 1)(1 0 0 0)(0 0 1 0)
+⎕←ChampionTeam↑(0 1 1)(0 0 0)(0 1 0)
+⎕←ChampionTeam↑(0 0 0 0 0)(1 0 0 0 0)(1 1 0 1 1)(1 1 0 0 0)(1 1 0 1 0)
diff --git a/challenge-343/asherbhs/hy/ch-1.hy b/challenge-343/asherbhs/hy/ch-1.hy
new file mode 100644
index 0000000000..7571b87991
--- /dev/null
+++ b/challenge-343/asherbhs/hy/ch-1.hy
@@ -0,0 +1,9 @@
+(defn zero-friend [nums]
+ (min (map abs nums))
+)
+
+(print (zero-friend [4 2 -1 3 -2]))
+(print (zero-friend [-5 5 -3 3 -1 1]))
+(print (zero-friend [7 -3 0 2 -8]))
+(print (zero-friend [-2 -5 -1 -8]))
+(print (zero-friend [-2 2 -4 4 -1 1]))
diff --git a/challenge-343/asherbhs/raku/ch-1.raku b/challenge-343/asherbhs/raku/ch-1.raku
new file mode 100644
index 0000000000..2d97da57d0
--- /dev/null
+++ b/challenge-343/asherbhs/raku/ch-1.raku
@@ -0,0 +1,9 @@
+sub zero-friend (Int:D @nums) {
+ @nums».abs.min
+}
+
+say zero-friend Array[Int].new: 4, 2, -1, 3, -2;
+say zero-friend Array[Int].new: -5, 5, -3, 3, -1, 1;
+say zero-friend Array[Int].new: 7, -3, 0, 2, -8;
+say zero-friend Array[Int].new: -2, -5, -1, -8;
+say zero-friend Array[Int].new: -2, 2, -4, 4, -1, 1;