What is the least amount of code you can write to create, sort (ascending), and print a list of 100 random positive integers? By least amount of code I mean characters contained in the entire source file, so get to minifying.
I'm interested in seeing the answers using any and all programming languages. Let's try to keep one answer per language, edit the previous to correct or simplify. If you can't edit, comment?
mackenir: an improvement by 7 characters:
Tcl is dead.
Long live tcl.
Creates a RANDOM (0-99) length list and puts RANDOM (0-99) integers in it.
Also prints to the screen and can be run exactly as shown in a tcl file, or the tcl shell.
PHP is nice too.
confirms completely to exercise
F#
APL (interactive):
If you want the numbers 0-99 (or 1-100, depending on whether you have the index origin in your workspace set to 0 or 1) to be unique, it takes 8 characters, like so:
↑100?100
If you don't care about uniqueness, do this (9 characters):
↑?100ρ100
Want larger numbers? Just substitute your upper limit, N, for the second 100 on each line, and your random numbers will be in the range 0 - N-1 (or 1-N if your index origin is set to 1).
If you want to guarantee that your numbers range from 0-99 (or 0 - N-1 if you're going for a larger upper limit) regardless of the index origin setting, just enclose either of the above lines in parentheses and add
-⎕IO
to the end (where ⎕ is APL's quad character). That's an additional 6 characters.
Windows BATCH: 160. This adds a leading zero's to the numbers, but otherwise the sorting is a little messed up (because sort sorts by characters - it doesn't know anything about numbers).
As a one-liner and way shorter (72):
An attempt in ruby:
(With eight fewer characters, but requiring the
tap
kestrel of Ruby 1.9)-for ruby 1.8:
30 characters. (could trim by 2 by changing back to 9e9, but comment in question says range should be MaxInt32.