24
2
Write a program or function that given an integer radius r returns the number of unit squares the circle with radius r centered at the origin passes through. If the circle passes exactly through a point on the grid that does not count as passing through the adjacent unit squares.
Here's an illustration for r = 5:
Illustration by Kival Ngaokrajang, found on OEIS
Examples:
0 → 0
1 → 4
4 → 28
5 → 28
49 → 388
50 → 380
325 → 2540
5524 → 44180
5525 → 44020
OEIS - A242118 – Luke – 2017-01-30T14:40:59.760
@Luke I just went looking for this, but it seems to use a slightly different definition (at least it doesn't agree on
N = 50
). – Martin Ender – 2017-01-30T14:41:31.787On the other hand, your illustration is clearly taken from https://oeis.org/A242118/a242118_1.pdf (which you should probably cite...)
– Martin Ender – 2017-01-30T14:43:49.563@MartinEnder The OEIS numbers are wrong, I have a draft in review as we speak. – orlp – 2017-01-30T14:46:33.910
The unit squares will have integer coordinates at their edges, yes? – Dennis – 2017-01-30T15:42:21.727
@Dennis Yes, although I'm interested what made you think otherwise. – orlp – 2017-01-30T15:45:56.560
It seems implied, but the spec doesn't actually say it. – Dennis – 2017-01-30T15:46:35.190
Can you explain how you arrived at the numbers for the case 50 and up, since they're different from the OEIS and what I'm getting? – smls – 2017-01-30T17:19:14.477
1@smls By counting in the bounding square. Make sure that you do not count squares where the circle only touches a corner. The numbers on OEIS are wrong, I have a correction in review right now. – orlp – 2017-01-30T17:28:07.737
@orlp: Got it now. May I suggest adding the test-case
5 -> 28
, which also has squares where the circle only touches a corner, but is easier to visualize / reason about than ones with large radii? – smls – 2017-01-30T18:12:50.410@smls Sure, but that's the illustration :) – orlp – 2017-01-30T18:55:35.473
2I have a sudden urge to build domes in minecraft again... – Patrick Roberts – 2017-01-30T19:10:14.700
4 → 28\n5 → 28
um... – user41805 – 2017-01-30T19:36:02.303@KritixiLithos Wait until you see 49/50 :) – orlp – 2017-01-30T19:41:14.570
Related with a solid circle. – xnor – 2017-01-30T20:32:42.680
2Are you a fellow 3Blue1Brown viewer? – nitro2k01 – 2017-01-31T01:11:36.130
@nitro2k01 Yes :) – orlp – 2017-01-31T10:11:20.833