Solve problem 4 task 1

This commit is contained in:
Dimitri Lozeve 2020-05-10 14:23:06 +02:00
parent d5d2bbb2cc
commit 1b69aed5e9
2 changed files with 11 additions and 3 deletions

View file

@ -39,10 +39,18 @@
urls←('https://www.dyalog.com/'∘,)¨paths
∇ r←revp dna
⍝ Test if a DNA string is a reverse palindrome.
isrevp←{⍵≡⌽'TAGC'['ATCG'⍳⍵]}
⍝ Generate all subarrays (position, length) pairs, for
⍝ 4 ≤ length ≤ 12.
subarrays←{⊃,/(⍳⍵),¨¨3↓¨¨12⌊1+⍵-⍳⍵}
∇ r←revp dna;positions
⍝ 2020 APL Problem Solving Competition Phase II
⍝ Stub function for Problem 4, Task 1 - revp
⍝ Put your code and comments below here
positions←subarraysdna
⍝ Filter subarrays which are reverse palindromes.
r←↑({isrevp dna[¯1+⍵[1]+⍳⍵[2]]}¨positions)/positions
∇ r←sset n

View file

@ -1,4 +1,4 @@
1 4
1 4
2 4
3 4
16 4