1 # The Computer Language Shootout
2 # http://shootout.alioth.debian.org/
3 # Contributed by Sokolov Yura
6 def gen_random (max,im=139968,ia=3877,ic=29573)
7 (max * ($last = ($last * ia + ic) % im)) / im
11 "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
12 "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
13 "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
14 "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
15 "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
16 "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
17 "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
38 ["a", 0.3029549426680],
39 ["c", 0.1979883004921],
40 ["g", 0.1975473066391],
41 ["t", 0.3015094502008],
44 def make_repeat_fasta(id, desc, src, n)
49 s = src * ((n / l) + 1)
51 puts(s.scan(/.{1,#{width}}/).join("\n"))
54 def make_random_fasta(id, desc, table, n)
60 table.each{|v| v[1]= (prob += v[1])}
62 puts((1..width).collect{
63 rand = gen_random(1.0)
64 table.find{|v| v[1]>rand}[0]
68 puts((1..(n%width)).collect{
69 rand = gen_random(1.0)
70 table.find{|v| v[1]>rand}[0]
76 n = (ARGV[0] or 250_000).to_i
78 make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
79 make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
80 make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)