Skip to content

Instantly share code, notes, and snippets.

@lsitters
Last active June 24, 2016 18:32
Show Gist options
  • Save lsitters/5903b2052815c10a30a37d7e1f7ea315 to your computer and use it in GitHub Desktop.
Save lsitters/5903b2052815c10a30a37d7e1f7ea315 to your computer and use it in GitHub Desktop.
HackerRank : Sherlock and The Beast
/*
* @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