Execute HQ9+/Ruby: Difference between revisions
m
Fixed syntax highlighting.
m (Categorization now in master page) |
m (Fixed syntax highlighting.) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1:
{{implementation|HQ9+}}{{collection|RCHQ9+}}
This [[Ruby]] program implements an [[HQ9+]] interpreter.
<
})
def initialize(opts={})
@program =
@accumulator = 0
end
Line 12 ⟶ 19:
def run
▲ dispatch = Hash.new(:unknown)
▲ dispatch['h'] = :hello
▲ dispatch['q'] = :quine
▲ dispatch['9'] = :beer
▲ dispatch['+'] = :accumulate
▲ @program.downcase.each_char do |char|
end
Line 46 ⟶ 45:
hq9 = HQ9plus.new(:program => '+qhp;+9Q')
hq9.run
puts hq9.accumulator</
Output:
|