-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenges.js
More file actions
59 lines (56 loc) · 1.78 KB
/
challenges.js
File metadata and controls
59 lines (56 loc) · 1.78 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
var binary = function() {
var pad = function(n, width) {
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}
var ops=["&", "|", "^"];
var num1=Math.floor(Math.random()*255);
var num2=Math.floor(Math.random()*255);
var bin1 = pad(num1.toString(2),8);
var bin2 = pad(num2.toString(2),8);
var op = Math.floor(Math.random()*3);
while (op==3)
op = Math.floor(Math.random()*3);
var res = eval (num1.toString() + " " + ops[op]+" "+num2.toString());
return {
"chall": bin1 + " " + ops[op] + "\n" + bin2,
"res": res
}
}
var hex = function() {
return {
"chall":"hex",
"res": 1
}
}
exports.challenges = {
"binary": {
"rules":"Give me the result with B <result> as a binary",
"description": "Solve a binary operation between two numbers",
"def": "B",
"delay":3000,
"chall": binary,
"num_sol": 1,
"solver": function(s, res) {
var x = parseInt(s[0], 2);
if (!isNaN(x))
if (x === res)
return true;
return false;
}
},
"hex": {
"rules":"Give me the result with H <result> as a number",
"description": "Convert a number from hex to decimal form",
"def": "H",
"delay":10000,
"chall": hex,
"num_sol": 1,
"solver": function(s, res) {
if (s[0] == '1')
return true;
else
return false;
}
}
}