Code Vita : Chakravyuha

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












Problem Statement




A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
below



enter image description here



A Chakravyuha has a very well-defined co-ordinate system. Each point
on the co-ordinate system is manned by a certain unit of the army. The
Commander-In-Chief is always located at the center of the army to
better co-ordinate his forces. The only way to crack the Chakravyuha
is to defeat the units in sequential order.



A Sequential order of units differs structurally based on the radius
of the Chakra. The radius can be thought of as length or breadth of
the matrix depicted above. The structure i.e. placement of units in
sequential order is as shown below



enter image description here



The entry point of the Chakravyuha is always at the (0,0) co-ordinate
of the matrix above. This is where the 1st army unit guards. From
(0,0) i.e. 1st unit Abhimanyu has to march towards the center at (2,2)
where the 25th i.e. the last of the enemy army unit guards. Remember
that he has to proceed by destroying the units in sequential fashion.
After destroying the first unit, Abhimanyu gets a power point.
Thereafter, he gets one after destroying army units which are
multiples of 11. You should also be a in a position to tell Yudhisthir
Maharaj the location at which Abhimanyu collected his power points.




Input Format:




First line of input will be length as well as breadth of the army units, say N




Output Format:




  • Print NxN matrix depicting the placement of army units, with unit numbers delimited by (t) Tab character

  • Print Total power points collected

  • Print coordinates of power points collected in sequential fashion (one per line)

  • Print coordinates of power points collected in sequential fashion (one per line)



Constraints:




0 < N <=100




The Logic:




enter image description here




The Code:



#include<stdio.h>

int isDiv(int);

int main()

int isDiv(int x)
if( x % 11 == 0 )
return 1;

else
return 0;




The Code is working fine as can be checked on Ideone







share|improve this question



























    up vote
    2
    down vote

    favorite












    Problem Statement




    A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
    below



    enter image description here



    A Chakravyuha has a very well-defined co-ordinate system. Each point
    on the co-ordinate system is manned by a certain unit of the army. The
    Commander-In-Chief is always located at the center of the army to
    better co-ordinate his forces. The only way to crack the Chakravyuha
    is to defeat the units in sequential order.



    A Sequential order of units differs structurally based on the radius
    of the Chakra. The radius can be thought of as length or breadth of
    the matrix depicted above. The structure i.e. placement of units in
    sequential order is as shown below



    enter image description here



    The entry point of the Chakravyuha is always at the (0,0) co-ordinate
    of the matrix above. This is where the 1st army unit guards. From
    (0,0) i.e. 1st unit Abhimanyu has to march towards the center at (2,2)
    where the 25th i.e. the last of the enemy army unit guards. Remember
    that he has to proceed by destroying the units in sequential fashion.
    After destroying the first unit, Abhimanyu gets a power point.
    Thereafter, he gets one after destroying army units which are
    multiples of 11. You should also be a in a position to tell Yudhisthir
    Maharaj the location at which Abhimanyu collected his power points.




    Input Format:




    First line of input will be length as well as breadth of the army units, say N




    Output Format:




    • Print NxN matrix depicting the placement of army units, with unit numbers delimited by (t) Tab character

    • Print Total power points collected

    • Print coordinates of power points collected in sequential fashion (one per line)

    • Print coordinates of power points collected in sequential fashion (one per line)



    Constraints:




    0 < N <=100




    The Logic:




    enter image description here




    The Code:



    #include<stdio.h>

    int isDiv(int);

    int main()

    int isDiv(int x)
    if( x % 11 == 0 )
    return 1;

    else
    return 0;




    The Code is working fine as can be checked on Ideone







    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Problem Statement




      A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
      below



      enter image description here



      A Chakravyuha has a very well-defined co-ordinate system. Each point
      on the co-ordinate system is manned by a certain unit of the army. The
      Commander-In-Chief is always located at the center of the army to
      better co-ordinate his forces. The only way to crack the Chakravyuha
      is to defeat the units in sequential order.



      A Sequential order of units differs structurally based on the radius
      of the Chakra. The radius can be thought of as length or breadth of
      the matrix depicted above. The structure i.e. placement of units in
      sequential order is as shown below



      enter image description here



      The entry point of the Chakravyuha is always at the (0,0) co-ordinate
      of the matrix above. This is where the 1st army unit guards. From
      (0,0) i.e. 1st unit Abhimanyu has to march towards the center at (2,2)
      where the 25th i.e. the last of the enemy army unit guards. Remember
      that he has to proceed by destroying the units in sequential fashion.
      After destroying the first unit, Abhimanyu gets a power point.
      Thereafter, he gets one after destroying army units which are
      multiples of 11. You should also be a in a position to tell Yudhisthir
      Maharaj the location at which Abhimanyu collected his power points.




      Input Format:




      First line of input will be length as well as breadth of the army units, say N




      Output Format:




      • Print NxN matrix depicting the placement of army units, with unit numbers delimited by (t) Tab character

      • Print Total power points collected

      • Print coordinates of power points collected in sequential fashion (one per line)

      • Print coordinates of power points collected in sequential fashion (one per line)



      Constraints:




      0 < N <=100




      The Logic:




      enter image description here




      The Code:



      #include<stdio.h>

      int isDiv(int);

      int main()

      int isDiv(int x)
      if( x % 11 == 0 )
      return 1;

      else
      return 0;




      The Code is working fine as can be checked on Ideone







      share|improve this question













      Problem Statement




      A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
      below



      enter image description here



      A Chakravyuha has a very well-defined co-ordinate system. Each point
      on the co-ordinate system is manned by a certain unit of the army. The
      Commander-In-Chief is always located at the center of the army to
      better co-ordinate his forces. The only way to crack the Chakravyuha
      is to defeat the units in sequential order.



      A Sequential order of units differs structurally based on the radius
      of the Chakra. The radius can be thought of as length or breadth of
      the matrix depicted above. The structure i.e. placement of units in
      sequential order is as shown below



      enter image description here



      The entry point of the Chakravyuha is always at the (0,0) co-ordinate
      of the matrix above. This is where the 1st army unit guards. From
      (0,0) i.e. 1st unit Abhimanyu has to march towards the center at (2,2)
      where the 25th i.e. the last of the enemy army unit guards. Remember
      that he has to proceed by destroying the units in sequential fashion.
      After destroying the first unit, Abhimanyu gets a power point.
      Thereafter, he gets one after destroying army units which are
      multiples of 11. You should also be a in a position to tell Yudhisthir
      Maharaj the location at which Abhimanyu collected his power points.




      Input Format:




      First line of input will be length as well as breadth of the army units, say N




      Output Format:




      • Print NxN matrix depicting the placement of army units, with unit numbers delimited by (t) Tab character

      • Print Total power points collected

      • Print coordinates of power points collected in sequential fashion (one per line)

      • Print coordinates of power points collected in sequential fashion (one per line)



      Constraints:




      0 < N <=100




      The Logic:




      enter image description here




      The Code:



      #include<stdio.h>

      int isDiv(int);

      int main()

      int isDiv(int x)
      if( x % 11 == 0 )
      return 1;

      else
      return 0;




      The Code is working fine as can be checked on Ideone









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 31 at 19:54
























      asked Jul 31 at 19:35









      Phoenix

      864




      864




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          You should try to keep your main function small and focused. (Well, you should try to keep every function you write small and focused!) For example, you might do something like this:



          struct Coord 
          int row, col;
          ;
          struct CoordList
          int size;
          Coord *data;
          ;

          void print_coords(Coord c, FILE *out)
          printf("(%d,%d)n", c.row, c.col);


          int main()
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          CoordList coords = collect_power_points(n);
          printf("%dn", coords.size);
          for (int i=0; i < coords.size; ++i)
          print_coords(coords.data[i]);




          Writing the little functions print_tab_delimited_matrix and collect_power_points is left as an exercise for the reader.




          Or, you might consider that there's no real point to collecting up all of the power-point coordinates in a physical list. You already know the formula for computing where each power point is picked up! So you might scrap the above code and rewrite your whole program as:



          int main() 
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          int n2 = n * n;
          printf("%dn", 1 + (n2 / 11));
          print_coords(get_coords_of_army(1, n), stdout);
          printf("(%d,%d)n", c.row, c.col);
          for (int i = 11; i <= n2; i += 11)
          print_coords(get_coords_of_army(i, n), stdout);




          Writing the function get_coords_of_army is left as an exercise for the reader. But the important thing to realize is that writing that function is supposed to be the challenge! You should develop the instinct and intuition for quickly breaking down a problem statement into sub-problems, and then solving those sub-problems. Notice that outside of main I don't need to do any input or output; I just have a very clean mathematical problem to solve.



          Coord get_coords_of_army(int which_army, int breadth_of_square);


          Everything else going on in this problem statement is basically a red herring.




          I note in passing that isDiv(x) is not a good name for a function that computes whether x is divisible by 11. You get points for naming it is...-something, but surely (A) is_divisible_by_11 would have been a better name, and (B) you don't really need a function for that!



          You could make the argument that this is futureproofing the code: what if the next iteration of the puzzle changes the locations of the power points? That's fair, and makes is_divisible_by_11 a bad name... but it doesn't make isDiv a good name! We might better write



          bool has_power_point(int which_army) 
          return (which_army == 1)


          and then back in our main function we can write simply



           printf("%dn", 1 + (n2 / 11));
          for (int i = 1; i <= n2; ++i)
          if (has_power_point(i))
          print_coords(get_coords_of_army(i, n), stdout);







          share|improve this answer





















          • So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
            – Phoenix
            Aug 1 at 8:50










          • @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
            – Quuxplusone
            Aug 1 at 18:13










          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: "196"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200690%2fcode-vita-chakravyuha%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          You should try to keep your main function small and focused. (Well, you should try to keep every function you write small and focused!) For example, you might do something like this:



          struct Coord 
          int row, col;
          ;
          struct CoordList
          int size;
          Coord *data;
          ;

          void print_coords(Coord c, FILE *out)
          printf("(%d,%d)n", c.row, c.col);


          int main()
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          CoordList coords = collect_power_points(n);
          printf("%dn", coords.size);
          for (int i=0; i < coords.size; ++i)
          print_coords(coords.data[i]);




          Writing the little functions print_tab_delimited_matrix and collect_power_points is left as an exercise for the reader.




          Or, you might consider that there's no real point to collecting up all of the power-point coordinates in a physical list. You already know the formula for computing where each power point is picked up! So you might scrap the above code and rewrite your whole program as:



          int main() 
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          int n2 = n * n;
          printf("%dn", 1 + (n2 / 11));
          print_coords(get_coords_of_army(1, n), stdout);
          printf("(%d,%d)n", c.row, c.col);
          for (int i = 11; i <= n2; i += 11)
          print_coords(get_coords_of_army(i, n), stdout);




          Writing the function get_coords_of_army is left as an exercise for the reader. But the important thing to realize is that writing that function is supposed to be the challenge! You should develop the instinct and intuition for quickly breaking down a problem statement into sub-problems, and then solving those sub-problems. Notice that outside of main I don't need to do any input or output; I just have a very clean mathematical problem to solve.



          Coord get_coords_of_army(int which_army, int breadth_of_square);


          Everything else going on in this problem statement is basically a red herring.




          I note in passing that isDiv(x) is not a good name for a function that computes whether x is divisible by 11. You get points for naming it is...-something, but surely (A) is_divisible_by_11 would have been a better name, and (B) you don't really need a function for that!



          You could make the argument that this is futureproofing the code: what if the next iteration of the puzzle changes the locations of the power points? That's fair, and makes is_divisible_by_11 a bad name... but it doesn't make isDiv a good name! We might better write



          bool has_power_point(int which_army) 
          return (which_army == 1)


          and then back in our main function we can write simply



           printf("%dn", 1 + (n2 / 11));
          for (int i = 1; i <= n2; ++i)
          if (has_power_point(i))
          print_coords(get_coords_of_army(i, n), stdout);







          share|improve this answer





















          • So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
            – Phoenix
            Aug 1 at 8:50










          • @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
            – Quuxplusone
            Aug 1 at 18:13














          up vote
          2
          down vote













          You should try to keep your main function small and focused. (Well, you should try to keep every function you write small and focused!) For example, you might do something like this:



          struct Coord 
          int row, col;
          ;
          struct CoordList
          int size;
          Coord *data;
          ;

          void print_coords(Coord c, FILE *out)
          printf("(%d,%d)n", c.row, c.col);


          int main()
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          CoordList coords = collect_power_points(n);
          printf("%dn", coords.size);
          for (int i=0; i < coords.size; ++i)
          print_coords(coords.data[i]);




          Writing the little functions print_tab_delimited_matrix and collect_power_points is left as an exercise for the reader.




          Or, you might consider that there's no real point to collecting up all of the power-point coordinates in a physical list. You already know the formula for computing where each power point is picked up! So you might scrap the above code and rewrite your whole program as:



          int main() 
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          int n2 = n * n;
          printf("%dn", 1 + (n2 / 11));
          print_coords(get_coords_of_army(1, n), stdout);
          printf("(%d,%d)n", c.row, c.col);
          for (int i = 11; i <= n2; i += 11)
          print_coords(get_coords_of_army(i, n), stdout);




          Writing the function get_coords_of_army is left as an exercise for the reader. But the important thing to realize is that writing that function is supposed to be the challenge! You should develop the instinct and intuition for quickly breaking down a problem statement into sub-problems, and then solving those sub-problems. Notice that outside of main I don't need to do any input or output; I just have a very clean mathematical problem to solve.



          Coord get_coords_of_army(int which_army, int breadth_of_square);


          Everything else going on in this problem statement is basically a red herring.




          I note in passing that isDiv(x) is not a good name for a function that computes whether x is divisible by 11. You get points for naming it is...-something, but surely (A) is_divisible_by_11 would have been a better name, and (B) you don't really need a function for that!



          You could make the argument that this is futureproofing the code: what if the next iteration of the puzzle changes the locations of the power points? That's fair, and makes is_divisible_by_11 a bad name... but it doesn't make isDiv a good name! We might better write



          bool has_power_point(int which_army) 
          return (which_army == 1)


          and then back in our main function we can write simply



           printf("%dn", 1 + (n2 / 11));
          for (int i = 1; i <= n2; ++i)
          if (has_power_point(i))
          print_coords(get_coords_of_army(i, n), stdout);







          share|improve this answer





















          • So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
            – Phoenix
            Aug 1 at 8:50










          • @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
            – Quuxplusone
            Aug 1 at 18:13












          up vote
          2
          down vote










          up vote
          2
          down vote









          You should try to keep your main function small and focused. (Well, you should try to keep every function you write small and focused!) For example, you might do something like this:



          struct Coord 
          int row, col;
          ;
          struct CoordList
          int size;
          Coord *data;
          ;

          void print_coords(Coord c, FILE *out)
          printf("(%d,%d)n", c.row, c.col);


          int main()
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          CoordList coords = collect_power_points(n);
          printf("%dn", coords.size);
          for (int i=0; i < coords.size; ++i)
          print_coords(coords.data[i]);




          Writing the little functions print_tab_delimited_matrix and collect_power_points is left as an exercise for the reader.




          Or, you might consider that there's no real point to collecting up all of the power-point coordinates in a physical list. You already know the formula for computing where each power point is picked up! So you might scrap the above code and rewrite your whole program as:



          int main() 
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          int n2 = n * n;
          printf("%dn", 1 + (n2 / 11));
          print_coords(get_coords_of_army(1, n), stdout);
          printf("(%d,%d)n", c.row, c.col);
          for (int i = 11; i <= n2; i += 11)
          print_coords(get_coords_of_army(i, n), stdout);




          Writing the function get_coords_of_army is left as an exercise for the reader. But the important thing to realize is that writing that function is supposed to be the challenge! You should develop the instinct and intuition for quickly breaking down a problem statement into sub-problems, and then solving those sub-problems. Notice that outside of main I don't need to do any input or output; I just have a very clean mathematical problem to solve.



          Coord get_coords_of_army(int which_army, int breadth_of_square);


          Everything else going on in this problem statement is basically a red herring.




          I note in passing that isDiv(x) is not a good name for a function that computes whether x is divisible by 11. You get points for naming it is...-something, but surely (A) is_divisible_by_11 would have been a better name, and (B) you don't really need a function for that!



          You could make the argument that this is futureproofing the code: what if the next iteration of the puzzle changes the locations of the power points? That's fair, and makes is_divisible_by_11 a bad name... but it doesn't make isDiv a good name! We might better write



          bool has_power_point(int which_army) 
          return (which_army == 1)


          and then back in our main function we can write simply



           printf("%dn", 1 + (n2 / 11));
          for (int i = 1; i <= n2; ++i)
          if (has_power_point(i))
          print_coords(get_coords_of_army(i, n), stdout);







          share|improve this answer













          You should try to keep your main function small and focused. (Well, you should try to keep every function you write small and focused!) For example, you might do something like this:



          struct Coord 
          int row, col;
          ;
          struct CoordList
          int size;
          Coord *data;
          ;

          void print_coords(Coord c, FILE *out)
          printf("(%d,%d)n", c.row, c.col);


          int main()
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          CoordList coords = collect_power_points(n);
          printf("%dn", coords.size);
          for (int i=0; i < coords.size; ++i)
          print_coords(coords.data[i]);




          Writing the little functions print_tab_delimited_matrix and collect_power_points is left as an exercise for the reader.




          Or, you might consider that there's no real point to collecting up all of the power-point coordinates in a physical list. You already know the formula for computing where each power point is picked up! So you might scrap the above code and rewrite your whole program as:



          int main() 
          int n;
          scanf("%d", &n);
          print_tab_delimited_matrix(n, stdout);
          int n2 = n * n;
          printf("%dn", 1 + (n2 / 11));
          print_coords(get_coords_of_army(1, n), stdout);
          printf("(%d,%d)n", c.row, c.col);
          for (int i = 11; i <= n2; i += 11)
          print_coords(get_coords_of_army(i, n), stdout);




          Writing the function get_coords_of_army is left as an exercise for the reader. But the important thing to realize is that writing that function is supposed to be the challenge! You should develop the instinct and intuition for quickly breaking down a problem statement into sub-problems, and then solving those sub-problems. Notice that outside of main I don't need to do any input or output; I just have a very clean mathematical problem to solve.



          Coord get_coords_of_army(int which_army, int breadth_of_square);


          Everything else going on in this problem statement is basically a red herring.




          I note in passing that isDiv(x) is not a good name for a function that computes whether x is divisible by 11. You get points for naming it is...-something, but surely (A) is_divisible_by_11 would have been a better name, and (B) you don't really need a function for that!



          You could make the argument that this is futureproofing the code: what if the next iteration of the puzzle changes the locations of the power points? That's fair, and makes is_divisible_by_11 a bad name... but it doesn't make isDiv a good name! We might better write



          bool has_power_point(int which_army) 
          return (which_army == 1)


          and then back in our main function we can write simply



           printf("%dn", 1 + (n2 / 11));
          for (int i = 1; i <= n2; ++i)
          if (has_power_point(i))
          print_coords(get_coords_of_army(i, n), stdout);








          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Aug 1 at 1:05









          Quuxplusone

          9,62011451




          9,62011451











          • So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
            – Phoenix
            Aug 1 at 8:50










          • @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
            – Quuxplusone
            Aug 1 at 18:13
















          • So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
            – Phoenix
            Aug 1 at 8:50










          • @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
            – Quuxplusone
            Aug 1 at 18:13















          So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
          – Phoenix
          Aug 1 at 8:50




          So my logic to create the matrix is good ? . I didnt find anything about it in the review. Thanks.
          – Phoenix
          Aug 1 at 8:50












          @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
          – Quuxplusone
          Aug 1 at 18:13




          @Phoenix: Well, I didn't look at your code very deeply — just deeply enough to see that it was one huge clump of nested for-loops that I didn't want to get too far into. From the above review, you should be able to tell that I would have tried to write print_tab_delimited_matrix(n) in terms of get_army_for_coords(coords, n), which is just the inverse of get_coords_of_army(i, n). (Think about how to use that relationship to write unit tests for your code!)
          – Quuxplusone
          Aug 1 at 18:13












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200690%2fcode-vita-chakravyuha%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation