News for hackers. Stuff that matters.
Re:Has Anyone Ever Flipped Heads 76 Times in a Row? by Aaronneyer on Wednesday January 29, 2014 @11:26AM (#7144827)
Flipping 76 in a row is extremely improbable in the physical world, but fortunately we have computers (Where it's still quite improbable).

    [10] pry(main)> choices, tries, current, current_max = [:heads, :tails], 0, 0, 0
    [10] pry(main)> loop do
    [10] pry(main)*   tries += 1
    [10] pry(main)*   flip = choices.sample
    [10] pry(main)*   if flip == :heads
    [10] pry(main)*     current += 1
    [10] pry(main)*   else
    [10] pry(main)*     current = 0
    [10] pry(main)*   end
    [10] pry(main)*   if current > current_max
    [10] pry(main)*     current_max = current
    [10] pry(main)*     puts "New max: #{current_max}, after #{tries} tries"
    [10] pry(main)*   end
    [10] pry(main)* end
Highest so far: "New max: 31, after 77576302 tries"

There are no comments on this comment yet.