Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

##AWK, 90 bytes

AWK, 90 bytes

{z=1ドル*1ドル
for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1

Usage:

awk '{z=1ドル*1ドル
 for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
 if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1' <<< 5525

Just a simple search through quadrant 1 to find all boxes that will intersect the circle. Symmetry allows for the multiply by 4. Could go from -1ドル to 1ドル, but that would take a more bytes and be less efficient. Obviously this is not the most time efficient of algorithms, but it only takes about 16 seconds to run the 5525 case on my machine.

##AWK, 90 bytes

{z=1ドル*1ドル
for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1

Usage:

awk '{z=1ドル*1ドル
 for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
 if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1' <<< 5525

Just a simple search through quadrant 1 to find all boxes that will intersect the circle. Symmetry allows for the multiply by 4. Could go from -1ドル to 1ドル, but that would take a more bytes and be less efficient. Obviously this is not the most time efficient of algorithms, but it only takes about 16 seconds to run the 5525 case on my machine.

AWK, 90 bytes

{z=1ドル*1ドル
for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1

Usage:

awk '{z=1ドル*1ドル
 for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
 if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1' <<< 5525

Just a simple search through quadrant 1 to find all boxes that will intersect the circle. Symmetry allows for the multiply by 4. Could go from -1ドル to 1ドル, but that would take a more bytes and be less efficient. Obviously this is not the most time efficient of algorithms, but it only takes about 16 seconds to run the 5525 case on my machine.

Source Link
Robert Benson
  • 1.8k
  • 11
  • 13

##AWK, 90 bytes

{z=1ドル*1ドル
for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1

Usage:

awk '{z=1ドル*1ドル
 for(x=1ドル;x>=0;x--)for(y=0;y<=1ドル;y++){d=z-x*x-y*y
 if(d>0&&d<2*(x+y)+2)c++}0ドル=4*c}1' <<< 5525

Just a simple search through quadrant 1 to find all boxes that will intersect the circle. Symmetry allows for the multiply by 4. Could go from -1ドル to 1ドル, but that would take a more bytes and be less efficient. Obviously this is not the most time efficient of algorithms, but it only takes about 16 seconds to run the 5525 case on my machine.

AltStyle によって変換されたページ (->オリジナル) /