Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Javascript solution, slightly brute force:
- function sumOfDigitsOfNumbers(n1, n2) {
- return (n1+"" + n2+"").split("").reduce(function(a, b){
- return parseInt(a, 10) + parseInt(b, 10);
- }, 0);
- }
- var totalSpaces = 1;
- for(var y=0;y<299;++y) {
- for(var x=0;x<299;++x) {
- if (sumOfDigitsOfNumbers(x, y) > 19) break;
- totalSpaces += 8;
- }
- }
- console.log("The total number of spaces that are accessible to the monkey are: " + totalSpaces + ". Which is, sadly, not a prime number. Bummer.");
- // Why only count values up to 298?
- // 298 adds to 19, so this would be the max number in any direction then we just don't count any values that make it go above 19 as it can only travel 1 space @ a time.
- // Theoretically 1000 is a possible number, but 299 being before it makes it unreachable
- // therefore: the maximal dataset consists of only 298x298 (88804) possible numbers
- // This cycle exists 8 times
- // 1 for vertical, 1 for horizontal in 4 quadrants of the graph
- // 8 x eighth of the limited, walked dataset + 1 initial space = 8 x 9471 + 1 = 75769
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement