File: hash2.ruby

package info (click to toggle)
jruby 9.3.9.0%2Bds-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,856 kB
  • sloc: ruby: 517,823; java: 260,094; xml: 31,930; ansic: 5,777; yacc: 4,973; sh: 1,163; makefile: 105; jsp: 48; tcl: 40; exp: 11
file content (23 lines) | stat: -rw-r--r-- 451 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: hash2.ruby,v 1.2 2004-11-10 06:36:29 bfulgham Exp $
# http://shootout.alioth.debian.org/
# Revised by Dave Anderson

n = Integer(ARGV.shift || 1)

hash1 = {}
i = 0
for i in 0 .. 9999
    hash1["foo_" << i.to_s] = i
end

hash2 = Hash.new(0)
n.times do
    for i in hash1.keys
	hash2[i] += hash1[i]
    end
end

printf "%d %d %d %d\n",
    hash1["foo_1"], hash1["foo_9999"], hash2["foo_1"], hash2["foo_9999"]