aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-07-18 13:29:26 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-07-18 13:29:26 +0100
commitf5b7210dc9204bef43e19a501844436b41636a59 (patch)
treef6a0ddf98368d6112a6c675bb4e2f040fad81bc6
parentf2bb0a63740147a21e02d78147d4fdbba2ad1070 (diff)
downloadperlweeklychallenge-club-f5b7210dc9204bef43e19a501844436b41636a59.tar.gz
perlweeklychallenge-club-f5b7210dc9204bef43e19a501844436b41636a59.tar.bz2
perlweeklychallenge-club-f5b7210dc9204bef43e19a501844436b41636a59.zip
- Added APL solutions by Richard Park.
-rw-r--r--challenge-121/richard-park/apl/ch-1.aplf3
-rw-r--r--challenge-121/richard-park/apl/ch-2.aplf12
2 files changed, 15 insertions, 0 deletions
diff --git a/challenge-121/richard-park/apl/ch-1.aplf b/challenge-121/richard-park/apl/ch-1.aplf
new file mode 100644
index 0000000000..24903b4709
--- /dev/null
+++ b/challenge-121/richard-park/apl/ch-1.aplf
@@ -0,0 +1,3 @@
+ InvertBit←{
+ 2⊥~@(⍵-⍨1+≢b)⊢b←2⊥⍣¯1⊢⍺
+ } \ No newline at end of file
diff --git a/challenge-121/richard-park/apl/ch-2.aplf b/challenge-121/richard-park/apl/ch-2.aplf
new file mode 100644
index 0000000000..daa5bd1c5e
--- /dev/null
+++ b/challenge-121/richard-park/apl/ch-2.aplf
@@ -0,0 +1,12 @@
+ TravellingSalesman←{
+ ⎕IO←0
+⍝ Brute force travelling salesman
+⍝ For a better treatment of this problem in APL, see https://dl.acm.org/doi/10.1145/97811.97850
+⍝ ⍵: Matrix of path costs. ⍵[i;j] is cost from node i to j
+⍝ indices number costs
+⍝ permutations totals bitmask
+ 'dfns'⎕CY'pmat' ⍝ Permutation matrix
+ i←⍳n←≢c←⍵
+ b←(⊢∊⌊/)t←+/c[(¯1∘⌽,¨⊢)p←pmat n]
+ b∘⌿¨t,⍥⊂⍥⍪p
+ } \ No newline at end of file