Find first missing positive: Difference between revisions

Content added Content deleted
(Find first missing positive en True BASIC)
(Add CLU)
Line 372: Line 372:
{{out}}
{{out}}
<pre>⟨ 3 2 1 ⟩</pre>
<pre>⟨ 3 2 1 ⟩</pre>

=={{header|CLU}}==
<lang clu>contains = proc [T, U: type] (needle: T, haystack: U) returns (bool)
where T has equal: proctype (T,T) returns (bool),
U has elements: itertype (U) yields (T)
for item: T in U$elements(haystack) do
if item = needle then return(true) end
end
return(false)
end contains

fmp = proc [T: type] (list: T) returns (int)
where T has elements: itertype (T) yields (int)
n: int := 1
while contains[int, T](n, list) do
n := n + 1
end
return(n)
end fmp

start_up = proc ()
si = sequence[int]
ssi = sequence[si]
po: stream := stream$primary_output()
tests: ssi := ssi$[si$[1,2,0], si$[3,4,-1,1], si$[7,8,9,11,12]]
for test: si in ssi$elements(tests) do
for i: int in si$elements(test) do
stream$puts(po, int$unparse(i) || " ")
end
stream$putl(po, "==> " || int$unparse(fmp[si](test)))
end
end start_up</lang>
{{out}}
<pre>1 2 0 ==> 3
3 4 -1 1 ==> 2
7 8 9 11 12 ==> 1</pre>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==