chrislo-sourceclassifier 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +325 -0
- data/README.textile +51 -0
- data/Rakefile +64 -0
- data/examples/example.rb +22 -0
- data/lib/sourceclassifier.rb +22 -0
- data/lib/trainer.rb +51 -0
- data/sourceclassifier.gemspec +35 -0
- data/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/sources/gcc/ackermann.gcc-3.gcc +20 -0
- data/sources/gcc/ary.gcc +40 -0
- data/sources/gcc/binarytrees.gcc +136 -0
- data/sources/gcc/binarytrees.gcc-2.gcc +140 -0
- data/sources/gcc/binarytrees.gcc-3.gcc +134 -0
- data/sources/gcc/chameneos.gcc +117 -0
- data/sources/gcc/chameneos.gcc-2.gcc +134 -0
- data/sources/gcc/chameneos.gcc-3.gcc +120 -0
- data/sources/gcc/chameneosredux.gcc +306 -0
- data/sources/gcc/echo.gcc +144 -0
- data/sources/gcc/except.gcc +52 -0
- data/sources/gcc/fannkuch.gcc +105 -0
- data/sources/gcc/fannkuch.gcc-2.gcc +94 -0
- data/sources/gcc/fasta.gcc +158 -0
- data/sources/gcc/fasta.gcc-2.gcc +132 -0
- data/sources/gcc/fasta.gcc-3.gcc +145 -0
- data/sources/gcc/fasta.gcc-4.gcc +141 -0
- data/sources/gcc/fibo.gcc +20 -0
- data/sources/gcc/harmonic.gcc +22 -0
- data/sources/gcc/hash.gcc +31 -0
- data/sources/gcc/hash2.gcc +38 -0
- data/sources/gcc/heapsort.gcc +72 -0
- data/sources/gcc/hello.gcc-2.gcc +12 -0
- data/sources/gcc/hello.gcc-3.gcc +20 -0
- data/sources/gcc/knucleotide.gcc +173 -0
- data/sources/gcc/knucleotide.gcc-2.gcc +168 -0
- data/sources/gcc/lists.gcc +226 -0
- data/sources/gcc/magicsquares.gcc +378 -0
- data/sources/gcc/mandelbrot.gcc +84 -0
- data/sources/gcc/mandelbrot.gcc-2.gcc +63 -0
- data/sources/gcc/mandelbrot.gcc-3.gcc +91 -0
- data/sources/gcc/mandelbrot.gcc-4.gcc +78 -0
- data/sources/gcc/matrix.gcc +66 -0
- data/sources/gcc/message.gcc-2.gcc +72 -0
- data/sources/gcc/message.gcc-3.gcc +64 -0
- data/sources/gcc/methcall.gcc +89 -0
- data/sources/gcc/moments.gcc +120 -0
- data/sources/gcc/nbody.gcc +142 -0
- data/sources/gcc/nbody.gcc-2.gcc +143 -0
- data/sources/gcc/nbody.gcc-3.gcc +142 -0
- data/sources/gcc/nestedloop.gcc +25 -0
- data/sources/gcc/nsieve.gcc +35 -0
- data/sources/gcc/nsievebits.gcc-2.gcc +37 -0
- data/sources/gcc/nsievebits.gcc-3.gcc +53 -0
- data/sources/gcc/objinst.gcc +95 -0
- data/sources/gcc/partialsums.gcc +86 -0
- data/sources/gcc/partialsums.gcc-3.gcc +81 -0
- data/sources/gcc/partialsums.gcc-4.gcc +68 -0
- data/sources/gcc/pidigits.gcc +105 -0
- data/sources/gcc/primes.gcc +75 -0
- data/sources/gcc/prodcons.gcc +86 -0
- data/sources/gcc/random.gcc +29 -0
- data/sources/gcc/raytracer.gcc +125 -0
- data/sources/gcc/raytracer.gcc-2.gcc +181 -0
- data/sources/gcc/recursive.gcc +68 -0
- data/sources/gcc/recursive.gcc-2.gcc +55 -0
- data/sources/gcc/regexdna.gcc-2.gcc +126 -0
- data/sources/gcc/regexmatch.gcc +136 -0
- data/sources/gcc/revcomp.gcc +85 -0
- data/sources/gcc/revcomp.gcc-2.gcc +88 -0
- data/sources/gcc/revcomp.gcc-4.gcc +71 -0
- data/sources/gcc/reversefile.gcc +103 -0
- data/sources/gcc/reversefile.gcc-2.gcc +56 -0
- data/sources/gcc/sieve.gcc +34 -0
- data/sources/gcc/spectralnorm.gcc +54 -0
- data/sources/gcc/spellcheck.gcc +72 -0
- data/sources/gcc/spellcheck.gcc-2.gcc +61 -0
- data/sources/gcc/strcat.gcc +38 -0
- data/sources/gcc/sumcol.gcc-2.gcc +98 -0
- data/sources/gcc/sumcol.gcc-3.gcc +22 -0
- data/sources/gcc/sumcol.gcc-4.gcc +18 -0
- data/sources/gcc/sumcol.gcc-5.gcc +32 -0
- data/sources/gcc/takfp.gcc +23 -0
- data/sources/gcc/tcp-stream.gcc +122 -0
- data/sources/gcc/tcpecho.gcc +122 -0
- data/sources/gcc/tcpecho.gcc-2.gcc +136 -0
- data/sources/gcc/tcprequest.gcc +122 -0
- data/sources/gcc/threadring.gcc +73 -0
- data/sources/gcc/wc.gcc +52 -0
- data/sources/gcc/wc.gcc-2.gcc +40 -0
- data/sources/gcc/wc.gcc-3.gcc +46 -0
- data/sources/gcc/wordfreq.gcc-2.gcc +85 -0
- data/sources/perl/ackermann.perl +28 -0
- data/sources/perl/ackermann.perl-2.perl +25 -0
- data/sources/perl/ackermann.perl-3.perl +20 -0
- data/sources/perl/ackermann.perl-4.perl +18 -0
- data/sources/perl/ary.perl +25 -0
- data/sources/perl/ary.perl-2.perl +23 -0
- data/sources/perl/binarytrees.perl +66 -0
- data/sources/perl/binarytrees.perl-2.perl +71 -0
- data/sources/perl/chameneos.perl +67 -0
- data/sources/perl/echo.perl +81 -0
- data/sources/perl/except.perl +73 -0
- data/sources/perl/fannkuch.perl +44 -0
- data/sources/perl/fannkuch.perl-2.perl +38 -0
- data/sources/perl/fasta.perl +112 -0
- data/sources/perl/fasta.perl-2.perl +135 -0
- data/sources/perl/fasta.perl-4.perl +122 -0
- data/sources/perl/fibo.perl +15 -0
- data/sources/perl/fibo.perl-2.perl +0 -0
- data/sources/perl/fibo.perl-3.perl +0 -0
- data/sources/perl/harmonic.perl +7 -0
- data/sources/perl/hash.perl +23 -0
- data/sources/perl/hash.perl-2.perl +17 -0
- data/sources/perl/hash.perl-3.perl +24 -0
- data/sources/perl/hash2.perl +16 -0
- data/sources/perl/heapsort.perl +65 -0
- data/sources/perl/heapsort.perl-2.perl +0 -0
- data/sources/perl/hello.perl +5 -0
- data/sources/perl/knucleotide.perl-2.perl +30 -0
- data/sources/perl/lists.perl +48 -0
- data/sources/perl/mandelbrot.perl-2.perl +32 -0
- data/sources/perl/matrix.perl +59 -0
- data/sources/perl/matrix.perl-2.perl +0 -0
- data/sources/perl/matrix.perl-3.perl +0 -0
- data/sources/perl/message.perl +27 -0
- data/sources/perl/methcall.perl +66 -0
- data/sources/perl/moments.perl +44 -0
- data/sources/perl/nbody.perl +108 -0
- data/sources/perl/nestedloop.perl +28 -0
- data/sources/perl/nsieve.perl-2.perl +41 -0
- data/sources/perl/nsieve.perl-4.perl +43 -0
- data/sources/perl/nsievebits.perl +37 -0
- data/sources/perl/objinst.perl +73 -0
- data/sources/perl/partialsums.perl-3.perl +31 -0
- data/sources/perl/pidigits.perl +52 -0
- data/sources/perl/pidigits.perl-2.perl +47 -0
- data/sources/perl/process.perl +50 -0
- data/sources/perl/prodcons.perl +47 -0
- data/sources/perl/random.perl-4.perl +17 -0
- data/sources/perl/recursive.perl-2.perl +57 -0
- data/sources/perl/regexdna.perl +48 -0
- data/sources/perl/regexdna.perl-2.perl +43 -0
- data/sources/perl/regexdna.perl-3.perl +50 -0
- data/sources/perl/regexdna.perl-4.perl +49 -0
- data/sources/perl/regexdna.perl-5.perl +42 -0
- data/sources/perl/regexdna.perl-6.perl +43 -0
- data/sources/perl/regexmatch.perl +35 -0
- data/sources/perl/revcomp.perl-2.perl +34 -0
- data/sources/perl/reversefile.perl +8 -0
- data/sources/perl/reversefile.perl-2.perl +0 -0
- data/sources/perl/reversefile.perl-3.perl +0 -0
- data/sources/perl/sieve.perl +23 -0
- data/sources/perl/spectralnorm.perl-2.perl +54 -0
- data/sources/perl/spellcheck.perl +24 -0
- data/sources/perl/strcat.perl +13 -0
- data/sources/perl/strcat.perl-2.perl +0 -0
- data/sources/perl/sumcol.perl +8 -0
- data/sources/perl/takfp.perl +23 -0
- data/sources/perl/takfp.perl-3.perl +20 -0
- data/sources/perl/tcpecho.perl +61 -0
- data/sources/perl/tcprequest.perl +61 -0
- data/sources/perl/tcpstream.perl +61 -0
- data/sources/perl/threadring.perl +55 -0
- data/sources/perl/threadring.perl-2.perl +43 -0
- data/sources/perl/wc.perl +20 -0
- data/sources/perl/wc.perl-2.perl +14 -0
- data/sources/perl/wordfreq.perl +22 -0
- data/sources/perl/wordfreq.perl-3.perl +0 -0
- data/sources/perl/wordfreq.perl3.perl +0 -0
- data/sources/python/ackermann.python +21 -0
- data/sources/python/ary.python +19 -0
- data/sources/python/binarytrees.python +39 -0
- data/sources/python/binarytrees.python-3.python +44 -0
- data/sources/python/chameneos.python-6.python +73 -0
- data/sources/python/chameneosredux.python +126 -0
- data/sources/python/chameneosredux.python-2.python +122 -0
- data/sources/python/dispatch.python +176 -0
- data/sources/python/dispatch.python-2.python +136 -0
- data/sources/python/echo.python +64 -0
- data/sources/python/except.python +62 -0
- data/sources/python/fannkuch.python +50 -0
- data/sources/python/fannkuch.python-2.python +54 -0
- data/sources/python/fasta.python-2.python +79 -0
- data/sources/python/fibo.python +17 -0
- data/sources/python/fibo.python-2.python +0 -0
- data/sources/python/fibo.python-3.python +0 -0
- data/sources/python/harmonic.python-2.python +9 -0
- data/sources/python/hash.python +21 -0
- data/sources/python/hash.python-2.python +0 -0
- data/sources/python/hash2.python +30 -0
- data/sources/python/heapsort.python-3.python +66 -0
- data/sources/python/hello.python +5 -0
- data/sources/python/implicitode.python +231 -0
- data/sources/python/knucleotide.python +55 -0
- data/sources/python/lists.python +44 -0
- data/sources/python/magicsquares.python +145 -0
- data/sources/python/mandelbrot.python +44 -0
- data/sources/python/mandelbrot.python-2.python +35 -0
- data/sources/python/mandelbrot.python-3.python +46 -0
- data/sources/python/matrix.python +34 -0
- data/sources/python/matrix.python-2.python +23 -0
- data/sources/python/message.python +24 -0
- data/sources/python/message.python-2.python +20 -0
- data/sources/python/message.python-3.python +19 -0
- data/sources/python/meteor.python +210 -0
- data/sources/python/meteor.python-2.python +192 -0
- data/sources/python/methcall.python +51 -0
- data/sources/python/moments.python +65 -0
- data/sources/python/nbody.python +123 -0
- data/sources/python/nbody.python-2.python +120 -0
- data/sources/python/nestedloop.python +24 -0
- data/sources/python/nsieve.python +27 -0
- data/sources/python/nsieve.python-2.python +23 -0
- data/sources/python/nsieve.python-4.python +25 -0
- data/sources/python/nsievebits.python +27 -0
- data/sources/python/nsievebits.python-2.python +43 -0
- data/sources/python/objinst.python +53 -0
- data/sources/python/partialsums.python +37 -0
- data/sources/python/partialsums.python-2.python +35 -0
- data/sources/python/partialsums.python-3.python +48 -0
- data/sources/python/pidigits.python +38 -0
- data/sources/python/pidigits.python-3.python +63 -0
- data/sources/python/pidigits.python-4.python +24 -0
- data/sources/python/process.python +51 -0
- data/sources/python/process.python-2.python +133 -0
- data/sources/python/prodcons.python +51 -0
- data/sources/python/prodcons.python-2.python +0 -0
- data/sources/python/random.python +27 -0
- data/sources/python/raytracer.python +203 -0
- data/sources/python/recursive.python +35 -0
- data/sources/python/regexdna.python +39 -0
- data/sources/python/regexdna.python-2.python +34 -0
- data/sources/python/regexmatch.python +36 -0
- data/sources/python/revcomp.python-3.python +31 -0
- data/sources/python/reversefile.python +13 -0
- data/sources/python/reversefile.python-2.python +0 -0
- data/sources/python/reversefile.python-3.python +0 -0
- data/sources/python/sieve.python +50 -0
- data/sources/python/spectralnorm.python-2.python +36 -0
- data/sources/python/spellcheck.python +17 -0
- data/sources/python/strcat.python +35 -0
- data/sources/python/strcat.python-2.python +0 -0
- data/sources/python/sumcol.python-2.python +0 -0
- data/sources/python/sumcol.python-3.python +0 -0
- data/sources/python/takfp.python +19 -0
- data/sources/python/tcpecho.python +67 -0
- data/sources/python/tcprequest.python +67 -0
- data/sources/python/tcpstream.python +67 -0
- data/sources/python/threadring.python +47 -0
- data/sources/python/threadring.python-2.python +40 -0
- data/sources/python/threadring.python-3.python +34 -0
- data/sources/python/wc.python-2.python +19 -0
- data/sources/python/wordfreq.python +43 -0
- data/sources/python/wordfreq.python-2.python +0 -0
- data/sources/python/wordfreq.python-3.python +28 -0
- data/sources/python/wordfreq.python-4.python +38 -0
- data/sources/python/wordfreq.python-5.python +39 -0
- data/sources/ruby/ackermann.ruby +17 -0
- data/sources/ruby/ackermann.ruby-5.ruby +153 -0
- data/sources/ruby/ary.ruby +22 -0
- data/sources/ruby/binarytrees.ruby-2.ruby +55 -0
- data/sources/ruby/chameneos.ruby-2.ruby +71 -0
- data/sources/ruby/dispatch.ruby +114 -0
- data/sources/ruby/echo.ruby +41 -0
- data/sources/ruby/except.ruby +61 -0
- data/sources/ruby/except.ruby-2.ruby +61 -0
- data/sources/ruby/fannkuch.ruby +42 -0
- data/sources/ruby/fasta.ruby +81 -0
- data/sources/ruby/fibo.ruby +15 -0
- data/sources/ruby/harmonic.ruby-2.ruby +15 -0
- data/sources/ruby/hash.ruby +19 -0
- data/sources/ruby/hash2.ruby +23 -0
- data/sources/ruby/heapsort.ruby +55 -0
- data/sources/ruby/hello.ruby +6 -0
- data/sources/ruby/knucleotide.ruby-2.ruby +44 -0
- data/sources/ruby/lists.ruby +46 -0
- data/sources/ruby/mandelbrot.ruby-3.ruby +63 -0
- data/sources/ruby/matrix.ruby +40 -0
- data/sources/ruby/matrix.ruby-2.ruby +30 -0
- data/sources/ruby/message.ruby +29 -0
- data/sources/ruby/message.ruby-2.ruby +24 -0
- data/sources/ruby/meteor.ruby +386 -0
- data/sources/ruby/meteor.ruby-2.ruby +561 -0
- data/sources/ruby/methcall.ruby +58 -0
- data/sources/ruby/methcall.ruby-2.ruby +54 -0
- data/sources/ruby/moments.ruby +64 -0
- data/sources/ruby/nbody.ruby-2.ruby +145 -0
- data/sources/ruby/nestedloop.ruby +22 -0
- data/sources/ruby/nsieve.ruby +36 -0
- data/sources/ruby/nsieve.ruby-2.ruby +25 -0
- data/sources/ruby/nsievebits.ruby-2.ruby +42 -0
- data/sources/ruby/objinst.ruby +58 -0
- data/sources/ruby/partialsums.ruby +39 -0
- data/sources/ruby/pidigits.ruby +92 -0
- data/sources/ruby/pidigits.ruby-2.ruby +109 -0
- data/sources/ruby/prodcons.ruby +41 -0
- data/sources/ruby/random.ruby +17 -0
- data/sources/ruby/recursive.ruby-2.ruby +53 -0
- data/sources/ruby/regexdna.ruby +32 -0
- data/sources/ruby/regexdna.ruby-2.ruby +38 -0
- data/sources/ruby/regexmatch.ruby +33 -0
- data/sources/ruby/revcomp.ruby +28 -0
- data/sources/ruby/reversefile.ruby +7 -0
- data/sources/ruby/sieve.ruby +30 -0
- data/sources/ruby/spectralnorm.ruby +48 -0
- data/sources/ruby/spellcheck.ruby +18 -0
- data/sources/ruby/spellcheck.ruby-2.ruby +0 -0
- data/sources/ruby/strcat.ruby +12 -0
- data/sources/ruby/strcat.ruby-2.ruby +12 -0
- data/sources/ruby/sumcol.ruby +12 -0
- data/sources/ruby/sumcol.ruby-2.ruby +5 -0
- data/sources/ruby/takfp.ruby +15 -0
- data/sources/ruby/tcpecho.ruby +45 -0
- data/sources/ruby/tcprequest.ruby +45 -0
- data/sources/ruby/tcpstream.ruby +45 -0
- data/sources/ruby/threadring.ruby +61 -0
- data/sources/ruby/threadring.ruby-2.ruby +33 -0
- data/sources/ruby/wc.ruby +15 -0
- data/sources/ruby/wordfreq.ruby +17 -0
- data/sources/ruby/wordfreq.ruby2.ruby +0 -0
- data/test/fixtures/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/test/fixtures/sources/python/ackermann.python +21 -0
- data/test/fixtures/sources/ruby/ackermann.ruby +17 -0
- data/test/test_source_classifier.rb +40 -0
- data/test/test_trainer.rb +34 -0
- data/trainer.bin +1193 -0
- metadata +393 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# The Computer Language Benchmarks Game
|
2
|
+
# http://shootout.alioth.debian.org/
|
3
|
+
# Contributed by Antti Kervinen
|
4
|
+
# Modified by Tupteq
|
5
|
+
|
6
|
+
import sys
|
7
|
+
import thread
|
8
|
+
|
9
|
+
# Set minimum stack size for threads, otherwise the program may fail
|
10
|
+
# to create such a many threads
|
11
|
+
thread.stack_size(32*1024)
|
12
|
+
|
13
|
+
def threadfun(number, lock_acquire, next_release):
|
14
|
+
global n
|
15
|
+
while 1:
|
16
|
+
lock_acquire()
|
17
|
+
if n > 0:
|
18
|
+
n -= 1
|
19
|
+
next_release()
|
20
|
+
else:
|
21
|
+
print number
|
22
|
+
main_lock.release()
|
23
|
+
|
24
|
+
# main
|
25
|
+
n = int(sys.argv[1])
|
26
|
+
main_lock = thread.allocate_lock()
|
27
|
+
main_lock.acquire()
|
28
|
+
|
29
|
+
first_lock = thread.allocate_lock()
|
30
|
+
next_lock = first_lock
|
31
|
+
|
32
|
+
for number in xrange(503):
|
33
|
+
lock = next_lock
|
34
|
+
lock.acquire()
|
35
|
+
next_lock = thread.allocate_lock() if number < 502 else first_lock
|
36
|
+
thread.start_new_thread(threadfun,
|
37
|
+
(number+1, lock.acquire, next_lock.release))
|
38
|
+
|
39
|
+
first_lock.release()
|
40
|
+
main_lock.acquire()
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# The Computer Language Benchmarks Game
|
2
|
+
# http://shootout.alioth.debian.org/
|
3
|
+
#
|
4
|
+
# contributed by Daniel Nanz 2008-03-11
|
5
|
+
# --------------------------------------------
|
6
|
+
# Coroutines via enhanced generators
|
7
|
+
# (http://www.python.org/dev/peps/pep-0342/)
|
8
|
+
|
9
|
+
import sys
|
10
|
+
import itertools
|
11
|
+
|
12
|
+
def main(n = int(sys.argv[1]), n_threads=503, cycle=itertools.cycle):
|
13
|
+
|
14
|
+
def worker(worker_id):
|
15
|
+
|
16
|
+
n = 1
|
17
|
+
while True:
|
18
|
+
if n > 0:
|
19
|
+
n = (yield (n - 1))
|
20
|
+
else:
|
21
|
+
print worker_id
|
22
|
+
raise StopIteration
|
23
|
+
|
24
|
+
|
25
|
+
threadRing = [worker(w) for w in xrange(1, n_threads + 1)]
|
26
|
+
for t in threadRing: foo = t.next() # start exec. gen. funcs
|
27
|
+
sendFuncRing = [t.send for t in threadRing] # speed...
|
28
|
+
for send in cycle(sendFuncRing):
|
29
|
+
try:
|
30
|
+
n = send(n)
|
31
|
+
except StopIteration:
|
32
|
+
break
|
33
|
+
|
34
|
+
main()
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
# The Great Computer Language Shootout
|
3
|
+
# http://shootout.alioth.debian.org/
|
4
|
+
#
|
5
|
+
# contributed by kosh
|
6
|
+
|
7
|
+
import sys
|
8
|
+
|
9
|
+
def main():
|
10
|
+
nl = nw = nc = 0
|
11
|
+
|
12
|
+
for line in sys.stdin:
|
13
|
+
nl += 1
|
14
|
+
nc += len(line)
|
15
|
+
nw += len(line.split())
|
16
|
+
|
17
|
+
print "%d %d %d" % (nl, nw, nc)
|
18
|
+
|
19
|
+
main()
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
# $Id: wordfreq.python,v 1.2 2004-07-03 05:36:11 bfulgham Exp $
|
3
|
+
# http://shootout.alioth.debian.org/
|
4
|
+
#
|
5
|
+
# adapted from Bill Lear's original python word frequency counter
|
6
|
+
#
|
7
|
+
# Joel Rosdahl suggested using translate table to speed up
|
8
|
+
# word splitting. That change alone sped this program up by
|
9
|
+
# at least a factor of 3.
|
10
|
+
#
|
11
|
+
# with further speedups from Mark Baker
|
12
|
+
|
13
|
+
import sys
|
14
|
+
|
15
|
+
def main():
|
16
|
+
count = {}
|
17
|
+
i_r = map(chr, range(256))
|
18
|
+
|
19
|
+
trans = [' '] * 256
|
20
|
+
o_a, o_z = ord('a'), (ord('z')+1)
|
21
|
+
trans[ord('A'):(ord('Z')+1)] = i_r[o_a:o_z]
|
22
|
+
trans[o_a:o_z] = i_r[o_a:o_z]
|
23
|
+
trans = ''.join(trans)
|
24
|
+
|
25
|
+
rl = sys.stdin.readlines
|
26
|
+
|
27
|
+
lines = rl(4095)
|
28
|
+
while lines:
|
29
|
+
for line in lines:
|
30
|
+
for word in line.translate(trans).split():
|
31
|
+
try:
|
32
|
+
count[word] += 1
|
33
|
+
except KeyError:
|
34
|
+
count[word] = 1
|
35
|
+
lines = rl(4095)
|
36
|
+
|
37
|
+
l = zip(count.values(), count.keys())
|
38
|
+
l.sort()
|
39
|
+
l.reverse()
|
40
|
+
|
41
|
+
print '\n'.join(["%7s %s" % (count, word) for (count, word) in l])
|
42
|
+
|
43
|
+
main()
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import sys, re, string
|
2
|
+
|
3
|
+
def main():
|
4
|
+
count = {}
|
5
|
+
p = re.compile(r'[^a-z]')
|
6
|
+
for word in p.split(string.lower(sys.stdin.read())):
|
7
|
+
if not word: continue
|
8
|
+
count[word] = count.get(word, 0) + 1
|
9
|
+
|
10
|
+
bucket = {}
|
11
|
+
for key, val in count.items():
|
12
|
+
if not bucket.has_key(val):
|
13
|
+
bucket[val] = []
|
14
|
+
bucket[val].append(key)
|
15
|
+
|
16
|
+
freqs = bucket.keys()
|
17
|
+
freqs.sort()
|
18
|
+
freqs.reverse()
|
19
|
+
|
20
|
+
for freq in freqs:
|
21
|
+
words = bucket[freq]
|
22
|
+
words.sort()
|
23
|
+
words.reverse()
|
24
|
+
for word in words:
|
25
|
+
print "%7d\t%s" % (freq, word)
|
26
|
+
|
27
|
+
main()
|
28
|
+
sys.stdout.flush()
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import sys, re, string
|
2
|
+
|
3
|
+
def main():
|
4
|
+
# count is a dictionary of word counts
|
5
|
+
count = {}
|
6
|
+
# speed up function call by making a local alias
|
7
|
+
lower = string.lower
|
8
|
+
nextline = sys.stdin.readline
|
9
|
+
p = re.compile(r'[^a-z]')
|
10
|
+
while 1:
|
11
|
+
line = nextline()
|
12
|
+
if not line: break
|
13
|
+
for word in p.split(lower(line)):
|
14
|
+
if not count.has_key(word):
|
15
|
+
count[word] = 1
|
16
|
+
else:
|
17
|
+
count[word] = count[word] + 1
|
18
|
+
|
19
|
+
bucket = {}
|
20
|
+
for key, val in count.items():
|
21
|
+
if not bucket.has_key(val):
|
22
|
+
bucket[val] = []
|
23
|
+
bucket[val].append(key)
|
24
|
+
|
25
|
+
freqs = bucket.keys()
|
26
|
+
freqs.sort()
|
27
|
+
freqs.reverse()
|
28
|
+
|
29
|
+
for freq in freqs:
|
30
|
+
words = bucket[freq]
|
31
|
+
words.sort()
|
32
|
+
words.reverse()
|
33
|
+
for word in words:
|
34
|
+
if len(word) > 0:
|
35
|
+
print "%7d\t%s" % (freq, word)
|
36
|
+
|
37
|
+
main()
|
38
|
+
sys.stdout.flush()
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import sys, re, string, fileinput
|
2
|
+
|
3
|
+
def main():
|
4
|
+
# count is a dictionary of word counts
|
5
|
+
count = {}
|
6
|
+
# speed up function call by making a local alias
|
7
|
+
lower = string.lower
|
8
|
+
#nextline = sys.stdin.readline
|
9
|
+
p = re.compile(r'[^a-z]')
|
10
|
+
#while 1:
|
11
|
+
# line = nextline()
|
12
|
+
# if not line: break
|
13
|
+
for line in fileinput.input('-'):
|
14
|
+
for word in p.split(lower(line)):
|
15
|
+
if not count.has_key(word):
|
16
|
+
count[word] = 1
|
17
|
+
else:
|
18
|
+
count[word] = count[word] + 1
|
19
|
+
|
20
|
+
bucket = {}
|
21
|
+
for key, val in count.items():
|
22
|
+
if not bucket.has_key(val):
|
23
|
+
bucket[val] = []
|
24
|
+
bucket[val].append(key)
|
25
|
+
|
26
|
+
freqs = bucket.keys()
|
27
|
+
freqs.sort()
|
28
|
+
freqs.reverse()
|
29
|
+
|
30
|
+
for freq in freqs:
|
31
|
+
words = bucket[freq]
|
32
|
+
words.sort()
|
33
|
+
words.reverse()
|
34
|
+
for word in words:
|
35
|
+
if len(word) > 0:
|
36
|
+
print "%7d\t%s" % (freq, word)
|
37
|
+
|
38
|
+
main()
|
39
|
+
sys.stdout.flush()
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# $Id: ackermann.ruby,v 1.2 2005-06-10 00:57:22 igouy-guest Exp $
|
4
|
+
# http://www.bagley.org/~doug/shootout/
|
5
|
+
|
6
|
+
def ack(m, n)
|
7
|
+
if m == 0 then
|
8
|
+
n + 1
|
9
|
+
elsif n == 0 then
|
10
|
+
ack(m - 1, 1)
|
11
|
+
else
|
12
|
+
ack(m - 1, ack(m, n - 1))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
NUM = Integer(ARGV.shift || 1)
|
17
|
+
print "Ack(3,", NUM, "): ", ack(3, NUM), "\n"
|
@@ -0,0 +1,153 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# The Computer Language Benchmark Shootout
|
3
|
+
# http://shootout.alioth.debian.org
|
4
|
+
#
|
5
|
+
# original code by Martin DeMello
|
6
|
+
# modified by Jabari Zakiya 3/20/05
|
7
|
+
# modified by Glenn Parker 3/28/05 (format results)
|
8
|
+
|
9
|
+
include Math
|
10
|
+
|
11
|
+
SOLAR_MASS = 4*PI*PI
|
12
|
+
DAYS_PER_YEAR = 365.24
|
13
|
+
|
14
|
+
Vector3D = Struct.new("Vector3D", :x, :y, :z)
|
15
|
+
|
16
|
+
class Vector3D
|
17
|
+
|
18
|
+
def *(val)
|
19
|
+
Vector3D.new(*self.map {|i| i * val})
|
20
|
+
end
|
21
|
+
|
22
|
+
def /(val)
|
23
|
+
Vector3D.new(*self.map {|i| i / val})
|
24
|
+
end
|
25
|
+
|
26
|
+
#in-place add with scale
|
27
|
+
# a.adds(b, s) -> a += b*s
|
28
|
+
|
29
|
+
def adds(other, scale)
|
30
|
+
self[0] += other[0]*scale; self[1] += other[1]*scale
|
31
|
+
self[2] += other[2]*scale
|
32
|
+
end
|
33
|
+
|
34
|
+
def subs(other, scale)
|
35
|
+
self[0] -= other[0]*scale; self[1] -= other[1]*scale
|
36
|
+
self[2] -= other[2]*scale
|
37
|
+
end
|
38
|
+
|
39
|
+
def magnitude
|
40
|
+
x=self[0]; y=self[1]; z=self[2]
|
41
|
+
sqrt(x*x + y*y + z*z)
|
42
|
+
end
|
43
|
+
|
44
|
+
# |self - other|
|
45
|
+
def dmag(other)
|
46
|
+
x=self[0]-other[0]; y=self[1]-other[1]; z=self[2]-other[2]
|
47
|
+
sqrt(x*x + y*y + z*z)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Planet
|
52
|
+
attr_accessor :pos, :v, :mass
|
53
|
+
|
54
|
+
def initialize(x, y, z, vx, vy, vz, mass)
|
55
|
+
@pos = Vector3D.new(x, y, z)
|
56
|
+
@v = Vector3D.new(vx, vy, vz) * DAYS_PER_YEAR
|
57
|
+
@mass = mass * SOLAR_MASS
|
58
|
+
end
|
59
|
+
|
60
|
+
def distance(other)
|
61
|
+
self.pos.dmag(other.pos)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
jupiter = Planet.new(
|
66
|
+
4.84143144246472090e+00,
|
67
|
+
-1.16032004402742839e+00,
|
68
|
+
-1.03622044471123109e-01,
|
69
|
+
1.66007664274403694e-03,
|
70
|
+
7.69901118419740425e-03,
|
71
|
+
-6.90460016972063023e-05,
|
72
|
+
9.54791938424326609e-04)
|
73
|
+
|
74
|
+
saturn = Planet.new(
|
75
|
+
8.34336671824457987e+00,
|
76
|
+
4.12479856412430479e+00,
|
77
|
+
-4.03523417114321381e-01,
|
78
|
+
-2.76742510726862411e-03,
|
79
|
+
4.99852801234917238e-03,
|
80
|
+
2.30417297573763929e-05,
|
81
|
+
2.85885980666130812e-04)
|
82
|
+
|
83
|
+
uranus = Planet.new(
|
84
|
+
1.28943695621391310e+01,
|
85
|
+
-1.51111514016986312e+01,
|
86
|
+
-2.23307578892655734e-01,
|
87
|
+
2.96460137564761618e-03,
|
88
|
+
2.37847173959480950e-03,
|
89
|
+
-2.96589568540237556e-05,
|
90
|
+
4.36624404335156298e-05)
|
91
|
+
|
92
|
+
neptune = Planet.new(
|
93
|
+
1.53796971148509165e+01,
|
94
|
+
-2.59193146099879641e+01,
|
95
|
+
1.79258772950371181e-01,
|
96
|
+
2.68067772490389322e-03,
|
97
|
+
1.62824170038242295e-03,
|
98
|
+
-9.51592254519715870e-05,
|
99
|
+
5.15138902046611451e-05)
|
100
|
+
|
101
|
+
sun = Planet.new(0, 0, 0, 0, 0, 0, 1)
|
102
|
+
|
103
|
+
class Array
|
104
|
+
def each_pair
|
105
|
+
a = []
|
106
|
+
each_index {|i|
|
107
|
+
((i+1)...length).each {|j|
|
108
|
+
yield at(i), at(j)
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
bodies = [sun, jupiter, saturn, uranus, neptune]
|
115
|
+
|
116
|
+
class << bodies
|
117
|
+
def advance(dt)
|
118
|
+
mag = m1 = m2 = nil
|
119
|
+
each_pair {|b1, b2|
|
120
|
+
d = b1.distance(b2)
|
121
|
+
mag = dt/(d*d*d)
|
122
|
+
|
123
|
+
m1 = b1.mass * mag
|
124
|
+
m2 = b2.mass * mag
|
125
|
+
|
126
|
+
b1.v.adds(b2.pos, m2)
|
127
|
+
b1.v.subs(b1.pos, m2)
|
128
|
+
b2.v.adds(b1.pos, m1)
|
129
|
+
b2.v.subs(b2.pos, m1)
|
130
|
+
}
|
131
|
+
|
132
|
+
each {|b| b.pos.adds(b.v, dt)}
|
133
|
+
end
|
134
|
+
|
135
|
+
def energy
|
136
|
+
e = 0
|
137
|
+
each {|b| e += 0.5 * b.mass * (b.v.magnitude ** 2) }
|
138
|
+
each_pair {|b1, b2| e -= (b1.mass * b2.mass) / b1.distance(b2) }
|
139
|
+
e
|
140
|
+
end
|
141
|
+
|
142
|
+
def offset_momentum
|
143
|
+
p = Vector3D.new(0,0,0)
|
144
|
+
sun = self[0]
|
145
|
+
each {|b| p.adds(b.v, b.mass) }
|
146
|
+
sun.v.subs(p, 1.0/sun.mass)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
bodies.offset_momentum
|
151
|
+
puts "%.9f" % bodies.energy
|
152
|
+
Integer(ARGV[0]).times { bodies.advance(0.01) }
|
153
|
+
puts "%.9f" % bodies.energy
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# $Id: ary.ruby,v 1.3 2004-06-20 08:39:45 bfulgham Exp $
|
4
|
+
# http://www.bagley.org/~doug/shootout/
|
5
|
+
# with help from Paul Brannan and Mark Hubbart
|
6
|
+
|
7
|
+
n = Integer(ARGV.shift || 1)
|
8
|
+
|
9
|
+
x = Array.new(n)
|
10
|
+
y = Array.new(n, 0)
|
11
|
+
|
12
|
+
for i in 0 ... n
|
13
|
+
x[i] = i + 1
|
14
|
+
end
|
15
|
+
|
16
|
+
(0 .. 999).each do
|
17
|
+
(n-1).step(0,-1) do |i|
|
18
|
+
y[i] += x.at(i)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
puts "#{y.first} #{y.last}"
|