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?
C#
If you're okay with imposing a limit on the array size then:
Otherwise, a less restrictive (but slightly more verbose) angle could be taken:
Okay, I think this is the last time I'm coming back to this one...
116 chars:
Java, again
i don't think it can be made shorter than this.. i also cut out unnecessary spaces.
LE: oh yes it can :) inspired by ding's post..
Powershell :
35 chars (with PowerShell Community Extensions, which replaces
Get-Random
):20 characters (plain PowerShell v2):
C#
EDIT: made complete program. assumes newlines and spaces could be removed, but left in for clarity :)
EDIT: made even shorter.... I dare someone to improve this one... I've tried for an hour.
EDIT: I think that's a bit shorter.
EDIT: I think that's even more shorter. Ugh, make me stop.
EDIT: One more line, one less character. Debatable...
Explanation
A[100]
- an array of any old thing - in this case A's (it's a nice short name). The contents are completely ignored, it's the size of the array that counts..Select(i=>r.Next())
- generates an enumerable of 100 values of r.Next()..OrderBy(i=>i)
- sorts the previous in order..ToList()
- convert the sorted enumerable of int to a List, so we can use ForEach.ForEach(Console.WriteLine)
- call Console.WriteLine 100 times, passing in each integer value in the list.In OCaml:
Edit: in OCaml typing that in the toplevel will print out the list, but if you want the list printed to stdout:
C++ with boost. Too bad that #include's are already half of all the text :)