Advertisement
Guest User

Untitled

a guest
May 20th, 2015
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Fix my phone, minion!
  2. =====================
  3.  
  4. "She escaped? This can't be happening! Get me the security team!"
  5.  
  6. Professor Boolean, a notorious mad scientist, just found out his precious rabbit specimen has escaped! He rushes to call his security minions on the lab phone. However, the rabbit escapee hacked the phone to speed her escape! She left a sign with the following clues: Each digit that is dialed has to be a number that can be reached by a knight chess piece from the last digit dialed - that is, you must move precisely 2 spaces in one direction, and then 1 space in a perpendicular direction to dial the next correct number. You can dial any number you want to start with, but subsequent numbers must obey the knight's move rule.
  7.  
  8. The lab phone has the numbers arranged in the following way: 1, 2, 3 in the first row; 4, 5, 6 in the second row; 7, 8, 9 in the third row; and blank, 0, blank in the fourth row.
  9.  
  10. 123
  11. 456
  12. 789
  13. 0
  14.  
  15. For example, if you just dialed a 1, the next number you dial has to be either a 6 or an 8. If you just dialed a 6, the next number must be a 1 or 7.
  16.  
  17. Professor Boolean wants you to find out how many different phone numbers he can dial under these conditions. Write a function called answer(x, y, z) that computes the number of phone numbers one can dial that start with the digit x, end in the digit y, and consist of z digits in total. Output this number as a string representing the number in base-10.
  18.  
  19. x and y will be digits from 0 to 9. z will be between 1 and 100, inclusive.
  20.  
  21. Languages
  22. =========
  23.  
  24. To provide a Python solution, edit solution.py
  25. To provide a Java solution, edit solution.java
  26.  
  27. Test cases
  28. ==========
  29.  
  30. Inputs:
  31. (int) x = 6
  32. (int) y = 2
  33. (int) z = 5
  34. Output:
  35. (string) "6"
  36.  
  37. Inputs:
  38. (int) x = 1
  39. (int) y = 5
  40. (int) z = 100
  41. Output:
  42. (string) "0"
  43.  
  44. Inputs:
  45. (int) x = 3
  46. (int) y = 7
  47. (int) z = 1
  48. Output:
  49. (string) "0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement