Skip to main content
added 652 characters in body
Source Link
Dominic van Essen
  • 37.6k
  • 2
  • 24
  • 61

R, 8484 83 bytes

\(n,r=1e8r=2e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2>pi*2e16/n/2)F=!print(abs(round(x/1e62e6)))

Attempt This Online!Attempt This Online! (but it will time-out before completing), or Attempt a less-accurate version with only 4 million x-axis steps.

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200400 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.
Subtracting the slice-area at each step would require ≈10,000x less steps to achieve the required accuracy, but costs 6 bytes more5 bytes more.

R, 84 bytes

\(n,r=1e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2/n/2)F=!print(abs(round(x/1e6)))

Attempt This Online!

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.
Subtracting the slice-area at each step would require ≈10,000x less steps to achieve the required accuracy, but costs 6 bytes more.

R, 84 83 bytes

\(n,r=2e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*2e16/n)F=!print(abs(round(x/2e6)))

Attempt This Online! (but it will time-out before completing), or Attempt a less-accurate version with only 4 million x-axis steps.

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 400 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.
Subtracting the slice-area at each step would require ≈10,000x less steps to achieve the required accuracy, but costs 5 bytes more.

added 750 characters in body
Source Link
Dominic van Essen
  • 37.6k
  • 2
  • 24
  • 61

R, 84 bytes

\(n,r=1e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2/n/2)F=!print(abs(round(x/1e6)))

Attempt This Online!

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.
Subtracting the slice-area at each step would require ≈10,000x less steps to achieve the required accuracy, but costs 6 bytes more.

R, 84 bytes

\(n,r=1e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2/n/2)F=!print(abs(round(x/1e6)))

Attempt This Online!

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.

R, 84 bytes

\(n,r=1e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2/n/2)F=!print(abs(round(x/1e6)))

Attempt This Online!

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.
Subtracting the slice-area at each step would require ≈10,000x less steps to achieve the required accuracy, but costs 6 bytes more.

Source Link
Dominic van Essen
  • 37.6k
  • 2
  • 24
  • 61

R, 84 bytes

\(n,r=1e8)for(x in -r:r)if((F=F+(r^2-x^2)^.5)>pi*r^2/n/2)F=!print(abs(round(x/1e6)))

Attempt This Online!

Straightforward loop-over-x-values approach, not as elegant as Damian Pavlyshyn's probabilistic approach in R, but produces a single defined output for any input n.

Calculates the area-so-far in 200 million x-axis steps across the pizza, outputting the rounded x-axis value each time it hits the intended slice-area, and resetting the area-so-far back to zero.
Setting the area-so-far back to zero, instead of subtracting the slice-area and keeping the remainder for the next slice, is rather inaccurate, and so necessitates the huge number of x-axis steps to match all the test-cases.