apl - APL中的重复函数应用

标签 apl

给定整数 pqn 我想生成一个长度为 n 的向量元素

(⌊p ÷ q) (⌊(⌊p ÷ q) ÷ q) ...

换句话说,我想构建一个向量,其中 i:th 元素被 {⌊⍵ ÷ q} 应用 ip。我如何在 APL 中做到这一点?

最佳答案

这个简短的解决方案使用扫描 \ 可以在所有支持基本 dfns(内联 lambda)的 APL 中使用:

1↓{⌊⍵÷q}\(1+n)⍴p

Try it online!

注意它的低效率;它会为每个学期从头开始重新计算。

一个更复杂的解决方案通过使用/来迭代来避免重新计算:

r←,p
{r,←⌊(¯1↑r)÷q}/(1+n)⍴1
1↓r

Try it online!

关于apl - APL中的重复函数应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58362528/

相关文章:

filtering - J : indexing from one into another 中的数组

split - 如何在 APL 中将数字拆分为数字

function - GNU APL 中的大括号

scripting - 在 APL 中声明多行函数的问题

matrix - APL:矩阵操作技巧?

APL 从数组中删除元素

apl - 如何提高 Dyalog APL 中的变量精度?

decode - 为什么 APL 的 ⊥ 解码需要基向量中的额外数字?

apl - Dyalog APL - 从 .txt 文件读取

fibonacci - 在 APL 中生成没有循环或流量控制的斐波那契数列