Advertisement
Guest User

InsecureCombinationLockBreaker

a guest
Dec 4th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. //UIUC CS125 FALL 2014 MP. File: InsecureCombinationLockBreaker.java, CS125 Project: Challenge7-RecursiveKnight, Version: 2014-11-24T10:49:46-0600.714066947
  2. public class InsecureCombinationLockBreaker {
  3.  
  4.     public static int breakLock(InsecureCombinationLock lock) {
  5.         // Write your code here to break the combination lock
  6.         // Read the combination lock source code to determine
  7.         // the weakness in the lock
  8.        
  9.         // You do not need to use recursion.
  10.  
  11.         // - An inside programmer has written some extra
  12.         // code that gives you a tiny hint about how close you
  13.         // are to opening the lock.
  14.         // Using this single bit of information, your job
  15.         // is to find the integer value that opens the lock
  16.        
  17.         // This method is only for honors students and the curious to complete
  18.         // Honor students: Be prepared to demonstrate how you completed
  19.         // this problem!
  20.  
  21.         // **** This method is not graded as part of the MP ****
  22.        
  23.         // (but for your own local testing just remove
  24.         // the 'xxx's in the test  method in InsecureTest.java)
  25.        
  26.         // Beginner: This problem is not for beginners
  27.        
  28.         // Intermediate: It took me 90 minutes to create a robust solution
  29.         // (including 15 minutes debugging it with several million tests).
  30.        
  31.         // Advanced: 'Don't be wasteful' -
  32.         // Assume there is a 1s time penalty for every unlocking attempt,
  33.         // make sure your code uses the fewest number of unlocking attempts
  34.         // ie. It will open the lock as quickly as possible.
  35.         // (My solution was little wasteful but was simpler to implement).
  36.        
  37.         return 42;
  38.     }
  39.  
  40.     public static void main(String[] args) {
  41.             InsecureCombinationLock lock = new InsecureCombinationLock();
  42.             int code = breakLock(lock);
  43.            
  44.             System.out.println("Unlock code:"+code);
  45.             System.out.println(lock.isUnlocked() ? "Unlocked :-)" : "Still Locked :-(");
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement