-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
176 lines (169 loc) · 4.49 KB
/
index.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<html>
<head><title>The Got - Got - Need Machine</title>
<link rel="stylesheet" type="text/css" href="!!http://siwhitehouse.co.uk/stickers/serendipity/style/css/style.css">
<style>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tfoot, thead, tr, th, td {
border: 0;
font-family: inherit;
font-size: 100%;
font-style: inherit;
font-weight: inherit;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
}
th {
font-size: 28px;
line-height: 75px;
font-family: 'MarketDecoRegular';
font-weight: normal;
color: #002870;
white-space: nowrap;
}
table {
border: 4px solid;
border-spacing:10px 10px;
border-collapse: separate;
border-color: #009c3b;
border-radius: 25px;
}
tr, td {
border-collapse: collapse;
}
/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: 'MarketDecoRegular';
font-weight: normal;
color: #002870;
}
h1 a,
h2 a,
h3 a,
h4 a,
h5 a,
h6 a {
color: inherit;
}
h1 {
font-size: 32px;
line-height: 34px;
margin-bottom: 14px;
}
h2 {
font-size: 28px;
line-height: 30px;
margin-bottom: 10px;
}
h3 {
font-size: 24px;
line-height: 26px;
margin-bottom: 8px;
}
h4 {
font-size: 20px;
line-height: 22px;
margin-bottom: 4px;
}
h5 {
font-size: 17px;
line-height: 19px;
}
h6 {
font-size: 12px;
line-height: 14px;
}
body {
background: #FFDF00;
line-height: 1;
}
.half-line {
line-height: .5em;
}
</style>
</head>
<?php
/*
Initialise variables
*/
$total = $stickers = $swaps = '';
if (isset($_POST['total'])) {
$total = $_POST['total'];
$stickers = $_POST['stickers'];
$swaps = $_POST['swaps'];
$remainder = $total - $stickers;
$potential_remainder = $total-$stickers-$swaps;
$y= round($total*(log($total) + 0.5772156649)+0.5);
}
function portion ($remainder, $total){
$expected = 0;
for ($x=$remainder; $x>=1; $x--) {
$expected = $expected + ($total/$x);
}
return $expected;
}
?>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<div align="center">
<p>
</p>
<table border="2" align="center" cellpadding="12">
<th colspan="3">The Got-Got-Need Machine</th>
</tr>
<tr><td><h2 align="right">I have got </h2></td><td align="center"> <input type="text" name="stickers" size="5" value="<?php echo $stickers; ?>"> </td><td><h2>stickers</h2></td></tr>
<tr><td><h2 align="right">I have got </h2></td><td align="center"> <input type="text" name="swaps" size="5" value="<?php echo $swaps; ?>"> </td><td><h2>swaps</h2></td></tr>
<tr><td><h2 align="right">I need </h2></td><td align="center"> <input type="text" name="total" size="5" value="<?php echo $total; ?>"> </td><td><h2>stickers <br> in total</h2></td></tr>
<tr><td> </td><td align="center"> <input type="submit" value="Calculate"> </td><td> </td></tr>
</table>
</form>
<br>
<?php
if (isset($_POST['total'])) {
echo '<div id="results" style="text-align:center">';
echo '<h3>';
echo "To collect all $total stickers you should expect to buy ";
echo "$y stickers, without swapping";
echo "<br>";
echo "<br>";
echo "To get the remaining $remainder stickers you should expect to buy ";
echo round (portion($remainder, $total));
echo " more stickers.";
echo "<br>";
echo "<br>";
if ($potential_remainder > 0) {
echo "If you trade your $swaps swaps, you'll only have ";
echo $potential_remainder;
echo " left to collect";
echo "<br>";
echo "<br>";
echo "To get those, you'd only expect to have to buy ";
echo round(portion($potential_remainder, $total));
echo " more stickers. <br><br> Best get swapping!<br>";
} else {
echo 'If you managed to swap ' . ($total - $stickers) . ' of the ' . $swaps . ' tickets you have spare, you would have everything!<br><br>';
echo 'Good luck in swapping!';
}
echo '</h3>';
echo '<br><br><br><br>';
echo '<h4>The Got-Got-Need Machine is a Data Unlocked production</h4>';
echo '<a href = "http://dataunlocked.co.uk"><img src = "http://dataunlocked.co.uk/wp-content/uploads/2014/02/data-unlocked-logo-header-2.png" width="160" height="60"></a>';
echo '</div>';
}
?>
</div>
</body>
</html>