-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2017-09-15.jl
76 lines (69 loc) · 914 Bytes
/
2017-09-15.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function One()
x, y = rand(2)
X = minimum((x, y))
Y = maximum((x, y))
a = X
b = Y - X
c = 1 - Y
if c > a + b
return 0
elseif b > a + c
return 0
elseif a > b + c
return 0
else
return 1
end
end
function Two()
x, y, z = rand(3)
if x > y + z
return 0
elseif y > x + z
return 0
elseif z > x + y
return 0
else
return 1
end
end
function Three()
x, y = rand(2)
X = minimum((x, y))
Y = maximum((x, y))
assert(X != Y)
a = X^2
b = (Y - X)^2
c = (1 - Y)^2
if c > a + b
return 0
elseif b > a + c
return 0
elseif a > b + c
return 0
else
return 1
end
end
function Four()
x, y, z = rand(3)
X = x^2
Y = y^2
Z = z^2
if Z > X + Y
return 0
elseif Y > X + Z
return 0
elseif X > Y + Z
return 0
else
return 1
end
end
t = 0
n = 10000000
for i in 1:n
t += Four()
end
avg = t/n
display(avg)