From a57b4eb0934da5439d1a7a757244c932d8c0f564 Mon Sep 17 00:00:00 2001 From: Asher Harvey-Smith Date: Fri, 17 Oct 2025 13:15:58 +0100 Subject: challenge 343 --- challenge-343/asherbhs/apl/ch-1.apl | 7 +++++++ challenge-343/asherbhs/apl/ch-2.apl | 31 +++++++++++++++++++++++++++++++ challenge-343/asherbhs/hy/ch-1.hy | 7 +++++++ challenge-343/asherbhs/raku/ch-1.raku | 9 +++++++++ 4 files changed, 54 insertions(+) create mode 100644 challenge-343/asherbhs/apl/ch-1.apl create mode 100644 challenge-343/asherbhs/apl/ch-2.apl create mode 100644 challenge-343/asherbhs/hy/ch-1.hy create mode 100644 challenge-343/asherbhs/raku/ch-1.raku 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..985d3e54a3 --- /dev/null +++ b/challenge-343/asherbhs/hy/ch-1.hy @@ -0,0 +1,7 @@ +(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; -- cgit From a6e254d5397b0b177cc94bd16d9a79b3ffa6484a Mon Sep 17 00:00:00 2001 From: Asher Harvey-Smith Date: Fri, 17 Oct 2025 13:17:42 +0100 Subject: formatting tweak --- challenge-343/asherbhs/hy/ch-1.hy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/challenge-343/asherbhs/hy/ch-1.hy b/challenge-343/asherbhs/hy/ch-1.hy index 985d3e54a3..7571b87991 100644 --- a/challenge-343/asherbhs/hy/ch-1.hy +++ b/challenge-343/asherbhs/hy/ch-1.hy @@ -1,4 +1,6 @@ -(defn zero-friend [nums] (min (map abs nums))) +(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])) -- cgit