Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Takeuchi function - concurrent version
- def tak(x, y, z)
- unless y < x
- z
- else
- tak(tak(x-1, y, z),
- tak(y-1, z, x),
- tak(z-1, x, y))
- end
- end
- def tak2(x, y, z)
- unless y < x
- z
- else
- tak2(tak2(x-1, y, z),
- tak2(y-1, z, x),
- tak2(z-1, x, y))
- end
- end
- require 'benchmark'
- max = (ARGV.shift || 22).to_i
- puts "Max: #{max}"
- puts Benchmark.measure {
- threads = []
- threads << Thread.new do
- p tak(max, 9, 0)
- end
- threads << Thread.new do
- p tak2(max, 9, 0)
- end
- threads.each { |t| t.join }
- }
Add Comment
Please, Sign In to add comment