冴子先生で素数

id:kkkkkkkkさんとartonさんのを見て「冴子先生素数」を作りました。作ったといっても大半はartonさんのを写しただけですけれど…。

#!/usr/local/bin/ruby -Ks
require 'win32ole'

class Agent
  PATH = "C:\\Program Files\\Microsoft Office\\OFFICE10\\SAEKO.ACS"
  def initialize(path=PATH)
    agent = WIN32OLE.new("Agent.Control")
    agent.connected = true
    r = agent.Characters.load("name", path)
    while r.status != 0 && r.status != 1
      puts 'loading...'
    end
    @agent = agent.Characters.Character("name")
    @agent.Activate(2);
    @agent.show();
  end
  def say(msg)
    @agent.moveTo 200, 200, 1000
    # @agent.speak msg
    @agent.think msg
    @agent.play "ALERT"
  end
  def bye
    @agent.hide();
  end
end

def prime(n = 100, &block)
  is_prime = Array.new(n + 1, true)
  is_prime[0] = false
  is_prime[1] = false
  (2..n).each do |p|
    next unless is_prime[p]
    block.call(p)
    k = p + p
    while k <= n
      is_prime[k] = false
      k += p
    end
  end
  is_prime
end

agent = Agent.new
prime(100) do |p|
  agent.say "#{p}, "
end
gets
agent.bye

追記:http://arton.no-ip.info/diary/20060621.html#p02 を読んで、もう少し考えなくちゃいけないような気がしてきましたが、もう眠いので寝ます。おやすみなさい。