Skip to content

Commit 3736d3c

Browse files
committed
Used | Bitwise OR and ^= (Bitwise XOR) operators in calculating next Elementary Generation over Addition + and Subtraction -=
1 parent cdd28e9 commit 3736d3c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Cellular-Automata/Elementary.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ export function getNextElementaryGeneration (generation, rule) {
8484
const RIGHT_DEAD = 1 // 001 in binary
8585

8686
for (let i = 0; i < generation.length; i++) {
87-
let neighborhoodValue = LEFT_DEAD + MIDDLE_DEAD + RIGHT_DEAD
87+
let neighborhoodValue = LEFT_DEAD | MIDDLE_DEAD | RIGHT_DEAD
8888

8989
if (i - 1 > 0 && generation[i - 1] === 1) {
90-
neighborhoodValue -= LEFT_DEAD
90+
neighborhoodValue ^= LEFT_DEAD
9191
}
9292

9393
if (generation[i] === 1) {
94-
neighborhoodValue -= MIDDLE_DEAD
94+
neighborhoodValue ^= MIDDLE_DEAD
9595
}
9696

9797
if (i + 1 < generation.length && generation[i + 1] === 1) {
98-
neighborhoodValue -= RIGHT_DEAD
98+
neighborhoodValue ^= RIGHT_DEAD
9999
}
100100

101101
output[i] = ruleData[neighborhoodValue]

0 commit comments

Comments
 (0)