-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2018-03-30.jl
79 lines (70 loc) · 1.5 KB
/
2018-03-30.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
77
78
79
struct Card
color::Int
value::Int
end
global deck = Array{Card, 1}()
for color = 1:2
for value = 1:13
for i = 1:2
push!(deck, Card(color, value))
end
end
end
function draw_cards()
order = randperm(52)
first_pass = deck[order[1:7]]
second_pass = deck[order[8:15]]
return first_pass, second_pass
end
function legal_move(card1::Card, card2::Card)
if card1.color == card2.color
return false
elseif abs(card1.value - card2.value) == 1
return true
else
return false
end
end
function check_first_pass(cards::Array{Card, 1})
for i = 1:6
for j = (i + 1):7
if legal_move(cards[i], cards[j])
return false
end
end
end
return true
end
function check_second_pass(cards1::Array{Card, 1}, cards2::Array{Card, 1})
for card1 in cards1
for card2 in cards2
if legal_move(card1, card2)
return false
end
end
end
return true
end
function impossible_game()
top_cards, deck_cards = draw_cards()
if check_first_pass(top_cards)
if check_second_pass(top_cards, deck_cards)
return 1
end
end
return 0
end
function simulate_games(n::Int)
total = 0
for i = 1:n
total += impossible_game()
end
return total / n
end
function approx()
product = 1
for i = 1:(21 + 56)
product = product * (1279 - i) / (1327 - i)
end
return product
end