Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Created November 23, 2015 10:10
Show Gist options
  • Save dongyuwei/0bfa48e6e80b74214c8f to your computer and use it in GitHub Desktop.
Save dongyuwei/0bfa48e6e80b74214c8f to your computer and use it in GitHub Desktop.
code snippet of <<Eloquent JavaScript>> by Marijn Haverbeke
function findSolution(target){
function find(start, history){
if(start > target){
return null;
}
if(start === target){
return history;
}
return find( start * 3, '(' + history + ') * 3' ) || find( start + 5, '(' + history + ') + 5' );
}
return find(1, '1');
}
findSolution(24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment