
    
        
        
        
                
        
        
        
                
    
        
        
                
        
        
        
                
        
        
        
                
        
        
        
                
    
        
        
            
{"version":"https:\/\/jsonfeed.org\/version\/1","title":"mathspp.com feed","home_page_url":"https:\/\/mathspp.com\/blog\/tags\/invariants","feed_url":"https:\/\/mathspp.com\/blog\/tags\/invariants.json","description":"Stay up-to-date with the articles on mathematics and programming that get published to mathspp.com.","author":{"name":"Rodrigo Gir\u00e3o Serr\u00e3o"},"items":[{"title":"Problem #062 \u2013 sliding coins","date_published":"2022-06-12T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/problems\/sliding-coins","url":"https:\/\/mathspp.com\/blog\/problems\/sliding-coins","content_html":"<p>Can you align all of the coins on the right edge of the board?<\/p>\n\n<figure class=\"image-caption\"><img title=\"Diagram of the coin positions for the problem.\" alt=\"\" src=\"\/user\/pages\/02.blog\/03.problems\/p062-sliding-coins\/_setup.webp\"><figcaption class=\"\">Diagram of the coin positions for the problem.<\/figcaption><\/figure><h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>The diagram above shows a 3 by 4 grid with 3 coins, one per row and one per column,\nsuch that the rightmost column of the grid is empty.<\/p>\n<p>You are allowed to slide the coins to the columns on their right,\nbut the coins can never leave the board (nor can they be moved back to the left).\nAlso, you always have to move two coins at a time.<\/p>\n<p>Thus, this is a legal move:<\/p>\n<figure class=\"image-caption\"><img title=\"A legal move sliding the top two coins one slot to the right.\" alt='\"The diagram showing an example of a legal move with some arrows.\"' src=\"\/user\/pages\/02.blog\/03.problems\/p062-sliding-coins\/_legal_move.webp\"><figcaption class=\"\">A legal move sliding the top two coins one slot to the right.<\/figcaption><\/figure><p>But moving a single coin, such as in the diagram below, is not allowed:<\/p>\n<figure class=\"image-caption\"><img title=\"An illegal move that slides only one coin to the right.\" alt='\"The diagram showing an example of an illegal move.\"' src=\"\/user\/pages\/02.blog\/03.problems\/p062-sliding-coins\/_illegal_move.webp\"><figcaption class=\"\">An illegal move that slides only one coin to the right.<\/figcaption><\/figure><p>Your objective is to reach this position:<\/p>\n<figure class=\"image-caption\"><img title=\"Target position.\" alt='\"The same 3 by 4 grid containing a coin per row, with all coins on the rightmost column.\"' src=\"\/user\/pages\/02.blog\/03.problems\/p062-sliding-coins\/_objective.webp\"><figcaption class=\"\">Target position.<\/figcaption><\/figure><p>Can you do it?<\/p>\n<p>What if you extend the board two columns to the left and two rows up,\nand add another two coins along the diagonal?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought!<\/p>\n<\/div>\n<p>This is an adaptation of a problem from the <a href=\"https:\/\/amzn.to\/3NJUn5D\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">book &ldquo;Algorithmic Puzzles&rdquo;<\/a> by Anany Levitin and Maria Levitin.<sup id=\"fnref1:1\"><a href=\"#fn:1\" class=\"footnote-ref\">1<\/a><\/sup><\/p>\n<h2 id=\"solvers\">Solvers<a href=\"#solvers\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Congratulations to the ones that solved this problem correctly and, in particular, to the ones\nwho sent me their correct solutions:<\/p>\n<ul><li>David H., Taiwan;<\/li>\n<\/ul><p>Know how to solve this?\nJoin the list of solvers by <a href=\"mailto:rodrigo@mathspp.com?subject=Solution%20to%20Problem%20#062%20%E2%80%93%20sliding%20coins\" class=\"mailto\">emailing me<\/a> your solution!<\/p>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>You can move all coins to the right in 3 moves:<\/p>\n<ol><li>move the top and bottom coins (this aligns the top and middle coins while placing the bottom coin in the rightmost column);<\/li>\n<li>move the top and middle coins; and<\/li>\n<li>move the top and middle coins again.<\/li>\n<\/ol><p>This diagram shows the evolution of the grid:<\/p>\n<pre><code>X . . .  start\n. X . .\n. . X .\n\n. X . . &gt;\n. X . .\n. . . X &gt;\n\n. . X . &gt;\n. . X . &gt;\n. . . X\n\n. . . X &gt;\n. . . X &gt;\n. . . X<\/code><\/pre>\n<p>If we extend the board up and left, we'd have this starting configuration:<\/p>\n<pre><code>X . . . . .\n. X . . . .\n. . X . . .\n. . . X . .\n. . . . X .<\/code><\/pre>\n<p>Now, consider the total number of spaces to the right of the coins:<\/p>\n<pre><code>X 1 2 3 4 5\n. X 6 7 8 9\n. . X 0 1 2\n. . . X 3 4\n. . . . X 5<\/code><\/pre>\n<p>We see that there are 15 spaces on the grid to the right of coins.\nWe also know that each time we move two coins, the number of spaces to the right of the coins decreases by 2.\nNow, if we were to align all coins on the rightmost column, the number of spaces to the right of the coins would be 0.\nHowever, we can't...<\/p>","summary":"Can you align all of the coins on the right edge of the board?","date_modified":"2025-07-23T16:49:02+02:00","tags":["invariants","logic","mathematics"],"image":"\/user\/pages\/02.blog\/03.problems\/p062-sliding-coins\/thumbnail.webp"},{"title":"Problem #036 - huge, tiny triangle","date_published":"2021-05-19T00:00:00+02:00","id":"https:\/\/mathspp.com\/blog\/problems\/huge-tiny-triangle","url":"https:\/\/mathspp.com\/blog\/problems\/huge-tiny-triangle","content_html":"<p>Can you find a really large triangle that is also really tiny?<\/p>\n\n<p><img alt=\"\" src=\"\/user\/pages\/02.blog\/03.problems\/p036-huge-tiny-triangle\/thumbnail.webp\"><\/p>\n<h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Does there exist a triangle that has an area larger than the Earth's surface\n(approximately 510 million km\u00b2)\nbut whose heights sum up to less than one centimetre?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought and <a href=\"mailto:rodrigo@mathspp.com?subject=Solution%20to%20Problem%20#036%20-%20huge,%20tiny%20triangle\" class=\"mailto\">send me your solution<\/a>!<\/p>\n<\/div>\n<p>I saw this problem in the Facebook page of <a href=\"https:\/\/www.facebook.com\/nucmfctnova\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">a group of maths students from a local university<\/a>.<\/p>\n<p>If you need any clarification whatsoever, feel free to ask in the comment section below.<\/p>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Yes! There exists such a triangle.<\/p>\n<p>Let <span class=\"mathjax mathjax--inline\">\\([ABC]\\)<\/span> be a triangle with sides <span class=\"mathjax mathjax--inline\">\\(a\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(b\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(c\\)<\/span>,\nand let its respective heights be <span class=\"mathjax mathjax--inline\">\\(h_a\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(h_b\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(h_c\\)<\/span>.<\/p>\n<p>The area of this triangle is, therefore,<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n\\frac{ah_a}2 = \\frac{bh_b}2 = \\frac{ch_c}2 ~~~.\\]<\/p>\n<p>From the equalities above we conclude<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n\\begin{cases}\nah_a = ch_c \\iff h_a = \\frac{ch_c}a \\\\\nbh_b = ch_c \\iff h_b = \\frac{ch_c}b\n\\end{cases} ~~~.\\]<\/p>\n<p>Because we are talking about a triangle, we know that\n<span class=\"mathjax mathjax--inline\">\\(c &lt; a + b\\)<\/span>, which means we can take a look at the equation\nabove and remove <span class=\"mathjax mathjax--inline\">\\(c\\)<\/span> from there:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\nh_a = \\frac{ch_c}a \\leq \\frac{(a + b)h_c}{a} ~~~.\\]<\/p>\n<p>If, additionally, the triangle <span class=\"mathjax mathjax--inline\">\\([ABC]\\)<\/span> has two equal sides,\n<span class=\"mathjax mathjax--inline\">\\(a = b\\)<\/span>, we get<\/p>\n<p class=\"mathjax mathjax--block\">\\[\nh_a \\leq 2h_c ~~~,\\]<\/p>\n<p>and, similarly,<\/p>\n<p class=\"mathjax mathjax--block\">\\[\nh_b \\leq 2h_c ~~~.\\]<\/p>\n<p>Now, all we have to do is sum the three heights of the triangle:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\nh_a + h_b + h_c \\leq 2h_c + 2h_c + h_c = 5h_c ~~~.\\]<\/p>\n<p>Therefore, in our isosceles triangle with equal sides <span class=\"mathjax mathjax--inline\">\\(a\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(b\\)<\/span>,\nwe have that the sum of the three heights is less than or equal\nto <span class=\"mathjax mathjax--inline\">\\(5h_c\\)<\/span>, where <span class=\"mathjax mathjax--inline\">\\(h_c\\)<\/span> is the height relative to the side\nthat is unequal to the other two.\nWith that in mind, we can make a really \u201clong\u201d triangle\n(that is, for which <span class=\"mathjax mathjax--inline\">\\(c\\)<\/span> is large)\nthat is short\n(that is, for which <span class=\"mathjax mathjax--inline\">\\(h_c\\)<\/span> is small)\nso that it satisfies the restrictions in the problem statement.\nIn fact, our reasoning shows that there are triangles with areas\nthat can be arbitrarily large, while their three heights sum\nup to values that are arbitrarily small.<\/p>\n<p>Makes sense?<\/p>\n<p><a href=\"https:\/\/mathspp.com\/subscribe\">Don't forget to subscribe to the newsletter<\/a> to get bi-weekly\nproblems sent straight to your inbox and to add your reaction below.<\/p>","summary":"Can you find a really large triangle that is also really tiny?","date_modified":"2025-07-23T16:49:02+02:00","tags":["geometry","invariants","mathematics"],"image":"\/user\/pages\/02.blog\/03.problems\/p036-huge-tiny-triangle\/thumbnail.webp"},{"title":"Problem #031 - piped ants","date_published":"2021-03-07T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/piped-ants","url":"https:\/\/mathspp.com\/blog\/problems\/piped-ants","content_html":"<p>A bunch of ants are left inside a very, very, tight tube,\nand they keep colliding with each other and turning around.\nHow long will it take them to escape?<\/p>\n\n<figure class=\"image-caption\"><img title=\"Photo by Lorenz Lippert on Unsplash.\" alt=\"\" src=\"\/images\/b\/5\/c\/7\/d\/b5c7d316e57f354e6075050e2b50f7627c3d279b-thumbnail.png\"><figcaption class=\"\">Photo by Lorenz Lippert on Unsplash.<\/figcaption><\/figure>\n<h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Suppose you have a very thin pipe.\nThe pipe is the exact width of an ant, so that ants\ncan travel inside the pipe, but they can't cross paths because\nthe pipe isn't wide enough for that.\nAssume an ant takes exactly 1h to travel through said pipe.<\/p>\n<p>I will now place several ants along the pipe, facing different\ndirections, and all ants will start walking in a straight line.\nWhen two ants collide, they both turn around and continue\nwalking in the opposite direction they were walking in.\nWhen an ant reaches the end of the pipe, the ant just leaves the pipe.<\/p>\n<p>What is the shortest amount of time that ensures all ants have left the pipe?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought!<\/p>\n<\/div>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>This problem may look quite confusing if you try to imagine all the interactions\/bumps\nthere might be between an arbitrary number of ants inside the pipe.\nHowever, the only thing that matters to us is the time each ant takes to leave the pipe,\nand not the number of times the ants bump against each other!<\/p>\n<p>Imagine that two ants, <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span>, bump against each other at a given location\nof the pipe.\nLet us suppose that <span class=\"mathjax mathjax--inline\">\\(t_A\\)<\/span> is the time it would take ant <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> to leave the pipe if it\nwere alone in the pipe, and similarly for <span class=\"mathjax mathjax--inline\">\\(t_B\\)<\/span> and ant <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span>.\nWhen the two ants <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span> bump against each other and turn around, ant <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> is\nnow facing in the direction that <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span> was facing, and therefore has to walk whatever\n<span class=\"mathjax mathjax--inline\">\\(B\\)<\/span> <em>was<\/em> going to walk, therefore the time that the ant <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> is going to take is now <span class=\"mathjax mathjax--inline\">\\(t_B\\)<\/span>.\nSimilarly, when the ant <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span> turns around and faces the same distance that <span class=\"mathjax mathjax--inline\">\\(A\\)<\/span> <em>was<\/em>\ngoing to walk, the time it will take ant <span class=\"mathjax mathjax--inline\">\\(B\\)<\/span> to leave the pipe becomes <span class=\"mathjax mathjax--inline\">\\(t_A\\)<\/span>.<\/p>\n<p>When two ants bump, they swap the respective times they would take to leave the pipes\nif they were alone in the pipe.\nThis shows that the ants bumping against one another does not make them spend more time\n<em>in total<\/em>, it just means that the ants swap the roles of the ants that were closer to\nthe exit and farther away from the exit.<\/p>\n<p><a href=\"https:\/\/mathspp.com\/subscribe\">Don't forget to subscribe to the newsletter<\/a> to get bi-weekly\nproblems sent straight to your inbox and to add your reaction below.<\/p>","date_modified":"2025-07-23T16:49:02+02:00","tags":["combinatorics","invariants","mathematics"],"image":"\/user\/pages\/02.blog\/03.problems\/p031-piped-ants\/thumbnail.png"},{"title":"Problem #004 - solvability of the water buckets","date_published":"2017-11-22T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/solvability-water-buckets","url":"https:\/\/mathspp.com\/blog\/problems\/solvability-water-buckets","content_html":"<!-- v -->\n<p>In <a href=\"\/blog\/water-buckets\">this post<\/a> I talked about the riddle of the water buckets. Now I challenge you to prove that in some situations it is <em>impossible<\/em> to solve it!<\/p>\n\n<figure class=\"image-caption\"><img title=\"Photo by Nils Schirmer on Unsplash\" alt=\"A grayscale image with 3 buckets\" src=\"\/images\/9\/1\/f\/3\/6\/91f36efb87d56de14102dd77ae7037c7d1669d9b-buckets.jpg\"><figcaption class=\"\">Photo by Nils Schirmer on Unsplash<\/figcaption><\/figure><!-- ^ --><h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>You have <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> buckets, each bucket with capacity for <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> litres of water, <span class=\"mathjax mathjax--inline\">\\(i = 1, \\cdots, n\\)<\/span>. You want to manipulate the buckets in such a way that one of them holds exactly <span class=\"mathjax mathjax--inline\">\\(t\\)<\/span> litres of water, knowing that the only moves you can do are:<\/p>\n<ul><li>completely fill up bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> so that it holds <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> litres of water;<\/li>\n<li>completely empty bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> so that it now holds <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span> litres of water;<\/li>\n<li>move water from bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> to bucket <span class=\"mathjax mathjax--inline\">\\(j\\)<\/span>, until bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> becomes empty or bucket <span class=\"mathjax mathjax--inline\">\\(j\\)<\/span> becomes full, whatever happens first.<\/li>\n<\/ul><p>Prove that, if <span class=\"mathjax mathjax--inline\">\\(t\\)<\/span> is not a multiple of the greatest common divisor of the <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(i = 1, \\cdots, n\\)<\/span> then it is impossible for a single bucket to hold exactly <span class=\"mathjax mathjax--inline\">\\(t\\)<\/span> litres of water.<\/p>\n<p>For example, if the buckets have capacities <span class=\"mathjax mathjax--inline\">\\(4\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(6\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(t = 3\\)<\/span>, then you can't perform the moves above to get exactly <span class=\"mathjax mathjax--inline\">\\(3\\)<\/span> litres of water into one of the two buckets as the greatest common divisor of <span class=\"mathjax mathjax--inline\">\\(4\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(6\\)<\/span> is <span class=\"mathjax mathjax--inline\">\\(\\gcd(4, 6) = 2\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(3\\)<\/span> is <em>not<\/em> a multiple of <span class=\"mathjax mathjax--inline\">\\(2\\)<\/span>.<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought... and give it an actual shot! Take out a piece of paper and a pencil and get your brain working!<\/p>\n<\/div>\n<p>If you need any clarification whatsoever, feel free to ask in the comment section below.<\/p>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>A possible solution is to consider a clever invariant that applies to the amount of water that each bucket is holding at any point in time. To make this easier, let's call <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> to the greatest common divisor of the <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(i = 1, \\cdots, n\\)<\/span> (<span class=\"mathjax mathjax--inline\">\\(d = \\gcd(c_1, \\cdots, c_n)\\)<\/span>). Let's also say the amount of water in bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> is <span class=\"mathjax mathjax--inline\">\\(w_i\\)<\/span>. We will show that, regardless of the moves we make, <span class=\"mathjax mathjax--inline\">\\(w_i\\)<\/span> is <em>always<\/em> a multiple of <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> for all <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> (which we write <span class=\"mathjax mathjax--inline\">\\(d | w_i\\)<\/span> for _\"<span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> divides <span class=\"mathjax mathjax--inline\">\\(w_i\\)<\/span>\"_).<\/p>\n<p>At the start all buckets are empty, so <span class=\"mathjax mathjax--inline\">\\(w_1 = \\cdots = w_n = 0\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span> is a multiple of <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> so that is that. Now we show that the three moves above preserve this property that <span class=\"mathjax mathjax--inline\">\\(d | w_i\\ \\forall i\\)<\/span>.<\/p>\n<ul><li>Emptying bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span>: this means <span class=\"mathjax mathjax--inline\">\\(w_i = 0\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(d | 0\\)<\/span> so everything is good;<\/li>\n<li>Filling bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span>: this means <span class=\"mathjax mathjax--inline\">\\(w_i = c_i\\)<\/span> but, by definition, <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> is <em>a<\/em> divisor of <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> so certainly we have <span class=\"mathjax mathjax--inline\">\\(d | c_i\\)<\/span>;<\/li>\n<li>Moving water from bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> to bucket <span class=\"mathjax mathjax--inline\">\\(j\\)<\/span> until either bucket <span class=\"mathjax mathjax--inline\">\\(i\\)<\/span> becomes empty or bucket <span class=\"mathjax mathjax--inline\">\\(j\\)<\/span> becomes full, whatever happens first: before we move water around we have that <span class=\"mathjax mathjax--inline\">\\(d | w_i\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(d | w_j\\)<\/span> so we can say that <span class=\"mathjax mathjax--inline\">\\(w_i = k_i d\\)<\/span> and...<\/li><\/ul>","summary":"This blog post contains a problem related to the riddle of the water buckets and a setting in which it is impossible to solve.","date_modified":"2025-07-23T16:49:02+02:00","tags":["invariants","mathematics","modular arithmetic"],"image":"\/user\/pages\/02.blog\/03.problems\/p004-solvability-of-the-water-buckets\/buckets.jpg"},{"title":"Problem #003 - a quarrel in the Shire","date_published":"2017-11-07T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/quarrel-in-the-shire","url":"https:\/\/mathspp.com\/blog\/problems\/quarrel-in-the-shire","content_html":"<p>Gandalf has some Hobbits to appease but his task seems to go on forever. Can you give him a hand..?<\/p>\n<!-- v -->\n\n<p><img alt=\"A picture of the Shire\" src=\"\/images\/a\/c\/e\/6\/8\/ace680fedf424ad0b3347f680e223a906fa63d79-shire.jpg\"><\/p>\n<p>Once again I bring you a problem alongside my proposed solution. If you find any mistakes or come up with a different solution, please let me know!<\/p>\n<!-- ^ -->\n<h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>The Shire is a lovely place where <span class=\"mathjax mathjax--inline\">\\(N\\)<\/span> Hobbits live in perfect harmony. Or at least they lived, until a Hobbit decided to become an outside decorator and convinced some of his friends to paint their front doors with a very <em>fashionable<\/em> purple (all doors were yellow before that preposterous change).<\/p>\n<p>Overnight, the perfect balance and harmony in which the Hobbits lived shattered, and Hobbits whose doors were different colours couldn't stand one another.<\/p>\n<p>Worried, the great and wise Gandalf hurried to the Shire to try and settle this matter. This was what he decided to do: in alphabetical order, he would visit each Hobbit. When visiting a Hobbit, he would change the colour of its door if and only if there were more Hobbits mad at him than there were Hobbits at peace with him. After visiting each Hobbit once, he would visit them all again in the same order, and then again, and then again, ..., repeating this process until a complete round of visits didn't change a thing.<\/p>\n<p>Is Gandalf's task always going to end, regardless of <span class=\"mathjax mathjax--inline\">\\(N\\)<\/span> and of the way the doors are coloured when he first arrives? Or are there values of <span class=\"mathjax mathjax--inline\">\\(N\\)<\/span> and\/or door colourings such that Gandalf will have to spend an eternity trying to solve the Hobbits' problems?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought... Grab a piece of paper and play out some scenarios by hand!<\/p>\n<\/div>\n<p>If you need any clarification whatsoever, feel free to ask in the comment section below.<\/p>\n<div class=\"notices green\">\n<p><strong>Hint<\/strong>: Gandalf's endeavour is always a finite one.<\/p>\n<\/div>\n<div class=\"notices green\">\n<p><strong>Hint<\/strong>: look for a \"semi-invariant\"; a quantity that can only change in a certain way, which allows you to verify that Gandalf will rest eventually.<\/p>\n<\/div>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Gandalf's task always has an end. To see why, imagine the <span class=\"mathjax mathjax--inline\">\\(N\\)<\/span> Hobbits represented as dots, and every two Hobbits are connected by a line. That line is green if they are friendly towards each other (their front doors have the same colour) and red if their front doors have different colours. Now count the number of red lines in that representation and call it <span class=\"mathjax mathjax--inline\">\\(R_0\\)<\/span>, where the <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span> indicates the number of visits Gandalf has already paid to the Hobbits. If Gandalf already visited <span class=\"mathjax mathjax--inline\">\\(t\\)<\/span> Hobbits, let <span class=\"mathjax mathjax--inline\">\\(R_t\\)<\/span> denote the number of red lines in the representation I defined earlier.<\/p>\n<p>It should be fairly easy to see that we have <span class=\"mathjax mathjax--inline\">\\(R_{t+1} \\leq R_t\\)<\/span>. This is true because when Gandalf visits a Hobbit, he will only change its door if that means the number of green lines increases, i.e. the number of red lines decreases. This means only two things can happen:<\/p>\n<ul><li>For a certain <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(R_k = 0\\)<\/span> and that means all Hobbits...<\/li><\/ul>","summary":"Gandalf from Lord of The Rings is the star of this brain teaser...","date_modified":"2025-07-23T16:49:02+02:00","tags":["invariants","mathematics","graphs"],"image":"\/user\/pages\/02.blog\/03.problems\/p003-quarrel-in-the-shire\/shire.jpg"},{"title":"Problem #002 - a bag full of numbers","date_published":"2017-11-06T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/bag-full-of-numbers","url":"https:\/\/mathspp.com\/blog\/problems\/bag-full-of-numbers","content_html":"<p>Two friends were bored and decided to play a game... a mathematical game with a paper bag!<\/p>\n<!-- v -->\n\n<figure class=\"image-caption\"><img title=\"Photo by B S K from FreeImages\" alt=\"a photo of a paper bag\" src=\"\/images\/5\/4\/c\/9\/b\/54c9b96cd56d5bd47703d53ab49a8a09eb5e1147-paperbag.jpg\"><figcaption class=\"\">Photo by B S K from FreeImages<\/figcaption><\/figure>\n<!-- ^ -->\n<h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>John and Mary have a bag full of integer numbers. In fact, the bag has <span class=\"mathjax mathjax--inline\">\\(10^{10^{10}}\\)<\/span> integers, each written on a plastic card, and the sum of all the <span class=\"mathjax mathjax--inline\">\\(10^{10^{10}}\\)<\/span> integers in the bag is <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span>. In turns, Mary and John are going to play with the bag by doing the following:<\/p>\n<ul>\n<li>Picking two cards from the bag with numbers <span class=\"mathjax mathjax--inline\">\\(a\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(b\\)<\/span> and removing them from the bag;<\/li>\n<li>Inserting a new card in the bag with the number <span class=\"mathjax mathjax--inline\">\\(a^3 + b^3\\)<\/span>.<\/li>\n<\/ul>\n<p>Is there any initial number configuration and\/or set of moves for which it is possible that, after <span class=\"mathjax mathjax--inline\">\\(10^{10^{10}} - 1\\)<\/span> moves, the only card in the bag has the number <span class=\"mathjax mathjax--inline\">\\(73\\)<\/span>?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought... and most important of all, try it for real! Let me know how it went in the comment section below ;)<\/p>\n<\/div>\n<div class=\"notices green\">\n<p><strong>Hint<\/strong>: the answer is \"no\". Can you show why?<\/p>\n<\/div>\n<div class=\"notices green\">\n<p><strong>Hint<\/strong>: look for an invariant of the game! That is, find a property of the game that does <em>not<\/em> change when Mary and John play it.<\/p>\n<\/div>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>(If you spot a mistake in my solution <em>please<\/em> let me know in the comments below.)<\/p>\n<p>No, there is no initial configuration nor set of moves that allows us to reach the goal. Note how <span class=\"mathjax mathjax--inline\">\\(x \\equiv x^3 \\mod 2\\)<\/span>. That is, <span class=\"mathjax mathjax--inline\">\\(x\\)<\/span> has the same parity as <span class=\"mathjax mathjax--inline\">\\(x^3\\)<\/span>. Let us assume that, at a given point, all the integers in the bag add up to <span class=\"mathjax mathjax--inline\">\\(S\\)<\/span>. We show that the parity of the sum of all integers in the bag doesn't change when we remove the cards <span class=\"mathjax mathjax--inline\">\\(a,b\\)<\/span> and then add the card <span class=\"mathjax mathjax--inline\">\\(a^3+b^3\\)<\/span>:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n    x \\equiv x^3 \\mod 2 \\implies S \\equiv S - a - b + a^3 + b^3 \\iff S + a + b \\equiv S + a^3 + b^3 \\mod 2\\]<\/p>\n<p>Thus we can't end up only with <span class=\"mathjax mathjax--inline\">\\(73\\)<\/span> in the bag, as everything in the bag should add up to an even number and <span class=\"mathjax mathjax--inline\">\\(73\\)<\/span> is odd.<\/p>\n<p>Bonus question: find a solution that would still work for <span class=\"mathjax mathjax--inline\">\\(2, 74, 308\\)<\/span> (and for an infinity of even numbers), even though those are even.<\/p>","summary":"In this blog post I will challenge you with an interesting problem...","date_modified":"2025-07-23T16:49:02+02:00","tags":["invariants","mathematics","number theory"],"image":"\/user\/pages\/02.blog\/03.problems\/p002-a-bag-full-of-numbers\/paperbag.jpg"},{"title":"Problem #001 - a dancing triangle","date_published":"2017-11-05T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/a-dancing-triangle","url":"https:\/\/mathspp.com\/blog\/problems\/a-dancing-triangle","content_html":"<!-- v -->\n<p>This post's format will be a bit different from the usual and the first of a series of posts of this type. In this post, I will state a problem and then present my solution.<\/p>\n\n<p><img alt=\"A scheme of what is explained below\" src=\"\/images\/8\/d\/5\/4\/0\/8d5406c3479f3f035a59bfcb85e7fc29b51f6e50-dancingtrianglescheme.webp\"><\/p>\n<!-- ^ -->\n<h2 id=\"problem-statement\">Problem statement<a href=\"#problem-statement\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>Let <span class=\"mathjax mathjax--inline\">\\([ABC]\\)<\/span> be any triangle. We now define a transformation of the triangle which moves one vertex and leaves the other two unchanged.\nTo apply a transformation, start by picking the vertex you want to move.\nAssume it was <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span>.\nConsider the line that goes through <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span> which is parallel to <span class=\"mathjax mathjax--inline\">\\([AB]\\)<\/span>, and pick any point <span class=\"mathjax mathjax--inline\">\\(C'\\)<\/span> in it.\nYour transformed triangle is <span class=\"mathjax mathjax--inline\">\\([ABC']\\)<\/span>.\nYou can repeat this process as many times as you want.<\/p>\n<p>Can the original triangle be transformed into a triangle where all sides were doubled?\nHow\/why?<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought...<\/p>\n<\/div>\n<p>If you need any clarification whatsoever, feel free to ask in the comment section below.<\/p>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>The answer to the question is <em>no<\/em>, one cannot apply the transformation a given number of times and get to a triangle with sides that are twice the original size. To see why, we will show that the area of the triangle remains unchanged when you apply the transformation. If we do that and if we realize that doubling up the lengths of the sides makes the area four times bigger, then we conclude that we cannot create the triangle we wished.<\/p>\n<p>Say we have a triangle <span class=\"mathjax mathjax--inline\">\\([ABC]\\)<\/span> and, without loss of generality, we are going to apply the transformation to <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span>. Furthermore, we can assume <span class=\"mathjax mathjax--inline\">\\([AB]\\)<\/span> is horizontal (this is not needed, just makes it even simpler to visualize the proof). We know that <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span> is going to be moved to a point <span class=\"mathjax mathjax--inline\">\\(C'\\)<\/span> in a line that is parallel to <span class=\"mathjax mathjax--inline\">\\([AB]\\)<\/span>. We know that the area of a triangle is <span class=\"mathjax mathjax--inline\">\\(\\frac{b \\times h}{2}\\)<\/span> where <span class=\"mathjax mathjax--inline\">\\(b\\)<\/span> is the length of the base and <span class=\"mathjax mathjax--inline\">\\(h\\)<\/span> is the height. If <span class=\"mathjax mathjax--inline\">\\([AB]\\)<\/span> is seen as the base (its length doesn't change when <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span> moves to <span class=\"mathjax mathjax--inline\">\\(C'\\)<\/span>) we see that the height <span class=\"mathjax mathjax--inline\">\\(h\\)<\/span> is the length of the line segment that goes from <span class=\"mathjax mathjax--inline\">\\(AB\\)<\/span> to <span class=\"mathjax mathjax--inline\">\\(C\\)<\/span> and is perpendicular to <span class=\"mathjax mathjax--inline\">\\(AB\\)<\/span>. But the line segment that goes from <span class=\"mathjax mathjax--inline\">\\(C'\\)<\/span> to <span class=\"mathjax mathjax--inline\">\\(AB\\)<\/span> and is perpendicular to it has exactly the same length, so the area of the triangle didn't change.<\/p>\n<!-- v -->\n<div class=\"notices blue\">\n<p>This problem does remind me of <a href=\"\/blog\/problems\/huge-tiny-triangle\">problem 36<\/a>,\nso you might want to take a look at that one too!<\/p>\n<\/div>\n<!-- ^ -->","date_modified":"2025-07-23T16:49:02+02:00","tags":["geometry","invariants","mathematics"],"image":"\/user\/pages\/02.blog\/03.problems\/p001-a-dancing-triangle\/dancing_triangle_scheme.webp"}]}
