Find first missing positive: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(→{{header|Quackery}}: added method.) |
||
Line 969: | Line 969: | ||
witheach [ task echo sp ] |
witheach [ task echo sp ] |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
|||
<pre>3 2 1</pre> |
|||
===Brute force=== |
|||
Search for each integer. The largest the missing integer can be is one more than the number of items in the nest. |
|||
<syntaxhighlight lang="Quackery"> [ dup size |
|||
dup 1+ unrot |
|||
times |
|||
[ i^ 1+ |
|||
over find |
|||
over found not if |
|||
[ dip |
|||
[ drop i^ 1+ ] |
|||
conclude ] ] |
|||
drop ] is task ( [ --> n ) |
|||
' [ [ 1 2 0 ] [ 3 4 -1 1 ] [ 7 8 9 11 12 ] ] |
|||
witheach [ task echo sp ]</syntaxhighlight> |
|||
{{out}} |
{{out}} |