Find first missing positive: Difference between revisions

Content deleted Content added
Line 951: Line 951:
<code>uniquewith</code> is defined at [[Remove duplicate elements#Quackery]] and conveniently sorts the nest.
<code>uniquewith</code> is defined at [[Remove duplicate elements#Quackery]] and conveniently sorts the nest.


Then hunt for the first item which does not have the same value as its index.
Then hunt for the first item which does not have the same value as its index. If they all have the same values as their indices, the missing integer is the same as the size of the processed nest.


<syntaxhighlight lang="Quackery"> [ dup size 1+ [] rot
<syntaxhighlight lang="Quackery"> [ [] swap
witheach
witheach
[ dup 0 > iff
[ dup 0 > iff
Line 960: Line 960:
0 join
0 join
uniquewith >
uniquewith >
dup size swap
witheach
witheach
[ i^ != if
[ i^ != if
[ drop i^
[ drop i^
conclude ] ] ] is task ( [ -> n )
conclude ] ] ] is task ( [ --> n )


' [ [ 1 2 0 ] [ 3 4 -1 1 ] [ 7 8 9 11 12 ] ]
' [ [ 1 2 0 ] [ 3 4 -1 1 ] [ 7 8 9 11 12 ] ]


witheach [ task echo sp ]
witheach [ task echo sp ]</syntaxhighlight>
</syntaxhighlight>


{{out}}
{{out}}