From 0097080190d525a53036d12bc6783f4a6db2ec5c Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Tue, 19 May 2020 16:32:29 +0200 Subject: [PATCH] Improve problem 2 solution --- Contest2020/Contest2020.dyalog | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Contest2020/Contest2020.dyalog b/Contest2020/Contest2020.dyalog index 5d83ae6..eac66d4 100644 --- a/Contest2020/Contest2020.dyalog +++ b/Contest2020/Contest2020.dyalog @@ -23,18 +23,21 @@ score←2(⍎⍕)dd×+/scores ∇ - ∇ steps←{p}Steps fromTo + ∇ steps←{p}Steps fromTo;segments;width ⍝ 2020 APL Problem Solving Competition Phase II ⍝ Problem 2, Task 1 - Steps + width←|-/fromTo :If 0=⎕NC'p' ⍝ No left argument: same as Problem 5 of Phase I - steps←{(⊃⍵)+(-×-/⍵)×0,⍳|-/⍵}fromTo - :ElseIf p<0 - steps←(-⌊p){(⊃⍵)+(-×-/⍵)×0,(⍳⍺)×|-/⍵÷⍺}fromTo - :ElseIf p>0 - steps←p{(⊃⍵)+(-×-/⍵)×(|-/⍵)⌊⍺×0,⍳⌈(|-/⍵)÷⍺}fromTo - :ElseIf p=0 - steps←⊃fromTo + segments←0,⍳width + :ElseIf p<0 ⍝ -⌊p is the number of equally-sized steps to take + segments←(-⌊p){0,⍵×⍺÷⍨⍳⍺}width + :ElseIf p>0 ⍝ p is the step size + segments←p{⍵⌊⍺×0,⍳⌈⍵÷⍺}width + :ElseIf p=0 ⍝ As if we took zero step + segments←0 :EndIf + ⍝ Take into account the start point and the direction. + steps←fromTo{(⊃⍺)+(-×-/⍺)×⍵}segments ∇ ∇ urls←PastTasks url;r;paths