Last active
August 29, 2015 14:16
-
-
Save fmundaca/3cc60b861160c55437e4 to your computer and use it in GitHub Desktop.
Algoritmo resuelto
This file contains 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 playing(list,times){ | |
var newArray = []; | |
var x = 0; | |
for(i=0;i<list.length;i++){ | |
// console.log(list.length); | |
if(times > 0){ | |
if(list.length%2 == 1){ | |
// impar debemos eliminar desde el 0 | |
if(i>0) | |
x = (2*i); | |
else | |
x = 0; | |
}else{ | |
//arreglo es par | |
x = (2*i)+1 | |
} | |
}else{ | |
x= list[(2*i)]; | |
} | |
if(list[x]!= undefined) | |
newArray.push(list[x]); | |
} | |
console.log(newArray); | |
return newArray; | |
} | |
function playTheGame(number){ | |
var list = []; | |
for(var i=0;i<number;i++){ | |
list.push(i); | |
} | |
console.log(list); | |
times = 0; | |
while(list.length > 1){ | |
list = playing(list,times); | |
times++; | |
} | |
} | |
playTheGame(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i don't know if this work well in all the cases, i don't have the time to probe xD