Created
April 1, 2019 14:19
-
-
Save sanketmaru/9cf77386dc85a166960dc38663d1cfb2 to your computer and use it in GitHub Desktop.
Rosetta 100 Doors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFinalOpenedDoors (numDoors) { | |
// Good luck! | |
var door = { | |
state: false | |
}; | |
var doors = []; | |
var counter = 1; | |
for(var i=0;i<numDoors;i++) { | |
} | |
while(counter < numDoors) { | |
doors = []; | |
for(var i=counter;i<=numDoors;counter+=i) { | |
if(counter === 1) { | |
door.num = i; | |
doors.push(door); | |
} else { | |
door.state = !door.state; | |
} | |
console.log(doors); | |
} | |
counter = counter + 1; | |
} | |
var result = []; | |
for(var i=0;i<doors.length - 1;i++) { | |
result.push(doors.num); | |
} | |
console.log(result); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment