Advertisement
LucasSousa

string challenge

Feb 12th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. This challenge will work with Strings composed by groups of pairs of numbers. All pairs are separated by slashes and all numbers in each pair are separated by a comma. This is a example of input: -2,3/5,-4/6,0/-3,0/-5,-5/0,-3/-4,0/0,-3/. The main aim is otimize the sequence by removing the excess of 0,0 pairs. When a 0,0 is removed from the middle of the sequence the surrounding pairs should be merged into a new single one. Look to this format: a,b/0,0/c,d.
  2. To merge pairs after remove 0,0 the new pair should be: a+c,b+d.
  3. Obs.: The input may contains more than one 0,0 pair, in addition, it can contains severals 0,0 in a row as well.
  4. Obs.: 0,0 can appears at begin or end of the sequence. In these cases it just need to be removed (all leading slashes are turned to only 1 -> "/0,0/1,0/" -> "/1,0/").
  5.  
  6. Example:
  7. Input: "3,2/0,0/-2,1/";
  8. Removing 0,0: "3,2//-2,1/";
  9. Merging previous and next groups: (3+(-2),2+1): "1,3/"
  10.  
  11. Another example:
  12. Input: "6,-1/3,1/3,3/0,0/-3,-3/-3,-1/6,1"
  13. Removing 0,0: "6,-1/3,1/3,3//-3,-3/-3,-1/6,1"
  14. Merging previous and next groups (3+(-3),3+(-3)): "6,-1/3,1/0,0/-3,-1/6,1"*
  15.  
  16. *Removing 0,0: "6,-1/3,1//-3,-1/6,1"
  17. Merging previous and next groups (3+(-3), 1+(-1)): "6,-1/0,0/6,1"*
  18.  
  19. *Removing 0,0: "6,-1//6,1"
  20. Merging previous and next groups (6+(6), -1+(1)): "12,0"*
  21.  
  22. *FORMATTING RULES (Optional challenge)
  23. The max value for numbers should be 6. This means that, if you get a sum case
  24. wich result is > 6, you need replace it to 12 - (result).
  25. Example:
  26. 6 + 6 = 12 (result 12, wrong);
  27. 6 + 6 = 12 - (12) = 0 (this means a 12 value takes same effect a 0 value).
  28. Other example:
  29. 5 + 4 = 9 (result 9, wrong)
  30. 5 + 4 = 12 - 9 = 3 (should be -3, look observation bellow)*.
  31. *Obs.: If the result is > 0 (positive) the final value should be negative and if the result is negative, the final result should be 12 + result, intead 12 - result. Example:
  32. -5 + -4 = -9 (wrong and operation with 12 should be +, instead - )
  33. -5 + -4 = 12 + (-9) = 3.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement