Skip to content

Instantly share code, notes, and snippets.

@nicolas-t
Created December 9, 2012 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas-t/4245491 to your computer and use it in GitHub Desktop.
Save nicolas-t/4245491 to your computer and use it in GitHub Desktop.
<script>
/*variables*/
var stair = [], routes = [], retours = [], sommes = [], result = false;
/*functions*/
function recur(index,parc){
if(index == (stair.length-1) || index == (stair.length-2) ){
retours.push(parc);
}
if(index+1 < stair.length){
parc_a = parc.slice(0);
parc_a.push(stair[index+1]);
recur(index+1, parc_a);
}
if(index+2 < stair.length){
parc_b = parc.slice(0);
parc_b.push(stair[index+2]);
recur(index+2, parc_b);
}
}
function somme(a){
var r = 0;
for( j = 0; j< a.length; j++){
r += a[j];
}
if(result === false || result< r){
result = r;
}
return r;
}
function checkio(p){
stair = p;
recur(-1,[0]);
for( i = 0; i< retours.length; i++){
sommes[i] = somme(retours[i]);
console.log(retours[i]);
console.log(sommes[i]);
}
console.log('et le resultat est...'+result);
}
/*procedure*/
checkio([-21, -23, -69, -67, 1, 41, 97, 49, 27]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment