1) Imagine you need to open a standard combination dial lock but don't know the combination and don't have a pair of bolt cutters. Write a program that prints all possible combinations so you can print them on a piece of paper and check off each one as you try it. Assume the numbers on the dial range from zero to thirty-six and three numbers in sequence are needed to open the lock.
Suppose the lock isn't a very good one and any number that's no more than one away from the correct number will also work. In other words if the combination is 17-6-32 then 18-5-31 will also open the lock. Write a program that prints the minimum number of combinations you need to try to guarantee opening the lock.
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 36; i +=2) {
for (int j = 0; j < 36; j+=2) {
for (int k = 0; k <36; k+=2) {
System.out.println(i + "-" + j + "-" + k);
}
}
}
}
}
Comments
Leave a comment