In APL, how can I compute the lowest unused positive integer from a given set of integers?

StackOverflow https://stackoverflow.com/questions/1394749

  •  21-09-2019
  •  | 
  •  

Question

For example, given 1 8 4 9 0 2 , return 3. Thanks.

Was it helpful?

Solution

  {⍬⍴(⍳1+⍴⍵)~⍵} 1 8 4 9 0 2

3

OTHER TIPS

The case where they are all used seems to have "one plus the largest" as the answer, but whether that is "from" the list is another question.

@Paul, are you using APL385 as your browser's font? That seems to have cleared up many things from this end.

Try

((⍳⍴n)∊n)⍳0

or

((iota rho n) element n) iota 0

This is more or less the standard idiom for choosing the next available file tie number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top