Improve solution to problem 5 task 1

This commit is contained in:
Dimitri Lozeve 2020-05-10 19:52:11 +02:00
parent 9f3faba1e0
commit fb28ee869f

View file

@ -58,14 +58,13 @@
⍝ Put your code and comments below here
sset←{((1E6|2∘×)⍣⍵)1}
∇ r←amounts rr rates
⍝ 2020 APL Problem Solving Competition Phase II
⍝ Stub function for Problem 5, Task 1 - rr
⍝ Put your code and comments below here
⍝ ((1+⊢)⊥⊣) computes the total return for a vector
⍝ of amounts and a vector of rates ⍵.
r←((↑∘amounts)((1+⊢)⊥⊣)(↑∘rates))¨rates
⍝ 2020 APL Problem Solving Competition Phase II
⍝ Problem 5, Task 1 - rr
⍝ ((1+⊢)⊥⊣) computes the total return for a vector of
⍝ amounts and a vector of rates ⍵. It is applied to
⍝ every prefix subarray of amounts and rates to get
⍝ all intermediate values. Quadratic complexity.
rr←(,\⊣)((1+⊢)⊥⊣)¨(,\⊢)
∇ r←amounts rr2 rates;recur
⍝ Second solution