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
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책

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

3

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top