Improve solution to problem 5 task 1
This commit is contained in:
parent
9f3faba1e0
commit
fb28ee869f
1 changed files with 7 additions and 8 deletions
|
@ -58,14 +58,13 @@
|
||||||
⍝ Put your code and comments below here
|
⍝ Put your code and comments below here
|
||||||
sset←{((1E6|2∘×)⍣⍵)1}
|
sset←{((1E6|2∘×)⍣⍵)1}
|
||||||
|
|
||||||
∇ r←amounts rr rates
|
|
||||||
⍝ 2020 APL Problem Solving Competition Phase II
|
⍝ 2020 APL Problem Solving Competition Phase II
|
||||||
⍝ Stub function for Problem 5, Task 1 - rr
|
⍝ Problem 5, Task 1 - rr
|
||||||
⍝ Put your code and comments below here
|
⍝ ((1+⊢)⊥⊣) computes the total return for a vector of
|
||||||
⍝ ((1+⊢)⊥⊣) computes the total return for a vector
|
⍝ amounts ⍺ and a vector of rates ⍵. It is applied to
|
||||||
⍝ of amounts ⍺ and a vector of rates ⍵.
|
⍝ every prefix subarray of amounts and rates to get
|
||||||
r←((↑∘amounts)((1+⊢)⊥⊣)(↑∘rates))¨⍳⍴rates
|
⍝ all intermediate values. Quadratic complexity.
|
||||||
∇
|
rr←(,\⊣)((1+⊢)⊥⊣)¨(,\⊢)
|
||||||
|
|
||||||
∇ r←amounts rr2 rates;recur
|
∇ r←amounts rr2 rates;recur
|
||||||
⍝ Second solution
|
⍝ Second solution
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue