N-movers: How much of the infinite board can I reach?












14












$begingroup$


Single moves



The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).



For example:




  • A 1-mover can move to any square that is horizontally or vertically adjacent

  • A 2-mover can move to any square that is diagonally adjacent

  • A 5-mover moves like a chess knight


Note that not all N-movers can move. A 3-mover can never leave its current square because none of the squares on the board are a distance of exactly root 3 from the current square.



Multiple moves



If allowed to move repeatedly, some pieces can reach any square on the board. For example, a 1-mover and a 5-mover can both do this. A 2-mover can only move diagonally and can only reach half of the squares. A piece that cannot move, like a 3-mover, cannot reach any of the squares (the starting square is not counted as "reached" if no movement occurs).



1-mover2-mover3-mover4-mover5-mover8-mover9-mover10-mover20-mover25-mover40-mover64-mover65-mover68-mover



The images show which squares can be reached. More details on hover. Click for larger image.




  • Squares reachable in 1 or more moves are marked in black

  • Squares reachable in exactly 1 move are shown by red pieces
    (apart from the 3-mover, which cannot move)


What proportion of the board can a given N-mover reach?



Input




  • A positive integer N


Output




  • The proportion of the board that an N-mover can reach

  • This is a number from 0 to 1 (both inclusive)

  • For this challenge, output as a fraction in lowest terms, like 1/4, is allowed


So for input 8, both 1/8 and 0.125 are acceptable outputs.



Scoring



This is code golf. The score is the length of the code in bytes. For each language, the shortest code wins.



Test cases



In the format input : output as fraction : output as decimal



  1 : 1     : 1
2 : 1/2 : 0.5
3 : 0 : 0
4 : 1/4 : 0.25
5 : 1 : 1
6 : 0 : 0
7 : 0 : 0
8 : 1/8 : 0.125
9 : 1/9 : 0.1111111111111111111111111111
10 : 1/2 : 0.5
13 : 1 : 1
16 : 1/16 : 0.0625
18 : 1/18 : 0.05555555555555555555555555556
20 : 1/4 : 0.25
25 : 1 : 1
26 : 1/2 : 0.5
64 : 1/64 : 0.015625
65 : 1 : 1
72 : 1/72 : 0.01388888888888888888888888889
73 : 1 : 1
74 : 1/2 : 0.5
80 : 1/16 : 0.0625
81 : 1/81 : 0.01234567901234567901234567901
82 : 1/2 : 0.5
144 : 1/144 : 0.006944444444444444444444444444
145 : 1 : 1
146 : 1/2 : 0.5
148 : 1/4 : 0.25
153 : 1/9 : 0.1111111111111111111111111111
160 : 1/32 : 0.03125
161 : 0 : 0
162 : 1/162 : 0.006172839506172839506172839506
163 : 0 : 0
164 : 1/4 : 0.25
241 : 1 : 1
242 : 1/242 : 0.004132231404958677685950413223
244 : 1/4 : 0.25
245 : 1/49 : 0.02040816326530612244897959184
260 : 1/4 : 0.25
261 : 1/9 : 0.1111111111111111111111111111
288 : 1/288 : 0.003472222222222222222222222222
290 : 1/2 : 0.5
292 : 1/4 : 0.25
293 : 1 : 1
324 : 1/324 : 0.003086419753086419753086419753
325 : 1 : 1
326 : 0 : 0
360 : 1/72 : 0.01388888888888888888888888889
361 : 1/361 : 0.002770083102493074792243767313
362 : 1/2 : 0.5
369 : 1/9 : 0.1111111111111111111111111111
370 : 1/2 : 0.5
449 : 1 : 1
450 : 1/18 : 0.05555555555555555555555555556
488 : 1/8 : 0.125
489 : 0 : 0
490 : 1/98 : 0.01020408163265306122448979592
520 : 1/8 : 0.125
521 : 1 : 1
522 : 1/18 : 0.05555555555555555555555555556
544 : 1/32 : 0.03125
548 : 1/4 : 0.25
549 : 1/9 : 0.1111111111111111111111111111
584 : 1/8 : 0.125
585 : 1/9 : 0.1111111111111111111111111111
586 : 1/2 : 0.5
592 : 1/16 : 0.0625
593 : 1 : 1
596 : 1/4 : 0.25
605 : 1/121 : 0.008264462809917355371900826446
610 : 1/2 : 0.5
611 : 0 : 0
612 : 1/36 : 0.02777777777777777777777777778
613 : 1 : 1
624 : 0 : 0
625 : 1 : 1









