From 1b69aed5e9e0b500356b40efc235da8ec88d7847 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sun, 10 May 2020 14:23:06 +0200 Subject: [PATCH] Solve problem 4 task 1 --- Contest2020/Contest2020.dyalog | 10 +++++++++- Contest2020/Data/rosalind_revp_2_output.txt | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Contest2020/Contest2020.dyalog b/Contest2020/Contest2020.dyalog index f8b0a23..8a34f02 100644 --- a/Contest2020/Contest2020.dyalog +++ b/Contest2020/Contest2020.dyalog @@ -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←subarrays⍴dna + ⍝ Filter subarrays which are reverse palindromes. + r←↑({isrevp dna[¯1+⍵[1]+⍳⍵[2]]}¨positions)/positions ∇ ∇ r←sset n diff --git a/Contest2020/Data/rosalind_revp_2_output.txt b/Contest2020/Data/rosalind_revp_2_output.txt index 9a0a469..191bad7 100644 --- a/Contest2020/Data/rosalind_revp_2_output.txt +++ b/Contest2020/Data/rosalind_revp_2_output.txt @@ -1,4 +1,4 @@ -1 4 + 1 4 2 4 3 4 16 4 @@ -86,4 +86,4 @@ 423 10 445 10 422 12 -444 12 \ No newline at end of file +444 12