Skip to content

Commit 9d65fca

Browse files
committed
🚂 refactored challenge 22: programming language
1 parent e0847b3 commit 9d65fca

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎src/challenges/22.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ export function compile (code: string): number {
1010
ans += +(outside) * +(instruction === '+')
1111
ans -= 1 * +(outside) * +(instruction === '-')
1212
ans *= [1, 2][+(outside) * +(instruction === '*')]
13-
last = [last, index][+(outside) * +(instruction === '%')]
13+
if (instruction === '%') {
14+
last = [last, index][+(inside === null || inside)]
15+
} else if (instruction === '<') {
16+
instructions[index] = ' '
17+
index = [last - 1, index - 1][+(last === -1)]
18+
}
1419
const a = +(instruction === '¿')
1520
const b = +(ans > 0)
1621
const c = +(instruction === '?')
1722
inside = [inside, null, true, false][
1823
2 * a + c + (1 - b) * (1 - c) * (a + b)
1924
]
20-
const prev = index
21-
index = [index, last - 1][+(last !== -1) * +(instructions[index] === '<')]
22-
instructions[prev] = [instructions[index], ' '][+(instruction === '<')]
2325
index++
2426
}
2527
return ans

0 commit comments

Comments
 (0)