share|improve this question











$endgroup$

















    14












    $begingroup$


    Single moves



    The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).



    For example:




    • A 1-mover can move to any square that is horizontally or vertically adjacent

    • A 2-mover can move to any square that is diagonally adjacent

    • A 5-mover moves like a chess knight


    Note that not all N-movers can move. A 3-mover can never leave its current square because none of the squares on the board are a distance of exactly root 3 from the current square.



    Multiple moves



    If allowed to move repeatedly, some pieces can reach any square on the board. For example, a 1-mover and a 5-mover can both do this. A 2-mover can only move diagonally and can only reach half of the squares. A piece that cannot move, like a 3-mover, cannot reach any of the squares (the starting square is not counted as "reached" if no movement occurs).



    1-mover2-mover3-mover4-mover5-mover8-mover9-mover10-mover20-mover25-mover40-mover64-mover65-mover68-mover



    The images show which squares can be reached. More details on hover. Click for larger image.




    • Squares reachable in 1 or more moves are marked in black

    • Squares reachable in exactly 1 move are shown by red pieces
      (apart from the 3-mover, which cannot move)


    What proportion of the board can a given N-mover reach?



    Input




    • A positive integer N


    Output




    • The proportion of the board that an N-mover can reach

    • This is a number from 0 to 1 (both inclusive)

    • For this challenge, output as a fraction in lowest terms, like 1/4, is allowed


    So for input 8, both 1/8 and 0.125 are acceptable outputs.



    Scoring



    This is code golf. The score is the length of the code in bytes. For each language, the shortest code wins.



    Test cases



    In the format input : output as fraction : output as decimal



      1 : 1     : 1
    2 : 1/2 : 0.5
    3 : 0 : 0
    4 : 1/4 : 0.25
    5 : 1 : 1
    6 : 0 : 0
    7 : 0 : 0
    8 : 1/8 : 0.125
    9 : 1/9 : 0.1111111111111111111111111111
    10 : 1/2 : 0.5
    13 : 1 : 1
    16 : 1/16 : 0.0625
    18 : 1/18 : 0.05555555555555555555555555556
    20 : 1/4 : 0.25
    25 : 1 : 1
    26 : 1/2 : 0.5
    64 : 1/64 : 0.015625
    65 : 1 : 1
    72 : 1/72 : 0.01388888888888888888888888889
    73 : 1 : 1
    74 : 1/2 : 0.5
    80 : 1/16 : 0.0625
    81 : 1/81 : 0.01234567901234567901234567901
    82 : 1/2 : 0.5
    144 : 1/144 : 0.006944444444444444444444444444
    145 : 1 : 1
    146 : 1/2 : 0.5
    148 : 1/4 : 0.25
    153 : 1/9 : 0.1111111111111111111111111111
    160 : 1/32 : 0.03125
    161 : 0 : 0
    162 : 1/162 : 0.006172839506172839506172839506
    163 : 0 : 0
    164 : 1/4 : 0.25
    241 : 1 : 1
    242 : 1/242 : 0.004132231404958677685950413223
    244 : 1/4 : 0.25
    245 : 1/49 : 0.02040816326530612244897959184
    260 : 1/4 : 0.25
    261 : 1/9 : 0.1111111111111111111111111111
    288 : 1/288 : 0.003472222222222222222222222222
    290 : 1/2 : 0.5
    292 : 1/4 : 0.25
    293 : 1 : 1
    324 : 1/324 : 0.003086419753086419753086419753
    325 : 1 : 1
    326 : 0 : 0
    360 : 1/72 : 0.01388888888888888888888888889
    361 : 1/361 : 0.002770083102493074792243767313
    362 : 1/2 : 0.5
    369 : 1/9 : 0.1111111111111111111111111111
    370 : 1/2 : 0.5
    449 : 1 : 1
    450 : 1/18 : 0.05555555555555555555555555556
    488 : 1/8 : 0.125
    489 : 0 : 0
    490 : 1/98 : 0.01020408163265306122448979592
    520 : 1/8 : 0.125
    521 : 1 : 1
    522 : 1/18 : 0.05555555555555555555555555556
    544 : 1/32 : 0.03125
    548 : 1/4 : 0.25
    549 : 1/9 : 0.1111111111111111111111111111
    584 : 1/8 : 0.125
    585 : 1/9 : 0.1111111111111111111111111111
    586 : 1/2 : 0.5
    592 : 1/16 : 0.0625
    593 : 1 : 1
    596 : 1/4 : 0.25
    605 : 1/121 : 0.008264462809917355371900826446
    610 : 1/2 : 0.5
    611 : 0 : 0
    612 : 1/36 : 0.02777777777777777777777777778
    613 : 1 : 1
    624 : 0 : 0
    625 : 1 : 1









    share|improve this question











    $endgroup$















      14












      14








      14





      $begingroup$


      Single moves



      The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).



      For example:




      • A 1-mover can move to any square that is horizontally or vertically adjacent

      • A 2-mover can move to any square that is diagonally adjacent

      • A 5-mover moves like a chess knight


      Note that not all N-movers can move. A 3-mover can never leave its current square because none of the squares on the board are a distance of exactly root 3 from the current square.



      Multiple moves



      If allowed to move repeatedly, some pieces can reach any square on the board. For example, a 1-mover and a 5-mover can both do this. A 2-mover can only move diagonally and can only reach half of the squares. A piece that cannot move, like a 3-mover, cannot reach any of the squares (the starting square is not counted as "reached" if no movement occurs).



      1-mover2-mover3-mover4-mover5-mover8-mover9-mover10-mover20-mover25-mover40-mover64-mover65-mover68-mover



      The images show which squares can be reached. More details on hover. Click for larger image.




      • Squares reachable in 1 or more moves are marked in black

      • Squares reachable in exactly 1 move are shown by red pieces
        (apart from the 3-mover, which cannot move)


      What proportion of the board can a given N-mover reach?



      Input




      • A positive integer N


      Output




      • The proportion of the board that an N-mover can reach

      • This is a number from 0 to 1 (both inclusive)

      • For this challenge, output as a fraction in lowest terms, like 1/4, is allowed


      So for input 8, both 1/8 and 0.125 are acceptable outputs.



      Scoring



      This is code golf. The score is the length of the code in bytes. For each language, the shortest code wins.



      Test cases



      In the format input : output as fraction : output as decimal



        1 : 1     : 1
      2 : 1/2 : 0.5
      3 : 0 : 0
      4 : 1/4 : 0.25
      5 : 1 : 1
      6 : 0 : 0
      7 : 0 : 0
      8 : 1/8 : 0.125
      9 : 1/9 : 0.1111111111111111111111111111
      10 : 1/2 : 0.5
      13 : 1 : 1
      16 : 1/16 : 0.0625
      18 : 1/18 : 0.05555555555555555555555555556
      20 : 1/4 : 0.25
      25 : 1 : 1
      26 : 1/2 : 0.5
      64 : 1/64 : 0.015625
      65 : 1 : 1
      72 : 1/72 : 0.01388888888888888888888888889
      73 : 1 : 1
      74 : 1/2 : 0.5
      80 : 1/16 : 0.0625
      81 : 1/81 : 0.01234567901234567901234567901
      82 : 1/2 : 0.5
      144 : 1/144 : 0.006944444444444444444444444444
      145 : 1 : 1
      146 : 1/2 : 0.5
      148 : 1/4 : 0.25
      153 : 1/9 : 0.1111111111111111111111111111
      160 : 1/32 : 0.03125
      161 : 0 : 0
      162 : 1/162 : 0.006172839506172839506172839506
      163 : 0 : 0
      164 : 1/4 : 0.25
      241 : 1 : 1
      242 : 1/242 : 0.004132231404958677685950413223
      244 : 1/4 : 0.25
      245 : 1/49 : 0.02040816326530612244897959184
      260 : 1/4 : 0.25
      261 : 1/9 : 0.1111111111111111111111111111
      288 : 1/288 : 0.003472222222222222222222222222
      290 : 1/2 : 0.5
      292 : 1/4 : 0.25
      293 : 1 : 1
      324 : 1/324 : 0.003086419753086419753086419753
      325 : 1 : 1
      326 : 0 : 0
      360 : 1/72 : 0.01388888888888888888888888889
      361 : 1/361 : 0.002770083102493074792243767313
      362 : 1/2 : 0.5
      369 : 1/9 : 0.1111111111111111111111111111
      370 : 1/2 : 0.5
      449 : 1 : 1
      450 : 1/18 : 0.05555555555555555555555555556
      488 : 1/8 : 0.125
      489 : 0 : 0
      490 : 1/98 : 0.01020408163265306122448979592
      520 : 1/8 : 0.125
      521 : 1 : 1
      522 : 1/18 : 0.05555555555555555555555555556
      544 : 1/32 : 0.03125
      548 : 1/4 : 0.25
      549 : 1/9 : 0.1111111111111111111111111111
      584 : 1/8 : 0.125
      585 : 1/9 : 0.1111111111111111111111111111
      586 : 1/2 : 0.5
      592 : 1/16 : 0.0625
      593 : 1 : 1
      596 : 1/4 : 0.25
      605 : 1/121 : 0.008264462809917355371900826446
      610 : 1/2 : 0.5
      611 : 0 : 0
      612 : 1/36 : 0.02777777777777777777777777778
      613 : 1 : 1
      624 : 0 : 0
      625 : 1 : 1









      share|improve this question











      $endgroup$




      Single moves



      The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).



      For example:




      • A 1-mover can move to any square that is horizontally or vertically adjacent

      • A 2-mover can move to any square that is diagonally adjacent

      • A 5-mover moves like a chess knight


      Note that not all N-movers can move. A 3-mover can never leave its current square because none of the squares on the board are a distance of exactly root 3 from the current square.



      Multiple moves



      If allowed to move repeatedly, some pieces can reach any square on the board. For example, a 1-mover and a 5-mover can both do this. A 2-mover can only move diagonally and can only reach half of the squares. A piece that cannot move, like a 3-mover, cannot reach any of the squares (the starting square is not counted as "reached" if no movement occurs).



      1-mover2-mover3-mover4-mover5-mover8-mover9-mover10-mover20-mover25-mover40-mover64-mover65-mover68-mover



      The images show which squares can be reached. More details on hover. Click for larger image.




      • Squares reachable in 1 or more moves are marked in black

      • Squares reachable in exactly 1 move are shown by red pieces
        (apart from the 3-mover, which cannot move)


      What proportion of the board can a given N-mover reach?



      Input




      • A positive integer N


      Output




      • The proportion of the board that an N-mover can reach

      • This is a number from 0 to 1 (both inclusive)

      • For this challenge, output as a fraction in lowest terms, like 1/4, is allowed


      So for input 8, both 1/8 and 0.125 are acceptable outputs.



      Scoring



      This is code golf. The score is the length of the code in bytes. For each language, the shortest code wins.



      Test cases



      In the format input : output as fraction : output as decimal



        1 : 1     : 1
      2 : 1/2 : 0.5
      3 : 0 : 0
      4 : 1/4 : 0.25
      5 : 1 : 1
      6 : 0 : 0
      7 : 0 : 0
      8 : 1/8 : 0.125
      9 : 1/9 : 0.1111111111111111111111111111
      10 : 1/2 : 0.5
      13 : 1 : 1
      16 : 1/16 : 0.0625
      18 : 1/18 : 0.05555555555555555555555555556
      20 : 1/4 : 0.25
      25 : 1 : 1
      26 : 1/2 : 0.5
      64 : 1/64 : 0.015625
      65 : 1 : 1
      72 : 1/72 : 0.01388888888888888888888888889
      73 : 1 : 1
      74 : 1/2 : 0.5
      80 : 1/16 : 0.0625
      81 : 1/81 : 0.01234567901234567901234567901
      82 : 1/2 : 0.5
      144 : 1/144 : 0.006944444444444444444444444444
      145 : 1 : 1
      146 : 1/2 : 0.5
      148 : 1/4 : 0.25
      153 : 1/9 : 0.1111111111111111111111111111
      160 : 1/32 : 0.03125
      161 : 0 : 0
      162 : 1/162 : 0.006172839506172839506172839506
      163 : 0 : 0
      164 : 1/4 : 0.25
      241 : 1 : 1
      242 : 1/242 : 0.004132231404958677685950413223
      244 : 1/4 : 0.25
      245 : 1/49 : 0.02040816326530612244897959184
      260 : 1/4 : 0.25
      261 : 1/9 : 0.1111111111111111111111111111
      288 : 1/288 : 0.003472222222222222222222222222
      290 : 1/2 : 0.5
      292 : 1/4 : 0.25
      293 : 1 : 1
      324 : 1/324 : 0.003086419753086419753086419753
      325 : 1 : 1
      326 : 0 : 0
      360 : 1/72 : 0.01388888888888888888888888889
      361 : 1/361 : 0.002770083102493074792243767313
      362 : 1/2 : 0.5
      369 : 1/9 : 0.1111111111111111111111111111
      370 : 1/2 : 0.5
      449 : 1 : 1
      450 : 1/18 : 0.05555555555555555555555555556
      488 : 1/8 : 0.125
      489 : 0 : 0
      490 : 1/98 : 0.01020408163265306122448979592
      520 : 1/8 : 0.125
      521 : 1 : 1
      522 : 1/18 : 0.05555555555555555555555555556
      544 : 1/32 : 0.03125
      548 : 1/4 : 0.25
      549 : 1/9 : 0.1111111111111111111111111111
      584 : 1/8 : 0.125
      585 : 1/9 : 0.1111111111111111111111111111
      586 : 1/2 : 0.5
      592 : 1/16 : 0.0625
      593 : 1 : 1
      596 : 1/4 : 0.25
      605 : 1/121 : 0.008264462809917355371900826446
      610 : 1/2 : 0.5
      611 : 0 : 0
      612 : 1/36 : 0.02777777777777777777777777778
      613 : 1 : 1
      624 : 0 : 0
      625 : 1 : 1






      code-golf grid chess board-game






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 20 mins ago







      trichoplax

















      asked 4 hours ago









      trichoplaxtrichoplax

      7,33163975




      7,33163975






















          1 Answer
          1






          active

          oldest

          votes


















          3












          $begingroup$


          Clean, 189 185 172 bytes



          import StdEnv
          $n#p=[[x,y]\x<-[~n..n],y<-[~n..n]|x^2+y^2==n]
          =sum[1.0\_<-iter n(q=removeDup[k\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(e=n>=e&&e>0)k])p]/toReal(n^2)


          Try it online!



          Finds every position reachable in the n-side-length square cornered on the origin in the first quadrant, then divides by n^2 to get the portion of all cells reachable.






          share|improve this answer











          $endgroup$













          • $begingroup$
            My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
            $endgroup$
            – trichoplax
            44 mins ago






          • 1




            $begingroup$
            @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
            $endgroup$
            – Οurous
            43 mins ago










          • $begingroup$
            I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
            $endgroup$
            – trichoplax
            35 mins ago











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "200"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179747%2fn-movers-how-much-of-the-infinite-board-can-i-reach%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3












          $begingroup$


          Clean, 189 185 172 bytes



          import StdEnv
          $n#p=[[x,y]\x<-[~n..n],y<-[~n..n]|x^2+y^2==n]
          =sum[1.0\_<-iter n(q=removeDup[k\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(e=n>=e&&e>0)k])p]/toReal(n^2)


          Try it online!



          Finds every position reachable in the n-side-length square cornered on the origin in the first quadrant, then divides by n^2 to get the portion of all cells reachable.






          share|improve this answer











          $endgroup$













          • $begingroup$
            My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
            $endgroup$
            – trichoplax
            44 mins ago






          • 1




            $begingroup$
            @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
            $endgroup$
            – Οurous
            43 mins ago










          • $begingroup$
            I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
            $endgroup$
            – trichoplax
            35 mins ago
















          3












          $begingroup$


          Clean, 189 185 172 bytes



          import StdEnv
          $n#p=[[x,y]\x<-[~n..n],y<-[~n..n]|x^2+y^2==n]
          =sum[1.0\_<-iter n(q=removeDup[k\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(e=n>=e&&e>0)k])p]/toReal(n^2)


          Try it online!



          Finds every position reachable in the n-side-length square cornered on the origin in the first quadrant, then divides by n^2 to get the portion of all cells reachable.






          share|improve this answer











          $endgroup$













          • $begingroup$
            My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
            $endgroup$
            – trichoplax
            44 mins ago






          • 1




            $begingroup$
            @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
            $endgroup$
            – Οurous
            43 mins ago










          • $begingroup$
            I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
            $endgroup$
            – trichoplax
            35 mins ago














          3












          3








          3





          $begingroup$


          Clean, 189 185 172 bytes



          import StdEnv
          $n#p=[[x,y]\x<-[~n..n],y<-[~n..n]|x^2+y^2==n]
          =sum[1.0\_<-iter n(q=removeDup[k\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(e=n>=e&&e>0)k])p]/toReal(n^2)


          Try it online!



          Finds every position reachable in the n-side-length square cornered on the origin in the first quadrant, then divides by n^2 to get the portion of all cells reachable.






          share|improve this answer











          $endgroup$




          Clean, 189 185 172 bytes



          import StdEnv
          $n#p=[[x,y]\x<-[~n..n],y<-[~n..n]|x^2+y^2==n]
          =sum[1.0\_<-iter n(q=removeDup[k\[a,b]<-[[0,0]:p],[u,v]<-q,k<-[[a+u,b+v]]|all(e=n>=e&&e>0)k])p]/toReal(n^2)


          Try it online!



          Finds every position reachable in the n-side-length square cornered on the origin in the first quadrant, then divides by n^2 to get the portion of all cells reachable.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 22 mins ago

























          answered 52 mins ago









          ΟurousΟurous

          6,82211034




          6,82211034












          • $begingroup$
            My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
            $endgroup$
            – trichoplax
            44 mins ago






          • 1




            $begingroup$
            @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
            $endgroup$
            – Οurous
            43 mins ago










          • $begingroup$
            I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
            $endgroup$
            – trichoplax
            35 mins ago


















          • $begingroup$
            My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
            $endgroup$
            – trichoplax
            44 mins ago






          • 1




            $begingroup$
            @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
            $endgroup$
            – Οurous
            43 mins ago










          • $begingroup$
            I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
            $endgroup$
            – trichoplax
            35 mins ago
















          $begingroup$
          My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
          $endgroup$
          – trichoplax
          44 mins ago




          $begingroup$
          My apologies - I was looking at the test cases which go from N=10 to N=13, whereas your test cases include N=11 and N=12 too. You are indeed correct for N=13. +1 from me :)
          $endgroup$
          – trichoplax
          44 mins ago




          1




          1




          $begingroup$
          @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
          $endgroup$
          – Οurous
          43 mins ago




          $begingroup$
          @trichoplax I've changed the tests to correspond to the question to avoid the same confusion again
          $endgroup$
          – Οurous
          43 mins ago












          $begingroup$
          I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
          $endgroup$
          – trichoplax
          35 mins ago




          $begingroup$
          I've further tested up to N=145 and all are correct. I couldn't test 146 on TIO due to the 60 second timeout though. I'm expecting some very long run times in answers here...
          $endgroup$
          – trichoplax
          35 mins ago


















          draft saved

          draft discarded




















































          If this is an answer to a challenge…




          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
            Explanations of your answer make it more interesting to read and are very much encouraged.


          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



          More generally…




          • …Please make sure to answer the question and provide sufficient detail.


          • …Avoid asking for help, clarification or responding to other answers (use comments instead).





          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f179747%2fn-movers-how-much-of-the-infinite-board-can-i-reach%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Aikido

          Tivadar Csontváry Kosztka

          Metroo de Marsejlo