News for hackers. Stuff that matters.
Re:Coin Flip Brain Teaser by aidenn0 on Friday July 24, 2009 @07:23PM (#722675)
The following lisp simulation gets numbers on about the same order of magnitude:

    (defun flip () (if (< (random 100) 49) nil t))

    (defun game (n d)
      (declare (optimize speed))
      (if (>= d 10) n
        (if (flip)
          (game (incf n) (incf d))
          (game (incf n) (decf d)))))
  
    (print (nth 1000 (sort (loop for i from 1 to 100000
                    collect (game 0 0)) #'> )))

There are no comments on this comment yet.