1 # The Computer Language Shootout
2 # http://shootout.alioth.debian.org
4 # contributed by jose fco. gonzalez
5 # modified by Sokolov Yura
9 def frecuency( seq
,length
)
10 n
, table
= seq
.length
- length
+ 1, Hash
.new(0)
12 (0 ... length
).each
do |f
|
13 (f
... n
).step(length
) do |i
|
14 table
[seq
[i
,length
]] += 1
21 def sort_by_freq( seq
,length
)
22 n
,table
= frecuency( seq
,length
)
23 a
, b
, v
= nil, nil, nil
24 table
.sort
{|a
,b
| b
[1] <=> a
[1]}.each
do |v
|
25 puts
"%s %.3f" % [v
[0].upcase
,((v
[1]*100).to_f
/n
)]
31 n
,table
= frecuency( seq
,s
.length
)
32 puts
"#{table[s].to_s}\t#{s.upcase}"
35 line
= STDIN.gets
while line
!~
/^>THREE/
37 while (line
!~
/^>/) & line
do
42 [1,2].each
{|i
| sort_by_freq( seq
,i
) }
44 %w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt
).each
{|s
| find_seq( seq
,s
) }