Exercism: Bash version of the 'Raindrops' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.6 KiB

3 years ago
  1. # Raindrops
  2. Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation).
  3. The rules of `raindrops` are that if a given number:
  4. - has 3 as a factor, add 'Pling' to the result.
  5. - has 5 as a factor, add 'Plang' to the result.
  6. - has 7 as a factor, add 'Plong' to the result.
  7. - _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number.
  8. ## Examples
  9. - 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong".
  10. - 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang".
  11. - 34 is not factored by 3, 5, or 7, so the result would be "34".
  12. Run the tests with:
  13. ```bash
  14. bats raindrops_test.sh
  15. ```
  16. After the first test(s) pass, continue by commenting out or removing the
  17. `[[ $BATS_RUN_SKIPPED == true ]] || skip`
  18. annotations prepending other tests.
  19. To run all tests, including the ones with `skip` annotations, run:
  20. ```bash
  21. BATS_RUN_SKIPPED=true bats raindrops_test.sh
  22. ```
  23. ## Source
  24. A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. [https://en.wikipedia.org/wiki/Fizz_buzz](https://en.wikipedia.org/wiki/Fizz_buzz)
  25. ## External utilities
  26. `Bash` is a language to write "scripts" -- programs that can call
  27. external tools, such as
  28. [`sed`](https://www.gnu.org/software/sed/),
  29. [`awk`](https://www.gnu.org/software/gawk/),
  30. [`date`](https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html)
  31. and even programs written in other programming languages,
  32. like [`Python`](https://www.python.org/).
  33. This track does not restrict the usage of these utilities, and as long
  34. as your solution is portable between systems and does not require
  35. installation of third party applications, feel free to use them to solve
  36. the exercise.
  37. For an extra challenge, if you would like to have a better understanding
  38. of the language, try to re-implement the solution in pure `Bash`,
  39. without using any external tools. Note that there are some types of
  40. problems that bash cannot solve, such as performing floating point
  41. arithmetic and manipulating dates: for those, you must call out to an
  42. external tool.
  43. ## Submitting Incomplete Solutions
  44. It's possible to submit an incomplete solution so you can see how others
  45. have completed the exercise.