Do ... While (^:) 中的动态动词条件

Dynamic verb condition in a Do... While (^:)

我在解决 this problem 时想到了这个问题。

NB. Find the next number whose prime factorization exponents
NB. match those of the given number.

exps=. /:~@{:@(__&q:)
f=. 3 : 0
  target=. exps y
  (>:^:(-.@(target-:exps))^:_) y+1
)

f 20 NB. 28

请注意,为了指定 Do...While 的 while 条件,我首先计算了参数 y 的素数指数并将该答案保存到 target。然后我可以写 -.@(target-:exps) 作为 While 条件。

这当然打破了默契的风格。所以我想知道是否有一种方法可以实现我上面的动词所达到的相同效果,但作为一个默认动词来实现?

我处理这个问题的方法是将 f 视为二元叉的中心,其中左侧参数是 exps y,这是不变的比较 target 和右侧参数是 >: y 进行初始递增。下一步是在 f 中的每个 ^: 处使用 ] 来保持 exps 单子。 [ 从左侧参数中拉入 exps y

写的默契

   exps=. /:~@{:@(__&q:)
   ft=: exps >:@]^:([ -.@-: exps@])^:_ >: 
   ft 20
28