WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Wall Street Quant · Puzzles & Problems · question 26 of 155

Write a function that takes a positive integer n as an input and performs the following steps. If n is even, divide it by 2, if n is odd, multiply it by 3 and add 1. Repeat the process (which has been called "Half Or Triple Plus One") indefinitely. The conjecture is that no matter what number you start with, you will always eventually reach 1. What is the smallest number that has not been proven to reach 1?

📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

The Collatz Conjecture, also known as the 3n+1 conjecture, is an unsolved problem in mathematics. Despite extensive computational evidence supporting the conjecture, no general proof has been found, and it remains an open question. Therefore, there is no known smallest number for which the conjecture hasn’t been proven to reach 1. Nonetheless, for all numbers tested up to this point (including numbers as large as 260), the conjecture holds.

Here is a simple function in Python to perform the "Half Or Triple Plus One" operations:

def collatz(n):
    if n <= 0:
        raise ValueError("Input must be a positive integer.")
    
    while n != 1:
        print(n)
        if n % 2 == 0:
            n = n // 2
        else:
            n = 3 * n + 1
    print(n)

This function takes a positive integer n as input and performs the Half Or Triple Plus One algorithm described in the Collatz conjecture. As a result, it prints the sequence of numbers visited during this process, including the final value of 1.

Keep in mind that without a rigorous proof that confirms the validity of the conjecture, it’s impossible to determine the smallest integer for which the conjecture fails.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Wall Street Quant interview — then scores it.
📞 Practice Wall Street Quant — free 15 min
📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

All 155 Wall Street Quant questions · All topics