aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRikedyP <rikedyp@gmail.com>2025-09-16 13:34:09 +0100
committerRikedyP <rikedyp@gmail.com>2025-09-16 13:34:09 +0100
commit59e694307f1cc13b2a240ce1e7d1e0911bb6e4de (patch)
tree3465d62b700d32c28077267505a7bf2ae01a9010
parent852e74279647336176a8649b1aaed55b54861342 (diff)
downloadperlweeklychallenge-club-59e694307f1cc13b2a240ce1e7d1e0911bb6e4de.tar.gz
perlweeklychallenge-club-59e694307f1cc13b2a240ce1e7d1e0911bb6e4de.tar.bz2
perlweeklychallenge-club-59e694307f1cc13b2a240ce1e7d1e0911bb6e4de.zip
brute force vs generated
-rw-r--r--challenge-339/richard-park/apl/MaxDiff.aplf11
1 files changed, 5 insertions, 6 deletions
diff --git a/challenge-339/richard-park/apl/MaxDiff.aplf b/challenge-339/richard-park/apl/MaxDiff.aplf
index 5c6d8e35c4..60e7e4e56e 100644
--- a/challenge-339/richard-park/apl/MaxDiff.aplf
+++ b/challenge-339/richard-park/apl/MaxDiff.aplf
@@ -1,21 +1,20 @@
MaxDiff←{
_←'cmat' 'pmat'⎕CY'dfns'
- MD←{
+ MD1←{
{⌈/-/×/(≢⍵)2 2⍴⍵},[1 2](⍵[4 cmat≢⍵]){⍺[⍵]}⍤1 99⊢pmat 4
+ }
+
+ MD2←{
⌈/-/×/⍵[c⌷⍨⊂↑⍸(⊢≡∪)∘∊¨∘.(,⍥⊂)⍨↓c←2 cmat≢⍵]
}
Pairs←{↑⊃,/i,¨¨(i←¯1↓⍳⍵)↓¨⊂⍳⍵}
MD←{
p←Pairs≢⍵ ⋄ rm←Pairs ¯2+≢⍵
- ⌈/,-/×/p,[0.5]⍤1⍤1 2⊢rm⌷⍤0 1⍤2 1↑(⍳≢n)~⍤1⊢p
-
- ⌈/-/×/⍵⌷⍨⊂↑⍣≡⊃,/p{⍺∘(,⍥⊂)¨⍵}¨(Pairs ¯2+≢⍵)∘{⍵∘{⍺[⍵]}¨⍺}¨(⍳5)∘~¨p←Pairs≢⍵
+ ⌈/,-/×/⍵⌷⍨⊂p,[0.5]⍤1⍤1 2⊢rm⌷⍤0 1⍤2 1⊢(⍳≢n)~⍤1⊢p
}
- u←∪{{(⊂⍋⍵)⌷⍵}⍤1{(≢⍵)2 2⍴⍵},[1 2](⍵[4 cmat≢⍵]){⍺[⍵]}⍤1 99⊢pmat 4}n
-
⍝ Tests
42≢MD 5 9 3 4 6:∘∘∘
10≢MD 1 ¯2 3 ¯4:∘∘∘