Create several small programs that answer the following questions:
1. Question One
Read a nonnegative integer N (range 0 to 20) and print the powers of 2 from 1 to 2N. You do not need to validate that the integer is in range.
Enter an integer: 6
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2. Question Two
The combination of n things taken m at a time is a value often used in mathematics and business. With this program you will read input values, n and m, and output the number of different combinations of m things that can be formed from a group containing n members. This can be calculated by computing the factorial of n and dividing it by the factorial of m and then further dividing the result by the factorial of (n – m). The value, n-factorial is computed by multiplying n by n – 1, then multiplying the result by n – 2, and so forth, until the final result is multiplied by 1. n-factorial is sometimes written as n! Thus, 5-factorial (5!) is calculated in the following fashion: 5 x (5 – 1) x (5 – 2) x (5 – 3) x (5 – 4) = 5 x 4 x 3 x 2 x 1 = 120. 3! is calculated similarly as 3 x (3 – 1) x (3 – 2) = 3 x 2 x 1 = 6. And (5 – 3)!, otherwise known as 2!, is calculated as 2 x (2 – 1) = 2 x 1 = 2. Thus, the number of different combinations of 5 things taken 3 at a time is calculated as follows:
n! / [m! x (n – m)!]
= 5! / [3! x (5 – 3)!]
= 120 / [6 x2]
= 120 / 12
Your function must calculate this value for any values of n and m. You must output the result as an integer.
Enter n and m: 10 5
3. Question Three
You’re working for a growing e-commerce web site, which has become a popular target for thieves. The thieves gain access to customers’ accounts by guessing passwords, which are all too often trivial (such as “secret”, “password”, and “1234”). If your customers used better passwords, your company would have less trouble with fraudulent purchases.
You’ve been tasked with creating a password analyzer, which will inform a customer about the relative strength of their choice of password. A “strong” password is one that is hard to guess – either by sheer length, or by using a combination of letters, numbers and symbols. For your assignment, a strong password has all of the following characteristics:
- Is at least 8 characters long (example: “spookyfish”)
- Includes both upper and lower case letters (example: “sPookyFISH”)
- Includes letters and at least one number or symbol (examples: “sPookyFISH3” or “$PookyFI3H”)
A “good” password has two of these characteristics, an “acceptable” one has only one. A password that doesn’t meet any of these would be considered “weak”. Write a function that will analyze a given password and output the strength rating of the chosen password. You will find tutorial on Patterns helpful (http://lua-users.org/wiki/PatternsTutorial)
You should allow for a maximum password length of 30 characters. No spaces are allowed.
Your program will output to the screen the relative strength of the password typed, using the characteristics listed above.
Enter your password: lizard
This password is WEAK
Enter your password: aardvark
This password is ACCEPTABLE
Enter your password: Aardvark
This password is GOOD
Enter your password: Aardvark77
This password is STRONG