-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path24.html
57 lines (53 loc) · 1.71 KB
/
24.html
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
<!DOCTYPE html>
<html>
<title>24 Game Solver: gives you all dissimilar solutions.</title>
<body>
<input type="text" id="input_a" value="A" size="2" onclick="this.select()" onkeydown="checkEnter(event)">
<input type="text" id="input_b" value="J" size="2" onclick="this.select()" onkeydown="checkEnter(event)">
<input type="text" id="input_c" value="Q" size="2" onclick="this.select()" onkeydown="checkEnter(event)">
<input type="text" id="input_d" value="K" size="2" onclick="this.select()" onkeydown="checkEnter(event)">
<input type="button" value="Solve" onclick="clickSolve()"><br>
<span id="output"></span>
<script type="text/javascript" src="24-expressions.js"></script>
<script type="text/javascript" src="24.js"></script>
<script type="text/javascript"><!--
function parse(s) {
switch (s.toUpperCase()) {
case "A":
return 1;
case "J":
return 11;
case "Q":
return 12;
case "K":
return 13;
}
var n = parseInt(s);
if (isNaN(n) || n < 1 || n > 13) {
alert("Invalid Input: " + s);
return 0;
}
return n;
}
function checkEnter(event) {
if (event.keyCode == 13) {
clickSolve();
}
}
function clickSolve() {
var ns = [parse(input_a.value), parse(input_b.value), parse(input_c.value), parse(input_d.value)];
// if (ns.indexOf(0) >= 0) { // not supported by IE6
if (ns[0] == 0 || ns[1] == 0 || ns[2] == 0 || ns[3] == 0) {
return false;
}
var solutions = solve(ns);
var s = solutions.length + " solution(s)<br>";
for (var i = 0; i < solutions.length; i ++) {
s += render(solutions[i]) + " = 24<br>";
}
output.innerHTML = s;
return false;
}
--></script>
</body>
</html>