harry’s memorandum

おれおれメモ

hello world

ゴミですな。

m = ("a"..."z").to_a + ["!","\s"]
puts [7,4,11,11,14,-1,22,14,17,11,3,-2].map {|n| m[n]}.join
 #=>hello world! 
m = ("a"..."z").to_a + ["!","\s"]
[7,11,14,22,17,3].zip([4,11,-1,14,11,-2]){|x,y| print m[x], m[y]}
puts
 #=>hello world! 

すこしぐらい凝ったのだとこんな感じかな。

class Progress
  def initialize
    @map = ("a"..."z").to_a + ["!","\s"]
    @interval = 0.01
    @str = ""
  end
  def ok?(s)
    s == @map[rand(@map.size)] ? true : false
  end
  def bar(s)
    while true
      if ok?(s)
        @str << s
        STDERR.print("\r#{@str}\r")
        break
      end
      sleep @interval
    end
  end
  def clear
    clean = " " * @str.size
    STDERR.print("\r#{clean}\r")
    @str = ""
  end
end

pg = Progress.new
"hello world!".split(//).each {|s| pg.bar(s)}
sleep 2
pg.clear