Feb 28, 2008

"Nabeatsu of the World" program.

It becomes "Aho" if multiples of 3 or numbers including 3.

module Enumerable
def aho(&block)
self.map do |a|
if 100 <= a
a.to_s
elsif block.call(a)
a.to_aho
else
a.to_s
end
end
end
end

class Integer
def to_aho
fig1 = [ "", "iiiichi", "niiii", "saaaan", "siiii", "goooo", "rooooku", "siiiichi", "haaaachi", "kyuuuu" ]
fig10 = [ "", "", "ni", "san", "yon", "go", "roku", "nana", "hachi", "kyu" ]

if self < 10
fig1[self]
elsif 10 <= self
fig10[self / 10] + "-ju-" + fig1[self % 10]
else
n.to_s
end
end
end


(1..100).aho{|a| (a % 3 == 0) || a.to_s.include?("3") }.each{|a| printf("%s ", a) }

No comments: