write a small JS function that, given an array of 0's and 1's, computes the next step of…
- User
write a small JS function that, given an array of 0's and 1's, computes the next step of the array, by applying a rewrite rule that sums 3 neighbors (mod 2), wrapping around (cell 0 interacts with last cell)
Assistant
function nextStep(arr) { const newArr = new Array(arr.length); for (let i = 0; i < arr.length; i++) { const prev = arr[(i - 1 + arr.length) % arr.length]; const curr = arr[i]; const next = arr[(i + 1) % arr.length]; newArr[i] = (prev + curr + next) % 2; } return newArr; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.