36 karma · joined Sep 7, 2011 (15y ago) · 17 submissions
comment 12y ago · link · parent
def choose_coin
rand < 0.001 ? 1 : 0.5
end
def flip_coin(coin)
rand < coin ? :heads : :tails
end
def all_10_heads?(coin)
10.times { return false if flip_coin(coin) == :tails }
true
end
next_flip = { :heads => 0, :tails => 0 }
1000000.times do
coin = choose_coin
next unless all_10_heads? coin
next_flip[flip_coin(coin)] += 1
end
puts next_flip[:heads].to_f / (next_flip[:heads] + next_flip[:tails])comment 13y ago · link · parent
comment 13y ago · link · parent
comment 13y ago · link · parent
I imagine an advocate of core.async would argue that they have a good analog for canceled promises, though, namely closing channels. On the other hand, closed channels will still yield nil when read from; the procedures trying to read from a closed channel would need to check for that.
comment 13y ago · link · parent
comment 13y ago · link · parent
12.
The Classic Buffer Overflow Attack(blog.8thlight.com ↗)
2 points · by mag487 · 14y ago · discuss
comment 14y ago · link · parent
comment 14y ago · link · parent
comment 14y ago · link · parent