Improve problem 2 solution
This commit is contained in:
parent
2807421031
commit
0097080190
1 changed files with 11 additions and 8 deletions
|
@ -23,18 +23,21 @@
|
||||||
score←2(⍎⍕)dd×+/scores
|
score←2(⍎⍕)dd×+/scores
|
||||||
∇
|
∇
|
||||||
|
|
||||||
∇ steps←{p}Steps fromTo
|
∇ steps←{p}Steps fromTo;segments;width
|
||||||
⍝ 2020 APL Problem Solving Competition Phase II
|
⍝ 2020 APL Problem Solving Competition Phase II
|
||||||
⍝ Problem 2, Task 1 - Steps
|
⍝ Problem 2, Task 1 - Steps
|
||||||
|
width←|-/fromTo
|
||||||
:If 0=⎕NC'p' ⍝ No left argument: same as Problem 5 of Phase I
|
:If 0=⎕NC'p' ⍝ No left argument: same as Problem 5 of Phase I
|
||||||
steps←{(⊃⍵)+(-×-/⍵)×0,⍳|-/⍵}fromTo
|
segments←0,⍳width
|
||||||
:ElseIf p<0
|
:ElseIf p<0 ⍝ -⌊p is the number of equally-sized steps to take
|
||||||
steps←(-⌊p){(⊃⍵)+(-×-/⍵)×0,(⍳⍺)×|-/⍵÷⍺}fromTo
|
segments←(-⌊p){0,⍵×⍺÷⍨⍳⍺}width
|
||||||
:ElseIf p>0
|
:ElseIf p>0 ⍝ p is the step size
|
||||||
steps←p{(⊃⍵)+(-×-/⍵)×(|-/⍵)⌊⍺×0,⍳⌈(|-/⍵)÷⍺}fromTo
|
segments←p{⍵⌊⍺×0,⍳⌈⍵÷⍺}width
|
||||||
:ElseIf p=0
|
:ElseIf p=0 ⍝ As if we took zero step
|
||||||
steps←⊃fromTo
|
segments←0
|
||||||
:EndIf
|
:EndIf
|
||||||
|
⍝ Take into account the start point and the direction.
|
||||||
|
steps←fromTo{(⊃⍺)+(-×-/⍺)×⍵}segments
|
||||||
∇
|
∇
|
||||||
|
|
||||||
∇ urls←PastTasks url;r;paths
|
∇ urls←PastTasks url;r;paths
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue