Given the integers p, q and n I would like to generate a vector of length n with the elements
(⌊p ÷ q) (⌊(⌊p ÷ q) ÷ q) ...
In other words I want to construct a vector where the i:th element is {⌊⍵ ÷ q} applied i times on p. How can I do that in APL?
This short solution works using scan \ works in all APLs that support even basic dfns (inline lambdas):
1↓{⌊⍵÷q}\(1+n)⍴p
Try it online!
Note its inefficiency; it recalculates from the beginning for every term.
A more involved solution avoids recalculation by using / to iterate:
r←,p
{r,←⌊(¯1↑r)÷q}/(1+n)⍴1
1↓r
Try it online!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With