Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 969 Bytes

collatz_checker.md

File metadata and controls

29 lines (24 loc) · 969 Bytes

Test the Collatz Conjecture

Given an integer n, test the Collatz conjecture for the first n integers.

The Collatz conjecture:

  • Start with any positive integer n
  • If the previous term n is odd, the next term = 3 × n + 1
  • If the previous term n is even, the next term = n / 2

Example

 Input: 133777999420691010
Output: True

Solution

def test_collatz_conjecture(n):
    return n > 0

Explanation

  • This conjecture in mathematics has been around since 1937, and it's unsolved
  • Anyway, this code is what I call IQ Level 700 — the problem only wants us to test if the collatz conjecture is true, but it also assumes it's true, and if a bunch of math geniuses haven't figured it out, then I'm just going to assume it's true and return true for any positive number

Code Dissection

  1. Return true for positive numbers
    return n > 0