The Collatz Conjecture dates back to 1937 and is believed to be true, yet it still remains unproven. Start with a positive integer n and repeat the following: if your number is even, then replace it with n/2; if was is odd, replace it with value 3n+1. The conjecture is that for any possible n this process will eventually produce the value 1.
Write a program that simulates this process for a value of n that a user inputs, printing the sequence of values produced, one per line. An example of the execution might appear as follows:
Enter a number: 12
12
6
3
10
5
16
8
4
2
1
As an aside, Wikipedia reports that computers have been used to show that all values of \(n \leq 87 * 2^{60}\) are consistent with the conjecture. Still, there is no proof that it is true for all n.
Spoiler: (my code)
Write a program that estimates the square root of a positive number by using a while loop to test integers and determine the largest integer whose square is smaller than the number in question. For example, if esitmating the square root of 10, the program should determine that \(3 \leq \sqrt{10} \leq 4\) because \(3^2 = 9 \leq 10 \leq 4^2 = 16\). Another sample might look as follows for the program:
Enter a number: 46.1 The square root of 46.1 is between 6 and 7.
Spoiler: (my code)
Write a program that asks a user to enter 3 words on a single line. Repeat the request until the user properly enters 3 words. A sample session might be the following:
Enter 3 words: Three words Try again. Enter 3 words: why? Try again. Enter 3 words: I don't want to Try again. Enter 3 words: I give up Thank you.
Spoiler: (my code)
A common requirement for a password is that it be at least eight characters, that it not contain spaces, and that it use at least three of the following four class of characters: uppercase letters, lowercase letters, numbers, symbols. For the sake of this task, we assuming anything that is not a letter or number or space is a symbol (though in reality, some characters such as spaces are not actually allowed).
Write a program that asks a user for a password, reprompting until they meet this criteria. A sample session is shown below (though most password programs would not display the password visibly).
New password: Maroon 5 Invalid password. Try again. New password: P!nk Invalid password. Try again. New password: Menswe@r SuccessSpoiler: (my code)