
    
        
        
        
                
    
        
        
                
    
        
        
            
{"version":"https:\/\/jsonfeed.org\/version\/1","title":"mathspp.com feed","home_page_url":"https:\/\/mathspp.com\/blog\/tags\/pigeonhole-principle","feed_url":"https:\/\/mathspp.com\/blog\/tags\/pigeonhole-principle.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 #054 \u2013 imperfect compression","date_published":"2022-01-23T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/imperfect-compression","url":"https:\/\/mathspp.com\/blog\/problems\/imperfect-compression","content_html":"<p>Can you show that perfect compression is impossible?<\/p>\n\n<figure class=\"image-caption\"><img title=\"Photo by Rui Matayoshi on Unsplash.\" alt=\"\" src=\"\/images\/e\/c\/d\/8\/d\/ecd8df7fc67e7eb6dc340f7f49c7cf0403cbc855-thumbnail.png\"><figcaption class=\"\">Photo by Rui Matayoshi 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>Compression is great: it is what lets you take that giant folder you have and reduce its size to save some memory on your laptop.\nOf course, you only do these compressions happily because you know you don't lose information when you compress things.\nThe data is just... compressed!<\/p>\n<p>For compression to be useful, it has to be bidirectional: you must be able to recover the original data from the compressed version.\nThis is only possible if two different pieces of data never get compressed into the same thing.\n(In mathematical terms, we say that the compression must be injective.)<\/p>\n<p>Now, on top of that, we are interested in compression that actually works, right?\nThat is, in compression that reduces the size of things.\nRight?<\/p>\n<p>Right!\nNow, the challenge is for you to show that no compression mechanism is perfect.\nIn other words, show that if a compression mechanism is bidirectional and it manages\nto take some pieces of data and transform them into something smaller,\nthen, there are pieces of data that will become <strong>larger<\/strong> by the action of the compression mechanism.<\/p>\n<p>If it makes it easier for you,\nwe can suppose that the data we are talking about are just sequences of letters.\nSo, we are talking about compression mechanisms that take sequences of letters and try to build smaller\nsequences of letters, the compression.\nFor example, maybe the sequence <code>aaaaaa<\/code> gets compressed into <code>Aaab<\/code>,\nbut maybe the mechanism fails on <code>AAAAAA<\/code> because it &ldquo;compresses&rdquo; it into <code>arghfewtoen<\/code>.<\/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=\"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#054%20%E2%80%93%20imperfect%20compression\" 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>Let's assume that there <em>is<\/em> a perfect compression algorithm.\nFor the empty sequence, what does this algorithm do?\nIt has to compress the empty sequence into the empty sequence,\nbecause there is no shorter sequence to compress the sequence into.<\/p>\n<p>Now, let's think about sequences of length 1.\nNone of those can be compressed into the only sequence of length 0,\nbecause there is already a sequence compressed into that (itself).\nThus, all sequences of length 1 must map to other sequences of length 1.\nOf course they don't map to sequences of length 2 or greater,\notherwise the <em>compression<\/em> would actually make the sequences larger.<\/p>\n<p>Therefore, the sequences of length 1 all map to each other,\nand no two sequences can map to the same one,\nso the compression algorithm really only works as a shuffling of the sequences...<\/p>\n<p>Now, we can just repeat this train of thought indefinitely:\nfor the sequences of length 2,\nnone of them can map to sequences of length 0 or 1,\nbecause those are all...<\/p>","summary":"Can you show the perfection compression algorithm doesn&#039;t exist?","date_modified":"2025-07-23T16:49:02+02:00","tags":["combinatorics","induction","mathematics","pigeonhole principle"],"image":"\/user\/pages\/02.blog\/03.problems\/p054-imperfect-compression\/thumbnail.png"},{"title":"Problem #032 - restaurant roundtable","date_published":"2021-03-21T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/restaurant-roundtable","url":"https:\/\/mathspp.com\/blog\/problems\/restaurant-roundtable","content_html":"<p>A waiter at a restaurant gets a group's order completely wrong.\nCan you turn the table to get two or more orders right?<\/p>\n\n<figure class=\"image-caption\"><img title=\"A scheme of a possible configuration of the wrong orders.\" alt=\"\" src=\"\/images\/2\/d\/f\/e\/d\/2dfed5736be78e67e0d709784e16e76a23d86b89-thumbnail.webp\"><figcaption class=\"\">A scheme of a possible configuration of the wrong orders.<\/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>An arbitrary number of people are people sitting down, around a round table,\nwaiting for their orders.\nWhen the waiter brings their orders, they mix everything up and no single\nperson is served what they ordered.<\/p>\n<p>Can you <em>always<\/em> turn the table so that at least two orders are correctly aligned?\nYou can start by trying with the example in the figure above, assuming\nyou are not colour-blind (sorry if you are :\/).<\/p>\n<div class=\"notices blue\">\n<p>Give it some thought...<\/p>\n<\/div>\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\nthat submitted correct solutions:<\/p>\n<ul>\n<li>Attila K., Hungary;<\/li>\n<li>Filippo M., Italy;<\/li>\n<li>Lu\u00eds S., Portugal;<\/li>\n<li>Andr\u00e9 S., Portugal.<\/li>\n<\/ul>\n<p>(The list is in no particular order.)<\/p>\n<h2 id=\"solution\">Solution<a href=\"#solution\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h2>\n<p>I received some really interesting solutions and I'll be sharing a paraphrasing\nof the one I think is the most elegant.<\/p>\n<p>Yes, it is always possible to turn the table some number of places\nin order to fix the dishes of at least two people at the same time.\nLet's see how to do it.<\/p>\n<p>Each person sitting at the table will look to its left and count the number of\nplates until its own plate.<\/p>\n<p>For example, if we consider this placement:<\/p>\n<p><img alt=\"\" src=\"\/images\/2\/d\/f\/e\/d\/2dfed5736be78e67e0d709784e16e76a23d86b89-thumbnail.webp\"><\/p>\n<p>Then the corresponding numbers would be the following:<\/p>\n<p><img alt=\"\" src=\"\/user\/pages\/02.blog\/03.problems\/p032-restaurant-roundtable\/_roundtable_counts.webp\"><\/p>\n<p>If there are <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> people sitting at the table, that number is an integer\nbetween <span class=\"mathjax mathjax--inline\">\\(1\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(n - 1\\)<\/span>, inclusive.\nIt is not <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span> because that would mean that person got the correct plate\nand it is not <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> because that is a whole turn around the table, also\nmeaning that person would've gotten its own plate.<\/p>\n<p>We have seen that each person has a number inside the set<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n\\{ 1, 2, \\cdots, n-1 \\} ~~~,\\]<\/p>\n<p>and there are <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> people, but that set only contains <span class=\"mathjax mathjax--inline\">\\(n - 1\\)<\/span> distinct numbers.\nTherefore, the pigeonhole principle tells you that at least two persons\nhave the same number <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span>, which means you can turn the table <span class=\"mathjax mathjax--inline\">\\(d\\)<\/span> times\nin the counter-clockwise direction to deliver the correct plate to them.<\/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","mathematics","pigeonhole principle"],"image":"\/user\/pages\/02.blog\/03.problems\/p032-restaurant-roundtable\/thumbnail.webp"},{"title":"Problem #007 - binary multiples","date_published":"2018-02-26T00:00:00+01:00","id":"https:\/\/mathspp.com\/blog\/problems\/binary-multiples","url":"https:\/\/mathspp.com\/blog\/problems\/binary-multiples","content_html":"<p>Is it true that every integer you can think of has a multiple written out only with <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span>s and <span class=\"mathjax mathjax--inline\">\\(1\\)<\/span>s?<\/p>\n\n<p><img alt=\"A screenshot of a black screen with some white 0s and 1s\" src=\"\/user\/pages\/02.blog\/03.problems\/p007-binary-multiples\/binary_img.jpg\"><\/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>Let <span class=\"mathjax mathjax--inline\">\\(k \\in \\mathbb{Z}\\)<\/span> be an integer. Is there an integer <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> such that <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> is a multiple of <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> only has <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span>s and <span class=\"mathjax mathjax--inline\">\\(1\\)<\/span>s in its decimal expansion?<\/p>\n<p>As an example, if <span class=\"mathjax mathjax--inline\">\\(k = 2\\)<\/span> we could have <span class=\"mathjax mathjax--inline\">\\(n = 10\\)<\/span>.<\/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 is <em>yes<\/em>, any integer <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> has a \"binary multiple\" <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span>. To show this is true, we will build <span class=\"mathjax mathjax--inline\">\\(n\\)<\/span> starting from <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>.<\/p>\n<p>Assume <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> is positive, and consider the following <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> integers:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n    \\big\\{ 1, 11, 111, \\cdots, \\underbrace{1\\cdots 1}_{k\\ 1\\text{s}} \\big\\}\\]<\/p>\n<p>(which can be formally written out as taking <span class=\"mathjax mathjax--inline\">\\(\\{c_i\\}_{i = 1}^k\\)<\/span> with <span class=\"mathjax mathjax--inline\">\\(c_1 = 1\\)<\/span> and <span class=\"mathjax mathjax--inline\">\\(c_{i+1} = 10*c_i + 1\\)<\/span>).<\/p>\n<p>Then only one of two things can happen. Either one of <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> is a multiple of <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> (in which case all is good) or not. But if no <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> is a multiple of <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>, then we can consider the remainders of the <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> modulo <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n    \\{ c_1\\ \\text{mod}\\ k, c_2\\ \\text{mod}\\ k, \\cdots, c_k\\ \\text{mod}\\ k \\} \\subseteq \\{ 1, \\cdots, k - 1 \\}\\]<\/p>\n<p>We say that the remainders of the <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> are contained in the set to the right because none of the remainders is <span class=\"mathjax mathjax--inline\">\\(0\\)<\/span>, otherwise one of the <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> would be a multiple of <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>.<\/p>\n<p>Notice the left-hand set is built by taking the remainders of the <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> different <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span> but the right-hand set only has <span class=\"mathjax mathjax--inline\">\\(k - 1\\)<\/span> elements. The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pigeonhole_principle\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" class=\"external-link no-image\">pigeonhole principle<\/a> then says that there are at least two different <span class=\"mathjax mathjax--inline\">\\(c_i\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(c_j\\)<\/span> being mapped to the same element in the right-hand set, i.e. <span class=\"mathjax mathjax--inline\">\\(c_i \\equiv c_j \\ \\text{mod}\\ k\\)<\/span>. Assume we have <span class=\"mathjax mathjax--inline\">\\(j &gt; i\\)<\/span>, meaning <span class=\"mathjax mathjax--inline\">\\(c_j &gt; c_i\\)<\/span> and, in particular:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n    \\begin{cases}\n        c_j - c_i \\equiv 0\\ \\text{mod}\\ k \\\\\n        c_j - c_i = \\underbrace{1\\cdots 1}_{j-i\\ 1\\text{s}} \\underbrace{0\\cdots 0}_{i\\ 0\\text{s}}\n    \\end{cases}\\]<\/p>\n<p>Thus <span class=\"mathjax mathjax--inline\">\\(n = c_j - c_i\\)<\/span> is a \"binary multiple\" of <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span>.<\/p>\n<p>If <span class=\"mathjax mathjax--inline\">\\(k\\)<\/span> is negative, we repeat the above for <span class=\"mathjax mathjax--inline\">\\(-k\\)<\/span>. If <span class=\"mathjax mathjax--inline\">\\(k = 0\\)<\/span>, then <span class=\"mathjax mathjax--inline\">\\(n = 0\\)<\/span>.<\/p>\n<h3 id=\"example\">Example<a href=\"#example\" class=\"toc-anchor after\" data-anchor-icon=\"#\" aria-label=\"Anchor\"><\/a><\/h3>\n<p>If <span class=\"mathjax mathjax--inline\">\\(k = 4\\)<\/span> we consider <span class=\"mathjax mathjax--inline\">\\(c_1 = 1\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(c_2 = 11\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(c_3 = 111\\)<\/span>, <span class=\"mathjax mathjax--inline\">\\(c_4 = 1111\\)<\/span> and realize none of these numbers is a multiple of <span class=\"mathjax mathjax--inline\">\\(4\\)<\/span>.<\/p>\n<p>Now we take the remainders:<\/p>\n<p class=\"mathjax mathjax--block\">\\[\n    \\begin{cases}\n        1 \\equiv 1\\ \\text{mod}\\ 4 \\\\\n        11 \\equiv 3\\ \\text{mod}\\ 4 \\\\\n        111 \\equiv 3\\ \\text{mod}\\ 4 \\\\\n        1111 \\equiv 3\\ \\text{mod}\\ 4\n    \\end{cases}\\]<\/p>\n<p>and see that, for example, <span class=\"mathjax mathjax--inline\">\\(c_3 \\equiv c_2\\ \\text{mod}\\ 4\\)<\/span>, implying that <span class=\"mathjax mathjax--inline\">\\(c_3 - c_2 = 100 \\equiv 0\\ \\text{mod}\\ 4\\)<\/span>.<\/p>","date_modified":"2025-07-23T16:49:02+02:00","tags":["mathematics","modular arithmetic","pigeonhole principle"],"image":"\/user\/pages\/02.blog\/03.problems\/p007-binary-multiples\/binary_img.jpg"}]}
