If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
I start with the example of N=150. The algorithm:
- Set sum to 0.
- Loop from n=1 to N.
- if n is divisible by 3 or 5, add n to sum.
Things to consider:
- Do I want to match the algorithm perfectly? Then there wouldn't be different colours or levels, just "Add" or "Ignore".
- Or do I want it to point out problems? E.g., if you split up Step 2.1 into two steps, "Check %3==0" and "Check %5==0", then you'll add multiples of 15 twice, hence the red colour for 15, 30, 45, etc.
- A cooler algorithm might be to loop through multiples of 3 (instead of 1 to N) and 5 directly, add them, then subtract multiples of (3*5), like set addition and subtraction. But that's not the easiest solution, which I think should be my goal.
- The way D3 handles data is more complicated than it seems.
- A transition applied to a dataset will affect all elements at the same time, except I want to show a loop.
- So the "var i = test.shift()" on line 92 is a bit hacky, but will loop through the elements of a copied version of the dataset.
- Then it redraws every line for every time through the loop.
- And after one loop is finished, it calls a transition on the transition recursively.
- I also don't want it to stall on the last element, so I add an invisible line to the end, because the number of loops is determined by the number of elements.
Some resources: Project Euler Problem #1, Help with SVG Labels, and many examples from Mike Bostock.