(state: Tape)
| 46 | } |
| 47 | |
| 48 | function evolve(state: Tape) { |
| 49 | const newState: Tape = []; |
| 50 | if (typeof width === "string") width = parseInt(width); |
| 51 | for (let i = 0; i < width; i++) { |
| 52 | const left = i > 0 ? state[i - 1] : 0; |
| 53 | const center = state[i]; |
| 54 | const right = i < width - 1 ? state[i + 1] : 0; |
| 55 | |
| 56 | const pattern: TapeValue = applyRule110(left, center, right); |
| 57 | log(`${i-1}${format([left])} ${i}${format([center])} ${i+1}${format([right])} ${pattern}`) |
| 58 | newState.push(pattern); |
| 59 | } |
| 60 | |
| 61 | return newState; |
| 62 | } |
| 63 | |
| 64 | console.log(`\nUSER:\n${state.join(" ")}\n${width}\n${generations}`) |
| 65 | console.log("\nASSISTANT:") |
no test coverage detected