Die Programmiersprache Ruby

Blog| Forum| Wiki  

Diese Seite zeigt Implementierungen von HQ9++

Implementierung von cypher:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/ruby -w 
# HQ9+ Interpreter written in Ruby, by cypher 

$accumulator = 0 

def hq9plus( source ) 
    source.downcase.each_byte do |command| 
        case command 
        when ?h 
            puts "Hello World!" 
        when ?q 
            puts source 
        when ?9 
            99.downto 1 do |num| 
                puts <<BEER 
#{num} bottle#{num>1?'s':''} of beer on the wall 
#{num} bottle#{num>1?'s':''} of beer 
take one down, pass it around, 
#{num-1!=0?num-1:"no more"} bottle#{num!=2?'s':''} of beer on the wall 

BEER 
            end 
        when ?+ 
            $accumulator += 1 
        else 
            raise "#{command} is not a valid HQ9+-Command!" 
        end 
    end 
end 

if __FILE__ == $0 
    source = IO.read(ARGV[0]).chomp 
    hq9plus( source.gsub( /[^hq9\+]/i, '' ) ) 
end