#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
#timeoutとモンテカルロ法〜
require'timeout'
min=[0,0]
begin
  Timeout.timeout(5){
    loop do
      x=rand
      y=rand
      x**2+y**2<1.0?min[0]+=1: min[1]+=1
    end
  }
rescue Timeout::Error
  puts("timeout")
end

printf("%d: pi=%f\n",min[0]+min[1],min[0]*4.0/(min[0]+min[1]))
