Jonah
Jonah

Reputation: 16242

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

This question occurred to my while solving 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

Note that in order to specify the while condition of the Do... While, I first had calculate the prime exponents of the argument y and save that answer to target. I was then able to write -.@(target-:exps) as the While condition.

This of course breaks the tacit style. So I'd like to know if there is a way to achieve the same thing that my verb above achieves, but do so as a single tacit verb?

Upvotes: 2

Views: 64

Answers (1)

bob
bob

Reputation: 4302

The way I approached this was to think of f as the centre of a dyadic fork where the left argument is exps y which is the unchanging comparison target and the right argument is >: y which does the initial incrementing. The next step was to use ] at each ^: in f to keep exps monadic. The [ pulls in exps y from the left argument.

Written in tacit

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

Upvotes: 2

Related Questions