¶ jay's stupid ass riddle
Posted 21 years, 8 months ago on May 12, 2004
#!/usr/bin/python import sys import random if len(sys.argv) < 2: sys.exit(2) random.seed() successes = 0 trials = int(sys.argv[1]) for i in range(trials): x = random.random() y = random.random() if ( min(x,y) < 0.5 and \ max(x,y) - min(x,y) < 0.5 and \ 1 - max(x,y) < 0.5 ): successes += 1 print float(successes) / trials # python jayriddle.py 1000000 0.25026 1 / 4 update: Okay, so jay objected to my empirical solution, and then I posted some really arrogant solution that was supposed to be like, "you're a tool. see how easy it is?" but then that was completely wrong and so jay (rightfully) called me a dumbass and then I started thinking about it the right way and realized sonic's solution is about as simple as it gets so I'm just gonna stick with my python script.
Re: jay's stupid ass riddle
Albert, gan4 ni3 de diannao...I hate your computer. By the way, just in case you didn't know it, your second solution is incorrect. The way I stated the conditions is the simplest way of describing the problem rigorously. Your conditions are too broad (ie, what if X=0.1 and Y=0.9, then you can't create a triangle), and your probability is wrong too (should be .5*.5 + .5*.5 = 0.5), and somehow those two errors cancel each other to get the correct answer. But it's all because of your stupid computer.
Comments disabled until the spammers go away. I hope you comment spammers all die horrible deaths and are forced to delete endless streams of comment spam in your days in purgatory. |
Recently
drifting orcasUrban Challenge log files... Thesis Proposal My book has been pirated? DGC NQE updates Archives
November 2003 (3)
December 2003 (11) January 2004 (11) February 2004 (14) March 2004 (9) April 2004 (9) May 2004 (10) June 2004 (13) July 2004 (7) August 2004 (11) September 2004 (7) October 2004 (12) November 2004 (8) December 2004 (6) January 2005 (7) February 2005 (6) March 2005 (6) April 2005 (5) May 2005 (6) June 2005 (2) July 2005 (3) August 2005 (6) September 2005 (2) October 2005 (5) November 2005 (3) December 2005 (4) January 2006 (4) February 2006 (4) March 2006 (3) April 2006 (2) May 2006 (4) June 2006 (1) July 2006 (1) August 2006 (1) September 2006 (1) October 2006 (4) December 2006 (2) January 2007 (3) July 2007 (2) August 2007 (2) September 2007 (3) October 2007 (5) February 2008 (1) May 2008 (1) June 2008 (1) July 2008 (1) |