Create, sort, and print a list of 100 random ints

2019-03-09 02:12发布

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?

30条回答
Deceive 欺骗
2楼-- · 2019-03-09 03:04

Python to print 100 random, sorted integers

import random,sys
print sorted(random.randint(1,sys.maxint)for x in range(100))

@Adam already beat me to it, but I thought using randint() and sys.maxint was sufficiently different to post anyway.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-09 03:07

Perl, a full 8 bytes shorter than nrich's version, and runs under "use warnings;" :)

perl -wle "$,=' ';print sort map {int rand 100} 1..100"
查看更多
beautiful°
4楼-- · 2019-03-09 03:10

In BASH:

for i in `seq 100`; do echo $RANDOM; done | sort -n
查看更多
叼着烟拽天下
5楼-- · 2019-03-09 03:11

xkcd style in PHP:

for($i=0;$i<100;$i++) echo "4\n";
查看更多
够拽才男人
6楼-- · 2019-03-09 03:11

Linux, command line:

% od -dAn -N40 /dev/random | tr ' ' '\n' | sort -nu
4959
6754
8133
10985
11121
14413
17335
20754
21317
30008
30381
33494
34935
41210
41417
43054
48254
51279
54055
55306
查看更多
时光不老,我们不散
7楼-- · 2019-03-09 03:11

My entry:

echo enter a bunch of ints, hit control-D when done
cat - | sort -n

or, per Adam in the comments:

echo enter a bunch of ints, hit control-D when done
sort -n
查看更多
登录 后发表回答