-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhex.html
More file actions
230 lines (225 loc) · 7.81 KB
/
hex.html
File metadata and controls
230 lines (225 loc) · 7.81 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>HEX your Brain</title>
<style type="text/css">
html, body {
height:100%;
margin: 0;
padding: 0;
border: 1;
outline: 0;
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
div {
background: #fff;
margin: 0 auto;
width: 300px;
padding: 100px;
text-align: center;
/* border-radius */
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
/* box-shadow */
-webkit-box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
-moz-box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
}
table.stat {
position: absolute;
top: 15px;
right: 15px;
text-align: left;
width: 250px;
}
table.best {
position: absolute;
top: 15px;
left: 15px;
text-align: left;
width: 300px;
}
</style>
<script type="text/javascript">
var lvl = 0;
var a = 0;
var b = 0;
var last = 0;
var best = 0;
var best10 = 0;
var sum = 0;
var att = 0;
var rank = 0;
var lStorage = ('localStorage' in window && window['localStorage'] !== null);
var storedStr = '';
var storedResults = [];
var titles = ["Kid", "Novice", "Student", "Associate", "Bachelor", "Master", "Doctor", "Honoraris Causa Doctor"];
var ranking = [
[15000, 10000, 7000, 4000, 3000, 2300, 1900, 1700],
[40000, 25000, 15000, 8000, 6000, 5000, 4000, 3000],
[120000, 30000, 20000, 12000, 8000, 6000, 5000, 4000],
[150000, 40000, 25000, 15000, 10000, 8000, 6500, 5500],
[180000, 50000, 30000, 20000, 12000, 9000, 7500, 6500],
[200000, 60000, 35000, 25000, 15000, 11000, 9000, 7500],
[220000, 70000, 40000, 30000, 20000, 15000, 10500, 8500],
[250000, 80000, 45000, 35000, 25000, 18000, 14000, 10000],
[400000, 100000, 60000, 50000, 40000, 30000, 25000, 20000]];
function refresh_best10(){
document.getElementById('best').rows[3].cells[1].innerHTML =
(best10+'').slice(0,-4)+'.'+(best10+'').slice(-4);
while((best10 < 10*ranking[lvl-1][rank])&&(rank < 8))rank++;
if(rank > 0) document.getElementById('best').rows[5].cells[1].innerHTML = titles[rank-1];
if(rank < 8) {
var target = ranking[lvl-1][rank];
document.getElementById('best').rows[6].cells[1].innerHTML =
(target+'').slice(0,-3)+'.'+(target+'').slice(-3);
}
else document.getElementById('best').rows[6].cells[1].innerHTML = "Nirvana";
storedResults[lvl-1] = best10;
localStorage["hex"] = JSON.stringify(storedResults);
}
function new_quest(flag){
var now = new Date();
if(flag){
document.getElementById('best').rows[8].cells[1].innerHTML =
now.getFullYear()+'.'+
('0'+(now.getMonth()+1)).slice(-2)+'.'+
('0'+now.getDate()).slice(-2) + ' ' +
('0'+now.getHours()).slice(-2)+':'+
('0'+now.getMinutes()).slice(-2)+':'+
('0'+now.getSeconds()).slice(-2);
var row = document.getElementById('stat').insertRow(1);
var cell = row.insertCell(0);
sum += parseInt(now - last);
att++;
document.getElementById('best').rows[1].cells[1].innerHTML = att;
if(best10 > 0){
if(now - last < best10/10)
cell.style.color = "Green";
if(now - last > 3*best10/10)
cell.style.color = "Red";
}
if((now - last < best)||(best == 0)) {
best = parseInt(now - last);
document.getElementById('best').rows[2].cells[1].innerHTML = best;
cell.style.fontSize = "150%";
}
cell.innerHTML = parseInt(now - last);
cell = row.insertCell(0);
cell.innerHTML = Number(a).toString(16) + '+' +
Number(b).toString(16) + '=' +
Number(a+b).toString(16);
if(document.getElementById('stat').getElementsByTagName("tr").length > 11)
sum -= parseInt(document.getElementById('stat').rows[11].cells[1].innerHTML);
if(document.getElementById('stat').getElementsByTagName("tr").length >= 11){
cell = row.insertCell(-1);
cell.innerHTML = (sum+'').slice(0,-4)+'.'+(sum+'').slice(-4);
document.getElementById('best').rows[4].cells[1].innerHTML = cell.innerHTML;
if((sum < best10)||(best10 == 0)) {
best10 = sum;
refresh_best10();
}
}else{
cell = row.insertCell(-1);
cell.innerHTML = "-";
}
if(document.getElementById('stat').getElementsByTagName("tr").length > 25)
document.getElementById('stat').deleteRow(-1);
}
a = Math.floor((Math.random()*15 + 1) * Math.pow(16,lvl-1));
b = Math.floor((Math.random()*15 + 1) * Math.pow(16,lvl-1));
str_a = Number(a).toString(16)
str_a = (str_a.length % 2 == 1) ? '0'+str_a : str_a;
str_a = str_a.replace(/\B(?=([0-9a-f]{2})+(?![0-9a-f]))/g, " ");
str_b = Number(b).toString(16)
str_b = (str_b.length % 2 == 1) ? '0'+str_b : str_b;
str_b = str_b.replace(/\B(?=([0-9a-f]{2})+(?![0-9a-f]))/g, " ");
last = now;
document.getElementById('q').innerHTML = str_a + '<br />' + str_b;
document.getElementById('inp').value = '';
}
function check(inp){
if(a == 0){
var last_lvl = lvl;
lvl = parseInt(inp.value);
if((lvl >= 1) && (lvl <= 9)){
var now = new Date();
last = 0; sum = 0;
if(last_lvl != lvl){
for(var i = 1; i < 9; i++)
document.getElementById('best').rows[i].cells[1].innerHTML = '';
document.getElementById('best').rows[0].cells[1].innerHTML = lvl;
document.getElementById('best').rows[7].cells[1].innerHTML = now.getFullYear()+'.'+('0'+(now.getMonth()+1)).slice(-2)+'.'+
('0'+now.getDate()).slice(-2) + ' ' + ('0'+now.getHours()).slice(-2)+':'+
('0'+now.getMinutes()).slice(-2)+':'+ ('0'+now.getSeconds()).slice(-2);
best = 0; rank = 0; att = 0;
if (lStorage) {
storedStr = localStorage["hex"];
} else
storedStr = '';
if (typeof storedStr !== 'undefined' && storedStr !== null){
storedResults = JSON.parse(storedStr);
best10 = storedResults[lvl-1];
if(best10 > 0) refresh_best10();
else best10 = 0;
} else best10 = 0;
}
var rows = document.getElementById('stat').rows;
for(; rows.length > 1; )
document.getElementById('stat').deleteRow(-1);
new_quest(0);
}
else
lvl = last_lvl;
}
else {
if(inp.value == Number(a+b).toString(16))
new_quest(1);
if(inp.value == 'q'){
a = 0; b = 0; last = 0;
document.getElementById('q').innerHTML = "Get ready"
document.getElementById('inp').value = '';
}
}
}
</script>
</head>
<body>
<div>
Welcome to HEX your Brain!<br />
Addition in base 16 speed test.<br />
Task and answers in base 16.<br />
Letters abcdef should be in lower case.<br />
Choose level by typing <br />
Number from 1 to 9<br />
Type 'q' to stop.
<p id="q" style="font-family: monospace; font-size: 16pt">Get ready</p>
<input id="inp" type="text" onkeyup='check(this)' autofocus />
<br /><br />
<small><small>
Tips&hints:<br />
- <a href="https://en.wikipedia.org/wiki/Hexadecimal">Theoretical basics wiki</a><br />
- Time measurement is in milliseconds;<br />
- Level you choose corresponds to digit count of the numbers to sum up;
</small></small>
<br /><br />
We also have <br /><a href="./Sum.html">decimal addition test</a><br />
and <a href="./bignum.html">bignum addition test</a>
</div>
<table id="stat" class="stat" ><tr><td>Equation</td><td>Time (ms)</td><td>Average of 10(s)</td></tr></table>
<table id="best" class="best" >
<tr><td>Level</td><td></td></tr>
<tr><td>Attempts</td><td></td></tr>
<tr><td>Best one</td><td></td></tr>
<tr><td>Best avg of 10</td><td></td></tr>
<tr><td>Last avg of 10</td><td></td></tr>
<tr><td>Title</td><td></td></tr>
<tr><td>Next mark</td><td></td></tr>
<tr><td>First Attempt</td><td></td></tr>
<tr><td>Last Attempt</td><td></td></tr>
</table>
</body>
</html>