Skip to content

Instantly share code, notes, and snippets.

@fmundaca
Last active August 29, 2015 14:16
Show Gist options
  • Save fmundaca/3cc60b861160c55437e4 to your computer and use it in GitHub Desktop.
Save fmundaca/3cc60b861160c55437e4 to your computer and use it in GitHub Desktop.
Algoritmo resuelto
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]);
@fmundaca
Copy link
Author

fmundaca commented Mar 6, 2015

i don't know if this work well in all the cases, i don't have the time to probe xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment