Find first missing positive: Difference between revisions
→Using filtering and sorting: fixed bug
(→{{header|Quackery}}: Added second method.) |
(→Using filtering and sorting: fixed bug) |
||
Line 942:
===Using filtering and sorting===
<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.
[ dup 0 > iff
join
else drop ]
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>
{{out}}
|