Created
December 18, 2011 05:19
-
-
Save ishiduca/1492449 to your computer and use it in GitHub Desktop.
任意の順番で「+5」か「*3」して、任意の値にする過程を示す 初期値は「1」
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 findSequence (goal) { | |
var find = function (start, history) { | |
return (start === goal) ? history : | |
(start > goal) ? null : | |
find(start + 5, "(" + history + " + 5)") || | |
find(start * 3, "(" + history + " * 3)"); | |
}; | |
return find(1, '1'); | |
} | |
console.log(findSequence(24)); | |
// (((1 * 3) + 5) * 3) | |
console.log(findSequence(68)); | |
// ((((((1 + 5) + 5) + 5) + 5) * 3) + 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment