function bulbs(arr){
var switched = 0;
for(var i = 0; i < arr.length; i++){
var initial = arr[i] === 1,
current = (switched % 2 === 1)? !initial:initial;
if(current === false){
switched++;
}
}
return switched;
}