{"id":3685,"date":"2019-08-01T00:01:24","date_gmt":"2019-08-01T07:01:24","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=3685"},"modified":"2019-08-09T17:47:26","modified_gmt":"2019-08-10T00:47:26","slug":"rotate-the-grid","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=3685","title":{"rendered":"Rotate the Grid"},"content":{"rendered":"<p>I&#8217;m not immersed in higher mathematics, therefore most of my programming puzzles tend to involve strings or other items I can easily comprehend. Beyond manipulating characters and strings, for my programming kung fu training I keep returning to the matrix or grid.<br \/>\n<!--more--><br \/>\nA grid is a two-dimensional array in C, a set of rows and columns defined as:<\/p>\n<p><code>int grid[8][8];<\/code><\/p>\n<p>The two dimensions are specified in brackets after the data type and variable name. They need not be equal, though in my mind equal dimensions define the difference between a grid\/matrix and what I&#8217;d call a table.<\/p>\n<p>The two-dimensional, double-bracket notation is merely for your reference. Internally, the grid&#8217;s data is stored in a linear fashion. So the same array can be declared as:<\/p>\n<p><code>int grid[64];<\/code><\/p>\n<p>To establish <code>grid[]<\/code> as a matrix and not a single file parade of 64 integers, you code the overhead, ensuring that data is manipulated and output in tidy rows and columns.<\/p>\n<p>For this month&#8217;s Exercise, your task is to create a two character grids of the same size, 5-by-5. The first grid is to be initialized randomly, filled with characters ranging from <code>'a'<\/code> to <code>'z'<\/code>. The second grid contains the same characters as the first, but it&#8217;s rotated 90 degrees clockwise. To wit:<\/p>\n<p><code>Original:<br \/>\n&nbsp;j  x  y  i  r<br \/>\n&nbsp;e  n  y  f  h<br \/>\n&nbsp;i  o  o  i  h<br \/>\n&nbsp;i  d  k  l  u<br \/>\n&nbsp;g  x  c  q  b<br \/>\nRotated:<br \/>\n&nbsp;g  i  i  e  j<br \/>\n&nbsp;x  d  o  n  x<br \/>\n&nbsp;c  k  o  y  y<br \/>\n&nbsp;q  l  i  f  i<br \/>\n&nbsp;b  u  h  h  r <\/code><\/p>\n<p>In order, your tasks are:<\/p>\n<ol>\n<li>Fill the grid\/matrix with random letters, a to z<\/li>\n<li>Output the original matrix<\/li>\n<li>Fill a second grid\/matrix with values from the first, but rotated 90&deg; clockwise<\/li>\n<li>Output the second, rotated matrix<\/li>\n<\/ol>\n<p>Please try this Exercise on your own before you peek at <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3698\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flip the matrix on its side. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3685\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3685","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3685"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3685\/revisions"}],"predecessor-version":[{"id":3713,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3685\/revisions\/3713"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}