Advertisement
Guest User

foobar

a guest
Nov 11th, 2014
1,894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. foobar:~/a_pirate_walks_into_a_bar ----$ help
  2. Use the following shell commands:
  3. cd change directory [dir_name]
  4. cat print file [file_name]
  5. deleteme delete all of your data associated with foobar
  6. edit open file in editor [file_name]
  7. feedback provide feedback on foobar
  8. less print a file a page at a time [file_name]
  9. ls list directory contents [dir_name]
  10. request request new challenge (of type 'tag') [tag]
  11. status print progress
  12. submit submit final solution file for assessment [file_name]
  13. tags print tag list
  14. verify runs tests on solution file [file_name]
  15. foobar:~/a_pirate_walks_into_a_bar -------$ status
  16. You've not yet solved a challenge.
  17. foobar:~/a_pirate_walks_into_a_bar -------$ tags
  18. Requesting tags...
  19. algo algorithms
  20. data_struct data structures
  21. low_level low-level representation (binary representations, endianness)
  22. math math
  23. crypto security and cryptography
  24.  
  25. foobar:~/a_pirate_walks_into_a_bar ------$ cat readme.txt
  26. A pirate walks into a bar...
  27. ============================
  28.  
  29. You must hurry to find Professor Boolean's secret lab. You fear it may be too late.
  30.  
  31. Rumor has it that one of the pirates in this tavern knows where it is. There's a whole row of them seated at the bar. You start by talking to the pirate seated on the left-most barstool. However, the pirate redirects you to another pirate. Fine... you go to talk to that one. To your great annoyance, that pirate redirects you to yet another pirate! And on and on it goes. Is there no end to this madness? You notice each pirate has a number tattooed on his arm and decide to ID each man by his number. Each pirate redirects to a different pirate, other than himself. Because of this, it is guaranteed that you will start going in loops talking to them.
  32.  
  33. Write a function answer(numbers) which returns the number of pirates which form a loop, given that you start by talking to the left-most pirate, 0. numbers will be an array of non-negative integers such that number[m] is the number of the pirate to whom pirate m redirects. No pirate redirects to himself. The left-most pirate is number 0, the next is number 1, and so on. Each element in the numbers list will be in the range [0, n-1] where n is the length of the numbers list.
  34.  
  35. For example, suppose the numbers list were [1, 3, 0, 1]. Then pirate 0 redirects to pirate 1, who redirects to pirate 3, who redirects back to pirate 1. There is a loop of two pirates: 1, 3. Thus the answer would be 2. Note that even though you started with pirate 0, he is not part of the loop.
  36.  
  37. The number of pirates will be at least 2 and no more than 5000.
  38.  
  39. Languages
  40. =========
  41.  
  42. To provide a Python solution, edit solution.py
  43. To provide a Java solution, edit solution.java
  44.  
  45. Test cases
  46. ==========
  47.  
  48. Inputs:
  49. (int list) numbers = [1, 0]
  50. Output:
  51. (int) 2
  52.  
  53. Inputs:
  54. (int list) numbers = [1, 2, 1]
  55. Output:
  56. (int) 2
  57.  
  58. Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.
  59.  
  60.  
  61. ### `request math`:
  62.  
  63. foobar:~/peculiar_balance -------$ cat readme.txt
  64. Peculiar balance
  65. ================
  66.  
  67. Can we save them? Beta Rabbit is trying to break into a lab that contains the only known zombie cure - but there's an obstacle. The door will only open if a challenge is solved correctly. The future of the zombified rabbit population is at stake, so Beta reads the challenge: There is a scale with an object on the left-hand side, whose mass is given in some number of units. Predictably, the task is to balance the two sides. But there is a catch: You only have this peculiar weight set, having masses 1, 3, 9, 27, ... units. That is, one for each power of 3. Being a brilliant mathematician, Beta Rabbit quickly discovers that any number of units of mass can be balanced exactly using this set.
  68.  
  69. To help Beta get into the room, write a method called answer(x), which outputs a list of strings representing where the weights should be placed, in order for the two sides to be balanced, assuming that weight on the left has mass x units.
  70.  
  71. The first element of the output list should correspond to the 1-unit weight, the second element to the 3-unit weight, and so on. Each string is one of:
  72.  
  73. "L" : put weight on left-hand side
  74. "R" : put weight on right-hand side
  75. "-" : do not use weight
  76.  
  77. To ensure that the output is the smallest possible, the last element of the list must not be "-".
  78.  
  79. x will always be a positive integer, no larger than 1000000000.
  80.  
  81. Languages
  82. =========
  83.  
  84. To provide a Python solution, edit solution.py
  85. To provide a Java solution, edit solution.java
  86.  
  87. Test cases
  88. ==========
  89.  
  90. Inputs:
  91. (int) x = 2
  92. Output:
  93. (string list) ["L", "R"]
  94.  
  95. Inputs:
  96. (int) x = 8
  97. Output:
  98. (string list) ["L", "-", "R"]
  99.  
  100. Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement