You get on the commandline a set of natural numbers (integers greater than or equal to zero). Find the smallest natural number not on the list, and print it to STDOUT followed by a newline. Nothing should appear on STDERR, the returncode does not matter. There will be 0 to 30 arguments, matching /^0\z|^[1-9]\d{0,5}\z/. The numbers can appear in any order and there can be duplicates.
example input:
3 7 13 15 0 1 0 4 21 5 13 13 13 9 10 12 8 6Some missing numbers in this sequence are 2, 11, 14 ... The smallest of these is 2, so the output should be:
2
Check your solution using the version 3 test program
The challenge runs under the generic perl golf rules.
Tell the length of your solutions (but not the solution itself) to ton- on ircnet #perl or mail the number to perl-golf@ton.iguana.be
The challenge finishes at 2002/08/18 23:00:00 UTC
34 ton,mtve,suo,s.turner 36 tybalt89,beowulf,m.wrenn 37 k.c.ivey,topmach,ya,banshee,e.a.zachs,terje,h.pazdziora,autrijus 38 s7l 39 kcwu 40 dkr,eugene 49 juuso 52 m.eloise,j.p.vidal,ufobat 55 r.champoux
ton 34 @a=0..30;@a[@ARGV]=();print<@a>.$/
mtve 34 $-+=$_==$-for(@ARGV)x30;print$-,$/
suo 34 @x=0..30;@x[@ARGV]=();print<@x>.$/
s.turner 34 -l $^C+=$_==$^Cfor(@ARGV)x30;print$^C
tybalt89 36 -l $-++while map/^$-$/,@ARGV;print$-
beowulf 36 -l $?++while map/^$?$/,@ARGV;print$?
m.wrenn 36 -l $?++while map/^$?$/,@ARGV;print$?
ton 36 -l $%++while grep!$_--,@ARGV;print$%
k.c.ivey 37 -l $%++while" @ARGV "=~/ $% /;print$%
TopMach 37 -l $%++while"@ARGV"=~/\b$%\b/;print$%
ya 37 -l ++$%while"@ARGV"=~/\b$%\b/;print$%
banshee 37 -l $%++while"@ARGV"=~/\b$%\b/;print$%
e.a.zachs 37 $%++until"@ARGV"!~/\b$%\b/;print$%,$/
terje 37 -l $%++while" @ARGV "=~/ $% /;print$%
h.pazdziora 37 -l $-++while grep$-==$_,@ARGV;print$-
autrijus 37 -l $?++while" @ARGV "=~/ $? /;print$?
s7l 38 $-++until" @ARGV "!~/ $- /&&print$-.$/
tybalt89 38 -l print"@{[@h{@a,@ARGV}=@a=0..30]}"*1
e.a.zachs 38 -l "@ARGV"=~/\b$%\b/?++$%&do$0:print$%
kcwu 39 (grep$%==$_,@ARGV)?++$%.do$0:print$%,$/
dkr 40 -l $_=0;$_++while" @ARGV "=~/ $_ /;print
terje 40 -l @a{@ARGV}=%::;++$%while$a{$%};print$%
e.a.zachs 42 -l print+(grep"@ARGV"!~/\b$_\b/,0..9x5)[0]
e.a.zachs 42 -l print+($_)=grep"@ARGV"!~/\b$_\b/,0..9x5
ton 43 -l print+(grep!$_--,@ARGV)&&1+`$^X $0 @ARGV`
banshee 43 -l @s[@ARGV]=(1)x30;$s[$_++]?do$0:print--$_
autrijus 45 -l map$.=~chr||print^exit,0..map$..=chr,@ARGV
ton 46 -l $_=1for@a[@ARGV];" @a "=~/ /;print$-[0]/2
kcwu 46 -l vec($a,$_,8)++for@ARGV;print index"$a^@","^@"
juuso 49 -l E:{for(@ARGV){$i==$_&&{$i++,redo E}}print$i|0}
m.eloise 52 -l for($i=0,$_=join' ',@ARGV;/\b$i\b/;$i++){}print$i
j.p.vidal 52 -l for$n(0..30){do{print$n;exit}if!grep/^$n$/,@ARGV}
tybalt89 57 -l $_=" @{[0..30]} @ARGV ";s/( .*)(?= .*\1 )//g;print$_+0
dkr 60 -l $n=-1;sub f{$n++;for(@_){$_==$n&&return&f}$n}print f@ARGV
Post-mortem:
ton 33 print<@{q[@b,@ARGV]=@b=0..30}>.$/
tybalt89 33 print<@{h{@a,@ARGV}=@a=0..30}>.$/