Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random Algebra

Name: Anonymous 2016-08-05 16:07

Given functions
f(a,b) = random(a) < random(b)
and
g(a,b) = a < random(a+b)

which if of them is more likely to result into 1, if random(n) returns arbitrary number in range of [0;n)?

Justify your answer.

Name: Anonymous 2016-08-05 17:38

(defun f (a b)
(if (< (random a) (random b)) 1 0))

(defun g (a b)
(if (< a (random b)) 1 0))

(defun count-fn-one (fn up-to)
"Counts how many times FN is 1"
(loop for i from 1 to up-to summing
(loop for j from 1 to up-to
summing (funcall fn i j))))

(defun which-is-more-one? (iters)
(if (> (count-fn-one #'f iters)
(count-fn-one #'g iters))
'F 'G))


...and the winner is:

* (which-is-more-one? 100)
F
* (which-is-more-one? 1000)
F
* (which-is-more-one? 10000)
F

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List