Find first missing positive: Difference between revisions

(→‎{{header|Quackery}}: Added second method.)
Line 942:
===Using filtering and sorting===
 
FilteringFilter out the non-positive integers, and sortingthen thenon-unique remainderelements (andafter adding zero).
 
<code>uniquewith</code> is defined at [[Remove duplicate elements#Quackery]] and conveniently sorts the nest.
<syntaxhighlight lang="Quackery"> [ dup size ' [ 0 ] rot
 
witheach
Then hunt for the first item which does not have the same value as its index.
 
<syntaxhighlight lang="Quackery"> [ dup size ' [ 0 ] rot
witheach
[ dup 0 > iff
join
else drop ]
sort0 join
uniquewith >
witheach
[ i^ != if
[ drop i^
conclude ] ] ] is task ( [ -> n )
 
' [ [ 1 2 0 ] [ 3 4 -1 1 ] [ 7 8 9 11 12 ] ]
 
witheach [ task echo sp ]</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
1,462

edits