Skip to content

Commit e053e22

Browse files
committed
bug fix resposta errada
1 parent e0fc5d2 commit e053e22

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/app/puzzle/puzzle/puzzle.component.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import * as pt_br from '../../../assets/json/pt_br.json';
1111
export class PuzzleComponent implements OnInit {
1212
env = environment.assets;
1313
ask: string;
14-
even: number = 0;
15-
odd: number = 0;
16-
count: number = 0;
1714
position = [];
1815
puzzle: number;
1916
divide: string;
@@ -69,15 +66,13 @@ export class PuzzleComponent implements OnInit {
6966
this.ask = this.langue.even_2;
7067
document.getElementById('even').setAttribute('class', 'even d-none');
7168
if (resp == 'yes') {
72-
this.even++;
7369
this.divide = this.langue.divide;
70+
this.position.push(0);
7471
} else {
75-
this.odd++;
76-
this.position[this.count] = 1;
7772
this.divide = this.langue.sub_divide;
73+
this.position.push(1);
7874
}
7975
document.getElementById('divide').setAttribute('class', 'divide d-block');
80-
this.count++;
8176
}
8277

8378
ok() {
@@ -91,34 +86,19 @@ export class PuzzleComponent implements OnInit {
9186
else document.getElementById('even').setAttribute('class', 'even d-block');
9287
}
9388

94-
pot(a: number, b: number): number {
95-
if (b == 0) return 1;
96-
if (b == 1) return a;
97-
let c: number = 0;
98-
for (let i = 1; i < b; i++) c += a * a;
99-
return c;
100-
}
101-
10289
magic() {
103-
let a = 0;
104-
let b = 0;
105-
if (this.odd == 0) this.puzzle = this.pot(2, this.even);
106-
else {
107-
for (let i = 0; i < this.count; i++) {
108-
if (this.position[i] == 1) b += this.pot(2, i); //impar
109-
}
110-
a = this.pot(2, this.even + this.odd);
111-
this.puzzle = a + b;
112-
console.log(this.puzzle);
90+
let resp = 1;
91+
for (let i = 0; i < this.position.length; i++) {
92+
if (this.position[i] == 1) {
93+
resp *= 2;
94+
resp += 1;
95+
} else resp *= 2;
11396
}
11497
document.getElementById('puzzle').setAttribute('class', 'puzzle d-block');
11598
}
11699

117100
remake() {
118101
this.ask = this.langue.even_1;
119-
this.even = 0;
120-
this.odd = 0;
121-
this.count = 0;
122102
this.puzzle = 0;
123103
this.position = [];
124104
document.getElementById('one').setAttribute('class', 'one d-none');

0 commit comments

Comments
 (0)