{"id":22955284,"url":"https://github.com/happycod3r/the-collatz-conjecture-3n1","last_synced_at":"2025-06-29T03:34:00.053Z","repository":{"id":187799330,"uuid":"677525694","full_name":"happycod3r/The-Collatz-Conjecture-3N1","owner":"happycod3r","description":"The Collatz Conjecture | 3N + 1","archived":false,"fork":false,"pushed_at":"2023-08-13T02:59:14.000Z","size":1081,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T16:16:53.476Z","etag":null,"topics":["3nplus1","3xplus1","collatz","collatz-algorithm","collatz-conjecture","collatz-graph","collatz-problem","collatz-sequences","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/happycod3r.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-11T20:00:34.000Z","updated_at":"2023-11-22T09:42:47.000Z","dependencies_parsed_at":"2023-08-12T07:07:20.610Z","dependency_job_id":null,"html_url":"https://github.com/happycod3r/The-Collatz-Conjecture-3N1","commit_stats":null,"previous_names":["happycod3r/the-collatz-conjecture-3n1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2FThe-Collatz-Conjecture-3N1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2FThe-Collatz-Conjecture-3N1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2FThe-Collatz-Conjecture-3N1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2FThe-Collatz-Conjecture-3N1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happycod3r","download_url":"https://codeload.github.com/happycod3r/The-Collatz-Conjecture-3N1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246735343,"owners_count":20825223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3nplus1","3xplus1","collatz","collatz-algorithm","collatz-conjecture","collatz-graph","collatz-problem","collatz-sequences","python3"],"created_at":"2024-12-14T16:28:54.393Z","updated_at":"2025-04-02T00:41:55.323Z","avatar_url":"https://github.com/happycod3r.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Collatz Conjecture (3N+1)\r\n\r\n![CC](res/collatz_by_K.A.Rousan1.webp)\r\n\r\n## [Table of Contents](#table-of-contents)\r\n\r\n- [Table of Contents](#table-of-contents)\r\n- [About](#about)\r\n  - [Origins and Name](#origins-name)\r\n  - [Rules](#rules)\r\n  - [Complex Behavior](#complex-behavior)\r\n  - [Efforts To Solve](#efforts-to-solve)\r\n\r\n## [About](#about)\r\n\r\n### [Origins and Name](#origins-name) \r\nThe **Collatz Conjecture**, also known as the **3n+1 conjecture** or the **hailstone sequence**, is a mathematical conjecture that concerns a sequence of numbers generated by a specific rule. The conjecture asks whether repeating two easy arithmetic operations on a sequence of numbers will eventually transform every positive integer into 1. It concerns sequences of integers in which each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. I described this in more detail in the [Rules](#rules) section. The conjecture is that these sequences always reach 1, no matter which positive integer is chosen to start the sequence.\r\n\r\nThe conjecture is named after the German mathematician [Lothar Collatz](https://en.wikipedia.org/wiki/Lothar_Collatz), who first proposed it in 1937. The conjecture is sometimes called the \"3n+1 conjecture\" because of the rule that involves multiplying by 3 and adding 1, and it's sometimes referred to as the \"hailstone sequence\" because the values in the sequence go up and down like hailstones in a storm.\r\n\r\n The Collatz Conjecture has fascinated mathematicians and researchers for decades due to its accessibility, potential connections to other mathematical concepts, and the challenge it presents in terms of proving its validity.\r\n\r\n It concerns sequences of integers in which each term is obtained from the previous term as follows:\r\n\r\n\r\n## [Rules](#rules)\r\nHere's a breakdown of the two rules for the Collatz Conjecture and how it works in general:\r\n\r\n- Start with any positive integer *`n`*\r\n- If *`n`* is even, divide it by **2** to get *`n/2`*\r\n- If *`n`* is odd, multiply it by 3 and add 1 to get *`3n + 1`*\r\n- Repeat the process with the result obtained in step 2 or step 3, and continue applying the same rules to each subsequent number in the sequence.\r\n\r\n\u003e As mentioned previously the conjecture states that, regardless of the initial value of\r\n*`n`*, this sequence will eventually reach the number 1. Once the sequence reaches 1, it will continue in a loop: 1 → 4 → 2 → 1\r\n \r\nBelow is an example of these rules in modern arithmetic notation to better visualize it\r\n![math notation](res/math.png)\r\n\r\n## [Complex Behavior](#complex-behavior)\r\n\r\nDespite its simple rules, the behavior of the Collatz sequence becomes quite complex as numbers get larger. Some numbers exhibit long, erratic sequences before eventually converging to 1. This complexity has made it difficult to prove the conjecture true for all positive integers. Smaller starting numbers have a shorter sequence of steps before reaching 1, so I'll demonstrate with small number first. \r\n\r\nFor example, let's make the first starting number 6, so `n = 6`:\r\n\r\n\r\n1) ***6*** is even, `6/2 = 3`\r\n2) ***3*** is odd, `3*3 + 1 = 10`\r\n3) ***10*** is even, `10/2 = 5`\r\n4) ***5*** is odd, `5*3 + 1 = 16`\r\n5) ***16*** is even, `16/2 = 8`\r\n6) ***8*** is even, `8/2 = 4`\r\n7) ***4*** is even, `4/2 = 2`\r\n8) ***2*** is even, `2/2 = 1`\r\n9) ***1*** is odd, `1*3 + 1 = 4`\r\n10) ***4*** is even, `4/2 = 2`\r\n11) ***2*** is even, `2/2 = 1`\r\n12) ***1*** is odd, `1*3 + 1 = 4`\r\n13) ***4*** is even, `4/2 = 2`\r\n14) ***2*** is even, `2/2 = 1`\r\n\r\nThis is what it looks like plotted on a graph:\r\n\r\n![ccseed6](res/ccseed6.png) \r\n\r\nAs you can see, once the sequence reaches **1** it begins looping 1 - 4 - 2 - 1 endlessly.\r\nMathematically you can easily understand and see exactly why this happens given the\r\ntwo \"*rules*\" or calculations being applied to even and odd numbers. Although while the \r\nconjecture is relatively easy to understand and has been tested extensively for many \r\nvalues of `n` using computers and otherwise, a formal proof of the conjecture's validity \r\nor counterexample (*a number that doesn't follow the sequence to 1*) has eluded \r\nmathematicians for decades. The Collatz Conjecture remains one of the most famous \r\nunsolved problems in number theory. Despite its simplicity, its behavior becomes \r\nincredibly complex as the numbers involved increase, making it a fascinating and really cool area of study in mathematics. \r\n\r\nTo demonstrate the increasing compexity I'll use a slightly larger number like **75** as the seed. \r\n\r\n![ccseed75](res/ccseed75.png)\r\n\r\nAs you can see no matter the number we end up in the same loop at the end again, 1 - 4 - 2 - 1 - 4 - 2 - 1 ... The low and high points are random yet you will always get that downward trend to the loop. The following image is a zoomed in section of the above graph where the looping starts:\r\n\r\n![ccseed75zoomed](res/loop_part.png)\r\n\r\nThe equation `1*3 + 1` will always be `4` which is even, so `4/2` then `2/2` will always end up back at 1 again, and so on.\r\n\r\nIf you use an even larger number to begin with such as **2,196** the results may be surprising. The sequence begins in the same usual downward trend before spiking way up beyond the original seed. Yet keeping true to the weirdness of mathematics, even after this drastic increase in the size of the number it always resolves itself back down to 1 begining the loop again. \r\n\r\n![ccseed2196](res/ccseed2196.png)\r\n\r\n## [Efforts to Solve](#efforts-to-solve)\r\n\r\nFrom its conception in 1937 to today, the Collatz Conjecture remains an unsolved problem in mathematics. No one has been able to prove or disprove the conjecture for all positive integers. Many mathematicians have attempted to tackle the problem, but the complexity and intricacy of the sequences have made it challenging to devise a proof or counterexample.\r\nThe Collatz Conjecture has been verified for an extremely large number of starting values using dedicated computers with simulations that have verified the conjecture for countless initial values, including those that are well beyond the reach of manual calculations. However, the sheer number of possibilities to check makes it impractical to definitively prove the conjecture true through exhaustive testing.\r\n\r\nSo, is there a number that can disprove the conjecture? and if so how do we find it? In my personal opinion I think it's reasonable at this point to say the results will be the same no matter the number, but as the famous mathematician [Paul Erdős](https://en.wikipedia.org/wiki/Paul_Erd%C5%91s) said \"*Mathematics is not yet ripe enough for such questions*\"\r\n\r\nOver the years people in various feilds such as number theorists, graph theorists, dynamic systems analysts, scientists, puzzle solvers, educators and mathematicians have developed various techniques and strategies in attempts to prove or disprove the conjecture. Some approaches involve finding specific properties of the sequence or exploring the behavior of particular subsets of integers and yet, still no one has been able to crack this puzzle. \r\n\r\nBecause the Collatz Conjeture serves as an example of a simple problem with surprisingly complex behavior, it's often used as a pedagogical tool to introduce concepts of iteration, recursion, and mathematical reasoning. \r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycod3r%2Fthe-collatz-conjecture-3n1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappycod3r%2Fthe-collatz-conjecture-3n1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycod3r%2Fthe-collatz-conjecture-3n1/lists"}