-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (56 loc) · 1.83 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Elm Sudoku</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/gh-buttons.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<script src="elm.js"></script>
<script src="js/utilities.js"></script>
<script src="js/admissible_cover.js"></script>
<script src="js/sudoku.js"></script>
<script src="js/sudoku_list.js"></script>
<script>
function main()
{
var rawState;
if (typeof localStorage !== 'undefined') {
rawState = localStorage.getItem('elm-sudoku-state');
}
var ports =
{ storedState : rawState === 'true'
, initialSudoku : newSerializedSudoku()
, newAvailable : null
, solutionAvailable : []
};
var main = Elm.fullscreen(Elm.Main, ports);
if (typeof localStorage !== 'undefined') {
main.ports.requestSaveState.subscribe(function(state) {
localStorage.setItem('elm-sudoku-state', state.toString());
});
}
main.ports.requestNew.subscribe(function() {
main.ports.newAvailable.send(newSerializedSudoku());
});
main.ports.requestSolution.subscribe(function(ssdk) {
if (ssdk === null) {
return;
}
var sdk = new Sudoku(ssdk.n);
ssdk.board.forEach(sdk.set);
var P = sdk.toAdmissibleCoverProblem(), list = [];
P.traverseAdmissibleCovers(sdk.appendSerializedSolution(list), 2);
main.ports.solutionAvailable.send(list);
});
}
function newSerializedSudoku()
{
var l = sudokuList.length, i = Math.floor(Math.random() * l);
return (new Sudoku(3, sudokuList[i])).serialize();
}
main();
</script>
</body>
</html>