Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. # Problem 1 - JSON Diff Utility
  2.  
  3. ### Write a utility to compare two JSON documents and generate the differences.
  4.  
  5. **Example -**
  6.  
  7. For two json documents - `clark1.json` and `clark2.json`.
  8.  
  9. `clark1.json`
  10.  
  11. ```
  12. {
  13. "name": "Clark Kent",
  14. "age":"33",
  15. "work":"Daily Planet",
  16. "friends": ["Lana Lang"]
  17. }
  18. ```
  19.  
  20. and
  21.  
  22. `clark2.json`
  23.  
  24. ```
  25. {
  26. "name": "Clark Kent",
  27. "age":"34",
  28. "work":"Daily Planet",
  29. "associations": ["Justice League"]
  30. }
  31. ```
  32.  
  33. **Diffs (result)**
  34.  
  35. 1. Property `age` is changed from 33 to 34
  36. 2. New property `associations` is added with value - `["Justice League"]`
  37. 3. Property `friends` is deleted
  38.  
  39. >**Note:** You can define your own format/type to represent a diff.
  40.  
  41. ### In addition, you should be able to create a new JSON document from a base JSON document and a list of differences.
  42.  
  43. **Example -**
  44.  
  45. For a json document - `clark1.json`
  46.  
  47. ```
  48. {
  49. "name": "Clark Kent",
  50. "age":"33",
  51. "work":"Daily Planet",
  52. "friends": ["Lana Lang"]
  53. }
  54. ```
  55.  
  56. And a list of diff -
  57. 1. Property `age` is changed from 33 to 34
  58. 2. New property `associations` is added with value - `["Justice League"]`
  59. 3. Property `friends` is deleted
  60.  
  61. You should be able to create a new JSON -
  62.  
  63. ```
  64. {
  65. "name": "Clark Kent",
  66. "age":"34",
  67. "work":"Daily Planet",
  68. "associations": ["Justice League"]
  69. }
  70. ```
  71.  
  72. **APIs**
  73.  
  74. `List<Diff> diff(String jsonA, String jsonB)`
  75.  
  76. `String patch(String jsonA, List<Diff>)`
  77.  
  78. ---
  79.  
  80. # Problem 2 - Expression evaluator
  81.  
  82. You will be provided with two strings - `expression` and `values`. `expression` represents a mathematical expression with some variables. `values` will provide the values of the variables in the expression in the following format -
  83.  
  84. `key=value;...;key=value`
  85.  
  86. **Example 1-**
  87.  
  88. `expression` - `"x^2 + 2x + 1"`
  89.  
  90. `values` - `"x=5"`
  91.  
  92. *Result* = 36
  93.  
  94. **Example 2 (with a trigonometric function)-**
  95.  
  96. `expression` - `"x^2 + 2x + 1 + sin(y)"`
  97.  
  98. `values` - `"x=5;y=π/2"`
  99.  
  100. **Result** = 37
  101.  
  102. **Example 3 (with a decimal number)-**
  103.  
  104. `expression` - `"x^2 + 2.5y + 1 + sin(z)"`
  105.  
  106. `values` - `"x=5;y=4;z=π/2"`
  107.  
  108. **Result** = 37
  109.  
  110.  
  111. ### Symbols and meanings
  112.  
  113. 1. `sin` - sine trigonometric function
  114. 2. `cos` - cosine trigonometric function
  115. 3. `tan` - tangent trigonometric function
  116. 4. `log` - logarithm function
  117. 5. `x^y` - `x` raised to power `y`
  118. 6. `xy` - product of `x` and `y`
  119. 7. `x/y` - `x` divided by `y`
  120. 8. `x+y` - sum of `x` and `y`
  121. 9. `x-y` - difference of `x` and `y`
  122. 10. `()` - parenthesis
  123. 11. `π` - Mathematical constant PI
  124.  
  125. **APIs**
  126.  
  127. `double evaluate(String expression, String values)`
  128.  
  129. ---
  130. ### Completion Date - `October 31, 2019`
  131. ### Programming Language - `Java`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement