1 ! Copyright (c) 2008 Eric Mertens.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.functions sequences ;
6 ! http://projecteuler.net/index.php?section=problems&id=100
11 ! If a box contains twenty-one coloured discs, composed of fifteen blue discs
12 ! and six red discs, and two discs were taken at random, it can be seen that
13 ! the probability of taking two blue discs, P(BB) = (15/21)*(14/20) = 1/2.
15 ! The next such arrangement, for which there is exactly 50% chance of taking
16 ! two blue discs at random, is a box containing eighty-five blue discs and
17 ! thirty-five red discs.
19 ! By finding the first arrangement to contain over 10^12 = 1,000,000,000,000
20 ! discs in total, determine the number of blue discs that the box would contain.
26 : euler100 ( -- answer )
28 [ dup dup 1- * 2 * 10 24 ^ <= ]
29 [ tuck 6 * swap - 2 - ] while nip ;
31 ! TODO: solution needs generalization
33 ! [ euler100 ] 100 ave-time
34 ! 0 ms ave run time - 0.14 SD (100 trials)