eniallator

CodeGolf: Oscillating Range Function

Jan 30th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. **New Challenge:** Oscillating range function
  2.  
  3. **Description:** You are to write a function that has 2 positive integer inputs, a and b. The output of this function will, for any a < b, in this case just be a. Then when a == b, the output will be b - 1, again (so this would be the output if a is either b - 1, or b). Then for a > b, the output numbers must go back down to 0 (where it started from) and 0 will be repeated twice, like b - 1. then the next section should then go back up to b - 1 and so on. If this is very confusing, I'm not really sure how to better express this in a better way, so please see the examples to clear anything up.
  4.  
  5. **Technical Details:** you can expect a to be an integer >= 0 and b to also be an integer >= 1.
  6.  
  7. **Examples:**
  8. ```
  9. These are the outputs of numbers 0 -> 19 (inclusive) as input a concatenated together:
  10. input b -> first 20 numbers as output
  11.  
  12. 1 -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  13. 2 -> 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0
  14. 3 -> 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1
  15. 4 -> 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3
  16. 5 -> 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0
  17. 6 -> 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4
  18. 7 -> 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5
  19. 8 -> 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3
  20. 9 -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1
  21. 10 -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  22. ```
Advertisement
Add Comment
Please, Sign In to add comment