Newer
Older
Ruby / pi.rb
@AKIBA Hiroki AKIBA Hiroki on 16 Nov 2024 238 bytes 2024-11-16 21:28:30
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
def pi(num)
  in_circle=0
  num.times do
    srand()
    x = rand()
    y = rand()
    if x*x+y*y<=1
      in_circle+=1
    end
  end
  pi=(in_circle/num.to_f)*4
  return(pi)
end
puts(pi(10000))