Created
October 30, 2015 07:34
-
-
Save andyperlitch/cf044e625f359428dbcb 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
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| </style> | |
| <script> | |
| function findSquareset(n, divisor) { | |
| if (!divisor) { | |
| divisor = 1; | |
| } | |
| // Result array | |
| var result = []; | |
| // Let s be the square of the floor of the square root of n/divisor | |
| var chunk = Math.pow(Math.floor(Math.sqrt(n/divisor)), 2); | |
| // Add this to result {divisor} times | |
| for (var i = divisor; i > 0; i--) { | |
| result.push(chunk); | |
| } | |
| // Take remainder of n - divisor * chunk | |
| var remainder = n - divisor * chunk; | |
| if (remainder > 0) { | |
| result = result.concat(findSquareset(remainder)); | |
| } | |
| return result; | |
| } | |
| // Create Graph | |
| var svg = d3.select('body').append('svg'); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment