Created
September 6, 2015 06:45
-
-
Save wulab/96e400f68169db9dc8d1 to your computer and use it in GitHub Desktop.
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 findSolution(target) { | |
| function find(start, history) { | |
| if (start == target) | |
| return history; | |
| else if (start > target) | |
| return null; | |
| else | |
| return find(start + 5, "(" + history + " + 5)") || | |
| find(start * 3, "(" + history + " * 3)"); | |
| } | |
| return find(1, "1"); | |
| } | |
| console.log(findSolution(24)); | |
| // → (((1 * 3) + 5) * 3) |
Author
wulab
commented
Sep 6, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment