{"id":263,"date":"2024-08-22T19:18:11","date_gmt":"2024-08-22T19:18:11","guid":{"rendered":"https:\/\/learnx.ca\/mt\/?page_id=263"},"modified":"2025-11-30T15:12:22","modified_gmt":"2025-11-30T15:12:22","slug":"infinity-coding","status":"publish","type":"page","link":"https:\/\/learnx.ca\/mt\/infinity-coding\/","title":{"rendered":"CODING PUZZLES"},"content":{"rendered":"\n<p>[<a href=\"https:\/\/learnx.ca\/mt\/infinity-coding\/#s\">Solutions<\/a>&nbsp;are shown after the puzzles]<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 1: Infinity (Scratch)<\/h4>\n\n\n\n<p>Go to <a href=\"https:\/\/scratch.mit.edu\/projects\/964712868\/editor\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/scratch.mit.edu\/projects\/964712868\/editor<\/a> .<\/p>\n\n\n\n<p>Run the code to see the list of numbers shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"295\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c1.png\" alt=\"\" class=\"wp-image-290\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c1.png 388w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c1-300x228.png 300w\" sizes=\"auto, (max-width: 388px) 85vw, 388px\" \/><\/figure>\n\n\n\n<p><strong>1. <\/strong>The code finds the sum of 10 fractions.<\/p>\n\n\n\n<p>  <strong>  a) <\/strong><span style=\"font-size: revert;\">Which fractions are they?<\/span><\/p>\n\n\n\n<p>  <strong>  b)<\/strong> What is the sum if this pattern continues forever?<\/p>\n\n\n\n<p><strong>2.<\/strong> How does the code work?<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"240\" height=\"306\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/09\/infinity-one-quarter.png\" alt=\"\" class=\"wp-image-449\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/09\/infinity-one-quarter.png 240w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/09\/infinity-one-quarter-235x300.png 235w\" sizes=\"auto, (max-width: 240px) 85vw, 240px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>3.<\/strong> Edit the code as shown on the right to find the sum of fractions 1\/4, 1\/16, 1\/64, and so on. <\/p>\n\n\n\n<p><strong>a)<\/strong> <span style=\"font-size: revert;\">What is the sum?<\/span><\/p>\n\n\n\n<p><strong>b) <\/strong>How does this sum make sense?<\/p>\n\n\n\n<p><strong>4. <\/strong>Edit the code to find the sum of fractions 1\/2, 1\/8, 1\/32, and so on.<\/p>\n\n\n\n<p>    <strong>a)<\/strong> <span style=\"font-size: revert;\">What is the sum?<\/span><\/p>\n\n\n\n<p><strong>b) <\/strong>How does this sum make sense?<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 2: Infinity (Python)<\/h4>\n\n\n\n<p>Go to <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/console\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/cscircles.cemc.uwaterloo.ca\/console<\/a> .<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"130\" height=\"251\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c4.png\" alt=\"\" class=\"wp-image-294\"\/><\/figure>\n<\/div>\n\n\n<p>Enter and run this Python code to list the numbers shown on the right.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"266\" height=\"143\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c3.png\" alt=\"\" class=\"wp-image-293\"\/><\/figure>\n\n\n\n<p><strong>1. <\/strong>The code finds the sum of 10 fractions.<\/p>\n\n\n\n<p>  <strong>  a) <\/strong><span style=\"font-size: revert;\">Which fractions are they?<\/span><\/p>\n\n\n\n<p>  <strong>  b)<\/strong> What is the sum if this pattern continues forever?<\/p>\n\n\n\n<p><strong>2.<\/strong> How does the code work?<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"284\" height=\"157\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/09\/infinity-python-one-quarter.png\" alt=\"\" class=\"wp-image-451\"\/><\/figure>\n<\/div>\n\n\n<p><strong>3.<\/strong> Edit the code as shown on the right to find the sum of fractions 1\/4, 1\/16, 1\/64, and so on. <\/p>\n\n\n\n<p><strong>a)<\/strong> <span style=\"font-size: revert;\">What is the sum?<\/span><\/p>\n\n\n\n<p><strong>b) <\/strong>How does this sum make sense?<\/p>\n\n\n\n<p><strong>4. <\/strong>Edit the code to find the sum of fractions 1\/2, 1\/8, 1\/32, and so on.<\/p>\n\n\n\n<p>    <strong>a)<\/strong> <span style=\"font-size: revert;\">What is the sum?<\/span><\/p>\n\n\n\n<p><strong>b) <\/strong>How does this sum make sense?<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 3: Natural Density<\/h4>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"281\" height=\"59\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c6.png\" alt=\"\" class=\"wp-image-298\"\/><\/figure>\n<\/div>\n\n\n<p>Natural numbers = {1, 2, 3, 4, 5, 6, 7, 8 \u2026}<\/p>\n\n\n\n<p>Even numbers = {2, 4, 6, 8, 10 \u2026}<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"141\" height=\"135\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c7.png\" alt=\"\" class=\"wp-image-299\"\/><\/figure>\n<\/div>\n\n\n<p><strong><em>Natural density<\/em> <\/strong>of even numbers&nbsp;<\/p>\n\n\n\n<p>= Chance of picking an even number from the infinite set of natural numbers<\/p>\n\n\n\n<p>= 0.5<\/p>\n\n\n\n<p><strong>Puzzles<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>What is the natural density of the odd numbers: {1, 3, 5, 7, 9 &#8230;}?<\/li>\n\n\n\n<li>What is the natural density of multiples of 3: {3, 6, 9, 12, 15 &#8230;}?<\/li>\n\n\n\n<li>What is the natural density of multiples of 10: {10, 20, 30, 40, 50 &#8230;}?<\/li>\n\n\n\n<li>What is the natural density of the number 1?<\/li>\n\n\n\n<li>What is the natural density of the square numbers: {1, 4, 9, 16, 25 &#8230;}?<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading has-dark-gray-color has-text-color has-link-color wp-elements-fd657f999b5c075dfd639e73e4ea691e\" id=\"s\">SOLUTIONS<\/h1>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 1<\/h4>\n\n\n\n<p><strong>1.a)<\/strong>&nbsp; 1\/2, 1\/4, 1\/8, 1\/16 \u2026&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p> <strong>1.b)<\/strong>&nbsp; 1&nbsp;&nbsp;[we see in the image below that all these fractions fit in 1 square]<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"162\" height=\"159\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-a2.png\" alt=\"\" class=\"wp-image-280\"\/><\/figure>\n\n\n\n<p><strong>3.<\/strong>&nbsp; 1\/3&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>4.<\/strong> 2\/3<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"217\" height=\"319\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-a11.png\" alt=\"\" class=\"wp-image-286\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-a11.png 217w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-a11-204x300.png 204w\" sizes=\"auto, (max-width: 217px) 85vw, 217px\" \/><\/figure>\n<\/div>\n\n\n<p>In the 2 images on the right, we see that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>the pink rectangle is twice the size of the blue square;<\/li>\n\n\n\n<li>the yellow rectangle is twice the size of the green square;<\/li>\n\n\n\n<li>the purple rectangle is twice the size of the orange square;<\/li>\n\n\n\n<li>and so forth.<\/li>\n<\/ul>\n\n\n\n<p>So, the rectangular pieces make up 2\/3 of the square below, and the remaining square pieces make up the remaining 1\/3.<\/p>\n\n\n\n<p>That is, 1\/2 + 1\/8 + 1\/32 + \u2026 = 2\/3.<\/p>\n\n\n\n<p>And, 1\/4 + 1\/16 + 1\/64 + &#8230; = 1\/3.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 2<\/h4>\n\n\n\n<p><strong>1.a)<\/strong>&nbsp; 1\/2, 1\/4, 1\/8, 1\/16 \u2026&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong> 1.b)<\/strong>&nbsp; 1<\/p>\n\n\n\n<p><strong>2.<\/strong>&nbsp; 1\/2<\/p>\n\n\n\n<p><strong>3.<\/strong>&nbsp; 1\/3&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>4.a)<\/strong>&nbsp; 2\/3<\/p>\n\n\n\n<p>[see explanation in Puzzle 1, #3 &amp; 4]<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Puzzle 3<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>0. 5 or 1\/2 (as half the natural numbers are odd)<\/li>\n\n\n\n<li>0.333&#8230; or 1\/3 (since 1\/3 of the natural numbers are multiples of 3)<\/li>\n\n\n\n<li>0.1 or 1\/10 (since 1\/10 of the natural numbers are multiples of 10)<\/li>\n\n\n\n<li>&nbsp;<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For natural numbers 1-10, there is 1\/10 chance of randomly picking the number 1.<\/li>\n\n\n\n<li>For natural numbers 1-100, there is 1\/100 chance of randomly picking the number 1.<\/li>\n\n\n\n<li>For natural numbers 1-1000, there is 1\/1000 chance of randomly picking the number 1.<\/li>\n\n\n\n<li>As we consider large and larger intervals, the probability decreases. Its limit is 0.<\/li>\n\n\n\n<li>This is like the walk to the door, where the distance left to walk is decreasing, and getting closer and closer to 0, which is its limit.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"310\" height=\"66\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c10.png\" alt=\"\" class=\"wp-image-300\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c10.png 310w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c10-300x64.png 300w\" sizes=\"auto, (max-width: 310px) 85vw, 310px\" \/><\/figure>\n\n\n\n<p><strong>5. <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Run the code at <a href=\"https:\/\/scratch.mit.edu\/projects\/565845359\/editor\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/scratch.mit.edu\/projects\/565845359\/editor<\/a><\/li>\n\n\n\n<li>What does this code do?<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"534\" height=\"366\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c8.png\" alt=\"\" class=\"wp-image-301\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c8.png 534w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c8-300x206.png 300w\" sizes=\"auto, (max-width: 534px) 85vw, 534px\" \/><\/figure>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"139\" height=\"381\" src=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c9.png\" alt=\"\" class=\"wp-image-302\" srcset=\"https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c9.png 139w, https:\/\/learnx.ca\/mt\/wp-content\/uploads\/2024\/08\/infinity-c9-109x300.png 109w\" sizes=\"auto, (max-width: 139px) 85vw, 139px\" \/><\/figure>\n<\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>Run the code with different intervals: 100, 10,000 and 1,000,000.<\/li>\n\n\n\n<li>Notice how the density changes.<\/li>\n\n\n\n<li>What is the limit of the natural density values?<\/li>\n<\/ul>\n\n\n\n<p>ABOUT THE NATURAL DENSITY OF SQUARE NUMBERS:<\/p>\n\n\n\n<p>The natural density of square numbers is counter-intuitive, as there is an infinite number of square numbers. How can their density be 0?<\/p>\n\n\n\n<p>But as we see from the coding simulation, the density of square numbers gets closer and closer to 0 as we consider larger intervals of natural numbers.<\/p>\n\n\n\n<p>We may also look at this problem algebraically:<\/p>\n\n\n\n<p>Natural density of square numbers<\/p>\n\n\n\n<p>      = number of square numbers \/ number of natural numbers<\/p>\n\n\n\n<p>      = sqrt(N) \/ N <\/p>\n\n\n\n<p>      = 1 \/ sqrt(N)<\/p>\n\n\n\n<p><strong>Note: <\/strong>IFor the first N natural numbers, there are at most sqrt(N) square numbers. As N becomes larger and larger, 1 \/ sqrt(N) gets closer and closer zero.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Solutions&nbsp;are shown after the puzzles] Puzzle 1: Infinity (Scratch) Go to https:\/\/scratch.mit.edu\/projects\/964712868\/editor . Run the code to see the list of numbers shown below. 1. The code finds the sum of 10 fractions. a) Which fractions are they? b) What is the sum if this pattern continues forever? 2. How does the code work? 3. &hellip; <a href=\"https:\/\/learnx.ca\/mt\/infinity-coding\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CODING PUZZLES&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-263","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/pages\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":26,"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/pages\/263\/revisions"}],"predecessor-version":[{"id":875,"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/pages\/263\/revisions\/875"}],"wp:attachment":[{"href":"https:\/\/learnx.ca\/mt\/wp-json\/wp\/v2\/media?parent=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}