-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
94 lines (86 loc) · 1.85 KB
/
index.js
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
new Vue({
el: '#paradoks',
data() {
return {
step: 0,
result: 0,
maxSize: 2048,
maxSizeInput: 2048
};
},
computed: {
totalStep() {
return Math.ceil(Math.log2(this.maxSize));
},
paradoks() {
const paradoks = [];
let loop = true;
let grupSize = 1;
let cardSize = 0;
let next = false;
let maxLimit = 0;
while (loop) {
paradoks[cardSize] = [];
for (let i = grupSize; i <= this.maxSize; i++) {
if (i % grupSize == 0) {
next = !next;
}
if (next) {
paradoks[cardSize].push(i);
}
}
cardSize++;
grupSize *= 2;
next = false;
if (cardSize == this.totalStep) {
loop = false;
}
}
return paradoks;
},
currentCard() {
return this.paradoks[this.step];
},
resultText() {
if (this.result > 0 && this.result) {
return `😎😎 ${this.result} 😎😎`;
}
return `Whoops! '${this.result}' is found.`;
}
},
watch: {
maxSizeInput(value) {
if (value > 3) {
if (value > 5000) {
const res = confirm('Are you sure you want to render more than 5000?');
if (!res) {
return;
}
}
this.maxSize = value;
this.reset();
}
}
},
mounted() {
const extraRuleTag = document.querySelector('#extra-rule');
document.addEventListener('keydown', (e) => {
if (Number.isSafeInteger(parseInt(e.key))) {
extraRuleTag.innerHTML = `[class^="${e.key}"] { background-color: red }`
}
})
},
methods: {
yep() {
this.result += this.paradoks[this.step][0];
this.step++;
},
nope() {
this.step++;
},
reset() {
this.step = 0;
this.result = 0;
}
}
});