{"id":1445,"date":"2003-11-08T12:31:33","date_gmt":"2003-11-08T12:31:33","guid":{"rendered":"https:\/\/cml-a.com\/content\/?p=1445"},"modified":"2003-11-08T12:31:33","modified_gmt":"2003-11-08T12:31:33","slug":"number-spiral","status":"publish","type":"post","link":"https:\/\/cml-a.com\/content\/2003\/11\/08\/number-spiral\/","title":{"rendered":"Number spiral"},"content":{"rendered":"\n<p>An old contest question.<\/p>\n\n\n\n<p>Taken from this forum post--<br><a href=\"http:\/\/compsci.ca\/v3\/viewtopic.php?t=2192\">http:\/\/compsci.ca\/v3\/viewtopic.php?t=2192<\/a><\/p>\n\n\n\n<p>The question<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>A spiral of numbers can start and end with any positive integers less than 100. Write a program which will accept two positive integers x and y as input, and output a list of numbers from x to y inclusive, shown in a spiral. You may assume that the end value is greater than or equal to the start value.\n\n\nA spiral starts with the first number in the centre. The next number appears immediately below the first number. The spiral continues with the numbers increasing in a counter-clockwise direction until the last number is printed. Read the input from the keyboard and display the output on the screen.<\/code><\/pre>\n\n\n\n<p> Sample session: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Start value:\n10\nEnd value:\n27\n27 26\n16 15 14 25\n17 10 13 24\n18 11 12 23\n19 20 21 22\n\n\nStart value:\n10\nEnd value:\n12\n\n\n12 11\n7 10\n8 9<\/code><\/pre>\n\n\n\n<p>In Object-Oriented Turing, the solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var start, finish, r, c, counter, i, rchange, cchange : int\nget start, finish\nr := 13\nc := 40\ncounter := 1\ni := start\nrchange := 1\ncchange := 4\nloop\nexit when i >= finish\nfor j : 1 .. counter\nlocate (r, c)\nif i &lt; 10 then put \" \", i .. else put i .. end if exit when i >= finish\ni += 1\nr += rchange\nend for\nfor j : 1 .. counter\nlocate (r, c)\nif i &lt; 10 then put \" \", i .. else put i .. end if exit when i >= finish\ni += 1\nc += cchange\nend for\nrchange *= -1\ncchange *= -1\ncounter += 1\nend loop<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An old contest question. Taken from this forum post&#8211;http:\/\/compsci.ca\/v3\/viewtopic.php?t=2192 The question Sample session: In Object-Oriented Turing, the solution:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[178],"class_list":["post-1445","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-software-development-project"],"_links":{"self":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/1445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/comments?post=1445"}],"version-history":[{"count":0,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/1445\/revisions"}],"wp:attachment":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/media?parent=1445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/categories?post=1445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/tags?post=1445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}