diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-22 12:04:12 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-22 12:04:12 +0100 |
| commit | dc249b163b0a950e64ef5788502b92b7024461a0 (patch) | |
| tree | 39a157ec4babb5221352cfb008f2934237e69700 | |
| parent | ae8dcfbd3166ee486ab68fe22ddf9f32eccc9fba (diff) | |
| download | perlweeklychallenge-club-dc249b163b0a950e64ef5788502b92b7024461a0.tar.gz perlweeklychallenge-club-dc249b163b0a950e64ef5788502b92b7024461a0.tar.bz2 perlweeklychallenge-club-dc249b163b0a950e64ef5788502b92b7024461a0.zip | |
- Added APL solutions by Richard Park.
| -rw-r--r-- | challenge-126/richard-park/apl/ch-1.aplf | 19 | ||||
| -rw-r--r-- | challenge-126/richard-park/apl/ch-2.aplf | 11 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-126/richard-park/apl/ch-1.aplf b/challenge-126/richard-park/apl/ch-1.aplf new file mode 100644 index 0000000000..fbb3ac764b --- /dev/null +++ b/challenge-126/richard-park/apl/ch-1.aplf @@ -0,0 +1,19 @@ + CountNumbers←{ + (⎕IO ⎕ML)←1 + 10>⍵:⍵-1 ⍝ Less than 10, n-1 + m←10*⌊10⍟⍵ ⍝ Magnitude (m) + k←⌊⍵÷m ⋄ r←¯1+k ⍝ Most significant digit (k) // Recursion factor (r) + 2>k:∇ ¯1+m ⍝ No new numbers start with 1, e.g. (1000 to 1999) + (∇ 1⌈m|⍵)+r+r×∇ ¯1+m ⍝ Recurse (∇) lesser significant digits and lower magnitudes + +⍝ A brute force version: +⍝ Converts integers up to ⍵ into character vectors and removes those that contain '1' +⍝ CountNumbersBrute ← {+/~'1'∘∊¨⍕¨⍳⍵} + +⍝ Memoisation: +⍝ Performance can be significantly improved with dfns.memo +⍝ 'memo'⎕CY'dfns' +⍝ 'cache'⎕NS⍬ +⍝ cache.(keys vals)←⍬⍬ +⍝ CountNumbersMemo ← CountNumbers memo cache + } diff --git a/challenge-126/richard-park/apl/ch-2.aplf b/challenge-126/richard-park/apl/ch-2.aplf new file mode 100644 index 0000000000..deafded6b2 --- /dev/null +++ b/challenge-126/richard-park/apl/ch-2.aplf @@ -0,0 +1,11 @@ + Minesweeper←{ + (⎕IO ⎕ML)←1 +⍝ Example input: 5 10⍴'× × ×××× × × × × ×× × × ×' + CellCount←{ + ⍝ A cell is a 3 by 3 area + c←'×'=,⍵ ⍝ 1 is a mine, 0 is not + 5⊃c:'×' ⍝ Middle is a mine? + +/c ⍝ Else count mines in cell + } + CellCount⌺3 3⊢⍵ + } |
