Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. CPEN 221 / Fall 2017
  2.  
  3. Programming Proficiency Test
  4. =========
  5.  
  6. January 17, 2018
  7.  
  8. ## General Instructions
  9.  
  10. + You have 75 minutes (1h 15m) to complete the assigned tasks.
  11. + Take your time to read the question.
  12. + Skeleton code can be obtained by cloning this repository. Add JUnit to your build path in Eclipse.
  13. + Best of luck!
  14.  
  15. ## Submission Instructions
  16.  
  17. + Submit your work to the Github classroom repository that was created for your.
  18. + **Do not alter the directory/folder structure. You should retain the structure as in this repository.**
  19. + Do not wait until the last minute to push your work to Github. It is a good idea to push your work at intermediate points as well. _I would recommend that you get your Git and Github workflow set up at the start._
  20.  
  21. ## Honour Code
  22.  
  23. By submitting your work to Github you agree to the following:
  24.  
  25. + You did not consult with any other person in completing the examination.
  26. + You did not aid any other person in the class in completing their examination.
  27. + If you consulted any external sources, such as resources available on the World Wide Web, in completing the examination then you have cited the source. (You do not need to cite class notes or Sun/Oracle Java documentation.)
  28. + You are not aware of any infractions of the honour code for this examination.
  29.  
  30. > Violations of this honour code will be treated as a case of academic misconduct and will dealt with under UBC policies governing such issues. A consequence of this may be to nullify this exam for everyone that submits work for grading!
  31.  
  32. # Question: Strange Number System Hops
  33.  
  34. > The skeleton source code for this question is in the package `fibbase`. You may import the provided code as a Gradle project in Eclipse.
  35.  
  36. [Zeckendorf's Theorem](https://en.wikipedia.org/wiki/Zeckendorf%27s_theorem) says that it is possible to represent any positive integer as the sum of one or more distinct Fibonacci numbers.
  37.  
  38. Let `F(n)` be the `n`-th Fibonacci number. We have:
  39.  
  40. * `F(1)` = 1
  41. * `F(2)` = 1
  42. * `F(3)` = 2
  43. * `F(4)` = 3
  44. * `F(5)` = 5
  45. * `F(6)` = 8
  46. * and so on.
  47.  
  48. Using only `0` and `1` as digits, we can represent the decimal number `10` in base-Fib as `10010` where the leftmost position corresponds to the Fibonacci number 8 and the rightmost position corresponds to the Fibonacci number 1. The decimal number `9` in base-Fib would be `10001`. **Note that in this context, we will always pick the representation that uses the larger Fibonacci numbers rather than the next two smaller ones.**
  49.  
  50. Given a decimal number `a`, we can represent it in base-Fib and then we can interpret the base-Fib number as a binary number. In the case of the decimal number `10`, the base-Fib representation is `10010` and if we were to interpret this as a binary number then we would get `18` as the corresponding decimal.
  51.  
  52. Let `x(a)` be the function that takes a positive integer and produces its base-Fib representation. Let `y(a)` be the function that takes a positive integer, computes the base-Fib representation `x(a)` and then interprets that representation as a binary number and produces the equivalent decimal number.
  53.  
  54. With our example, `x(10)` is `10010` and `y(10)` is `18`.
  55.  
  56. A few other examples:
  57.  
  58. * `x(1)` = 1; `y(1)` = 1
  59. * `x(2)` = 10; `y(2)` = 2
  60. * `x(3)` = 100; `y(3)` = 4
  61. * `x(4)` = 101; `y(4)` = 5
  62. * `x(5)` = 1000; `y(5)` = 8
  63. * `x(6)` = 1001; `y(6)` = 9
  64.  
  65. You have to implement the method `long ySum(long a, long b)` that returns `y(a)+y(a+1)+...+y(b-1)+y(b)` for integers `a` and `b` such that `b >= a`.
  66.  
  67. ### Test Cases
  68.  
  69. ```java
  70. @Test
  71. public void test1() {
  72. assertEquals(1, FibBase.ySum(1, 1));
  73. }
  74.  
  75. @Test
  76. public void test2() {
  77. assertEquals(3, FibBase.ySum(1, 2));
  78. }
  79.  
  80. @Test
  81. public void test3() {
  82. assertEquals(7, FibBase.ySum(1, 3));
  83. }
  84.  
  85. @Test
  86. public void test4() {
  87. assertEquals(12, FibBase.ySum(1, 4));
  88. }
  89.  
  90. @Test
  91. public void test5() {
  92. assertEquals(20, FibBase.ySum(1, 5));
  93. }
  94. ```
  95.  
  96. ## What Should You Implement / Guidelines
  97.  
  98. + You should implement all the methods that are indicated with `TODO`.
  99. + Passing the provided tests is the minimum requirement. Use the tests to identify cases that need to be handled. Passing the provided tests is *not sufficient* to infer that your implementation is complete and that you will get full credit. Additional tests will be used to evaluate your work. The provided tests are to guide you.
  100. + You can implement additional helper methods if you need to but you should keep these methods `private` to the appropriate classes.
  101. + You do not need to implement new classes **unless asked to**.
  102. + You can use additional standard Java libraries by importing them.
  103. + Do not throw new exceptions unless the specification for the method permits exceptions.
  104.  
  105. ## Answers to FAQs
  106.  
  107. #### Can I consult Java documentation and other Internet-based sources?
  108.  
  109. Yes, you can. The point of this test is not to demonstrate mastery over syntax but that you can solve a problem in a reasonable amount of time with reasonable resources.
  110.  
  111. *If you find useful information online outside the official Java documentation and the course material, you must cite the source. You should do so by adding comments in your source code.*
  112.  
  113. Naturally you are expected to adhere to all of the course and UBC policies on academic integrity.
  114.  
  115. #### Isn't one hour too short to produce a working implementation?
  116.  
  117. The questions are straightforward, and these are not very different from what one might sometimes encounter on a job interview (for example). The difference is that you get less time during an interview (10-15 minutes) with no access to additional resources. So the time allotted is reasonable in that regard and I am expecting that everyone will be able to clear this bar. The goal is that it is possible to say, at a minimal level, what everyone who completes this course can achieve.
  118.  
  119. #### Why am I not guaranteed full credit if my implementation passes all the provided tests?
  120.  
  121. It is easy to develop an implementation that passes the provided tests and not much else. A good-faith implementation that passes all the provided tests is very likely to pass other tests too.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement