You get on STDIN a sequence of integers, each representing the size of a stack of boxes. Each stack is lower than 10, but can not be empty, so the input lines match /^[1-9]\n\z/. Print on STDOUT how many there boxes are at each level starting from above, each number properly terminated with a \n. Nothing should be printed on STDERR. There will be between 1 and 1000 (inclusive) boxes.
example input:
5 3 1 3So the stacks look like:
+--+ | | <- 1 box +--+ +--+ | | <- 1 box +--+ +--+ +--+ +--+ | | | | | | <- 3 boxes +--+ +--+ +--+ +--+ +--+ +--+ | | | | | | <- 3 boxes +--+ +--+ +--+ +--+ +--+ +--+ +--+ | | | | | | | | <- 4 boxes +--+ +--+ +--+ +--+ 5 3 1 3Therefore the output should be:
1 1 3 3 4
Check your solution using the 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/06/30 23:00:00 UTC
35 ton,tybalt89 36 m.thelen,dave 37 p.haworth,q.huo,banshee,andys,[VI]Kille,juuso,d.hoover 38 suo 40 c.dolan,p.kailasa,terje 41 octo 42 j.krahn,a.qumsieh,beowulf 43 kci 45 p.carmody 46 darek 47 depesz 49 Sn0wSmyrf,osar 50 trstn 52 hispeed,sh 168 vc20
ton 35 -0p $\="$a\n".$\while$a=y/1-9/0-8/}{ ton 35 -0p $\=~s//$a\n/while$a=y/1-9/0-8/}{ tybalt89 35 -p $_=1+$_.$/for@;[9-$_..8]}{print@ m.thelen 36 -ln0 ($~+=s~$=~~g)&&print$~while--$= m.thelen 36 -ln0 $~+=s~$=~~gand print$~while--$= ton 36 -p $_=++$_.$/for@a[9-$_..8]}for(@a){ ton 36 -n $_=++$_.$/for@a[9-$_..8]}{print@a dave 36 -ln0 ($,+=s/$=//g)&&print$,while--$= p.haworth 37 -pl $_++for@s[1..$_]}while($_=pop@s){ q.huo 37 -lp $_++for@_[1..$_]}while($_=pop@_){ d.hoover 37 -pl ++$_[--$_]while$_}for(reverse@_){ [VI]Kille 37 -pl $_++for@_[1..$_]}while($_=pop@_){ andys 37 -n map$_=++$_.$/,@p[9-$_..8]}{print@p banshee 37 -nl ++$$[--$_]}{map{print$t+=pop@$}@$ juuso 37 -ln0 /$=/?print s//$=-1/eg:3while--$= suo 38 -p $x[--$_]++while$_}{$\=$_.$/.$\for@x dave 38 -p $k[--$_]++while$_}{$\=~s//$_\n/for@k c.dolan 40 -nl $_[9-$_]++for 1..$_}{$_&&print for@_ terje 40 -p $d[$_-1]++for 1..$_}{$\=$_.$/.$\for@d octo 41 -l map++$o[$_-1],<>;map{print$o+=pop@o}@o octo 41 -nl ++$o[$_-1];END{map{print$o+=pop@o}@o} beowolf 42 -l map{++$a[--$_]}<>;map{print$o+=pop@a}@a j.krahn 42 -ln $_[$_]++while$_--}{map{print}reverse@_ octo 44 -nl ++$o[9-$_--]while$_;END{map$_&&print,@o} ton 45 -p $z.=a.1x$_}{$_="$a\n$_"while$a=$z=~s/a1/a/g darek 46 -ln $a[$_]++while$_--;END{print for+reverse@a} depesz 47 $x[$_]++for map{1..$_}<>;print join$/,reverse@x Sn0wSmyrf 49 -nl $i=0;$a[$i++]++for 1..$_}{print for reverse@a trstn 50 -n END{print join"\n",reverse@a}$a[$_]++for(1..$_) hispeed 52 map{for(1..$_){$a[$_]++}}<>;print join"\n",reverse@a hispeed 64 for(;<>=~/\d+/;){for(@a[1..$&]){$_++}}print join("\n",reverse@a) d.hoover 34 -pl ++$_[--$_]while$_}for(sort@_){ (rejected) Ion 44 -l map$a[$_]++,0..$_-1for<>;print for sort@a (rejected)This was found after the post-mortem:
ton 33 -pl ++$;[--$_]}while(@;){$_+=pop@ (mixing tybalt89 and banshee) ton 33 -pl ++$a[$_]}while($#a){$_+=pop@a (here the ; trick fails)