Last active
June 24, 2016 18:32
-
-
Save lsitters/5903b2052815c10a30a37d7e1f7ea315 to your computer and use it in GitHub Desktop.
HackerRank : Sherlock and The Beast
This file contains 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
/* | |
* @desc https://www.hackerrank.com/challenges/sherlock-and-the-beast | |
* @param integer n | |
* @return array length of n filled with 5s || 3s or False | |
*/ | |
function decentNumber (n) { | |
var head, | |
c = n/3, | |
newN = n-5; | |
if(Number.isInteger(c)){ | |
return Array(n).fill(5); | |
} | |
for(var i = c; i > 0; i--){ | |
if(newN >= 0){ | |
head = decentNumber(newN); | |
if(head){ | |
return head.concat(Array(5).fill(3)); | |
} | |
break; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment