-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkiller.html
141 lines (135 loc) · 3.83 KB
/
killer.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Killer Sudoku Partitions</title>
<link href="bootstrap.min.css" rel="stylesheet">
<script src="jquery-3.6.0.min.js"></script>
<style>
body {
touch-action: manipulation;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
max-width: 390px;
}
.button {
float: left;
width: 34px;
text-align: center;
vertical-align: text-bottom;
line-height: 50px;
background: #eee;
margin: 2px;
font-family: monospace;
font-size: 20px;
}
.totals {
padding: 2px;
display: table;
}
.total.selected {
background: #f00;
}
.partitions {
margin-top: 10px;
padding: 2px;
display: table;
}
.partition.selected {
background: #f00;
}
.partition.impossible {
background: #ccc;
color: #aaa;
}
.options {
margin-top: 10px;
padding: 2px;
display: table;
}
.option {
width: 123px;
}
.option.selected {
background: #ccc;
color: #aaa;
}
</style>
</head>
<body>
<div class="totals"></div>
<div class="partitions"></div>
<div class="options"></div>
<script>
let option_table = [];
genOptions();
let selected_total = 0;
let selected_partition = 0;
let totals = $('.totals').on("mousedown", ".total", function() {
$('.total.selected').removeClass('selected');
$(this).addClass('selected');
selected_total = parseInt($(this).text(), 10);
partitions.children().each(function () {
let el = $(this);
const partition = parseInt(el.text(), 10);
el.toggleClass('impossible', getOptions(selected_total, partition).length === 0);
});
showOptions();
});
let partitions = $('.partitions').on("mousedown", ".partition", function() {
let el = $(this);
if (el.hasClass('impossible')) {
return;
}
$('.partition.selected').removeClass('selected');
el.addClass('selected');
selected_partition = parseInt(el.text(), 10);
showOptions();
});
let options = $('.options').on("mousedown", ".option", function() {
$(this).toggleClass('selected');
});
for (let n = 0; n <= 45; n++) {
totals.append('<div class="button total">' + n + '</div>');
}
for (let n = 1; n <= 9; n++) {
partitions.append('<div class="button partition">' + n + '</div>');
}
function showOptions() {
options.empty();
for (let option of getOptions(selected_total, selected_partition)) {
options.append('<div class="button option">' + option.join('') + '</div>');
}
}
function genOptions(digit=1, total=0, list=[], add=false) {
if (add) {
if (!option_table[total]) {
option_table[total] = [];
}
if (!option_table[total][list.length]) {
option_table[total][list.length] = [];
}
option_table[total][list.length].push(list);
}
if (digit > 9) {
return;
}
genOptions(digit + 1, total + digit, [...list, digit], true);
genOptions(digit + 1, total, list);
}
function getOptions(total, partition) {
if (!option_table[total]) {
return [];
}
return option_table[total][partition] || [];
}
</script>
</body>
</html>