Exercism: Rust version of the 'Beer Song' 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.

401 lines
15 KiB

  1. # Beer Song
  2. Recite the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
  3. Note that not all verses are identical.
  4. ```text
  5. 99 bottles of beer on the wall, 99 bottles of beer.
  6. Take one down and pass it around, 98 bottles of beer on the wall.
  7. 98 bottles of beer on the wall, 98 bottles of beer.
  8. Take one down and pass it around, 97 bottles of beer on the wall.
  9. 97 bottles of beer on the wall, 97 bottles of beer.
  10. Take one down and pass it around, 96 bottles of beer on the wall.
  11. 96 bottles of beer on the wall, 96 bottles of beer.
  12. Take one down and pass it around, 95 bottles of beer on the wall.
  13. 95 bottles of beer on the wall, 95 bottles of beer.
  14. Take one down and pass it around, 94 bottles of beer on the wall.
  15. 94 bottles of beer on the wall, 94 bottles of beer.
  16. Take one down and pass it around, 93 bottles of beer on the wall.
  17. 93 bottles of beer on the wall, 93 bottles of beer.
  18. Take one down and pass it around, 92 bottles of beer on the wall.
  19. 92 bottles of beer on the wall, 92 bottles of beer.
  20. Take one down and pass it around, 91 bottles of beer on the wall.
  21. 91 bottles of beer on the wall, 91 bottles of beer.
  22. Take one down and pass it around, 90 bottles of beer on the wall.
  23. 90 bottles of beer on the wall, 90 bottles of beer.
  24. Take one down and pass it around, 89 bottles of beer on the wall.
  25. 89 bottles of beer on the wall, 89 bottles of beer.
  26. Take one down and pass it around, 88 bottles of beer on the wall.
  27. 88 bottles of beer on the wall, 88 bottles of beer.
  28. Take one down and pass it around, 87 bottles of beer on the wall.
  29. 87 bottles of beer on the wall, 87 bottles of beer.
  30. Take one down and pass it around, 86 bottles of beer on the wall.
  31. 86 bottles of beer on the wall, 86 bottles of beer.
  32. Take one down and pass it around, 85 bottles of beer on the wall.
  33. 85 bottles of beer on the wall, 85 bottles of beer.
  34. Take one down and pass it around, 84 bottles of beer on the wall.
  35. 84 bottles of beer on the wall, 84 bottles of beer.
  36. Take one down and pass it around, 83 bottles of beer on the wall.
  37. 83 bottles of beer on the wall, 83 bottles of beer.
  38. Take one down and pass it around, 82 bottles of beer on the wall.
  39. 82 bottles of beer on the wall, 82 bottles of beer.
  40. Take one down and pass it around, 81 bottles of beer on the wall.
  41. 81 bottles of beer on the wall, 81 bottles of beer.
  42. Take one down and pass it around, 80 bottles of beer on the wall.
  43. 80 bottles of beer on the wall, 80 bottles of beer.
  44. Take one down and pass it around, 79 bottles of beer on the wall.
  45. 79 bottles of beer on the wall, 79 bottles of beer.
  46. Take one down and pass it around, 78 bottles of beer on the wall.
  47. 78 bottles of beer on the wall, 78 bottles of beer.
  48. Take one down and pass it around, 77 bottles of beer on the wall.
  49. 77 bottles of beer on the wall, 77 bottles of beer.
  50. Take one down and pass it around, 76 bottles of beer on the wall.
  51. 76 bottles of beer on the wall, 76 bottles of beer.
  52. Take one down and pass it around, 75 bottles of beer on the wall.
  53. 75 bottles of beer on the wall, 75 bottles of beer.
  54. Take one down and pass it around, 74 bottles of beer on the wall.
  55. 74 bottles of beer on the wall, 74 bottles of beer.
  56. Take one down and pass it around, 73 bottles of beer on the wall.
  57. 73 bottles of beer on the wall, 73 bottles of beer.
  58. Take one down and pass it around, 72 bottles of beer on the wall.
  59. 72 bottles of beer on the wall, 72 bottles of beer.
  60. Take one down and pass it around, 71 bottles of beer on the wall.
  61. 71 bottles of beer on the wall, 71 bottles of beer.
  62. Take one down and pass it around, 70 bottles of beer on the wall.
  63. 70 bottles of beer on the wall, 70 bottles of beer.
  64. Take one down and pass it around, 69 bottles of beer on the wall.
  65. 69 bottles of beer on the wall, 69 bottles of beer.
  66. Take one down and pass it around, 68 bottles of beer on the wall.
  67. 68 bottles of beer on the wall, 68 bottles of beer.
  68. Take one down and pass it around, 67 bottles of beer on the wall.
  69. 67 bottles of beer on the wall, 67 bottles of beer.
  70. Take one down and pass it around, 66 bottles of beer on the wall.
  71. 66 bottles of beer on the wall, 66 bottles of beer.
  72. Take one down and pass it around, 65 bottles of beer on the wall.
  73. 65 bottles of beer on the wall, 65 bottles of beer.
  74. Take one down and pass it around, 64 bottles of beer on the wall.
  75. 64 bottles of beer on the wall, 64 bottles of beer.
  76. Take one down and pass it around, 63 bottles of beer on the wall.
  77. 63 bottles of beer on the wall, 63 bottles of beer.
  78. Take one down and pass it around, 62 bottles of beer on the wall.
  79. 62 bottles of beer on the wall, 62 bottles of beer.
  80. Take one down and pass it around, 61 bottles of beer on the wall.
  81. 61 bottles of beer on the wall, 61 bottles of beer.
  82. Take one down and pass it around, 60 bottles of beer on the wall.
  83. 60 bottles of beer on the wall, 60 bottles of beer.
  84. Take one down and pass it around, 59 bottles of beer on the wall.
  85. 59 bottles of beer on the wall, 59 bottles of beer.
  86. Take one down and pass it around, 58 bottles of beer on the wall.
  87. 58 bottles of beer on the wall, 58 bottles of beer.
  88. Take one down and pass it around, 57 bottles of beer on the wall.
  89. 57 bottles of beer on the wall, 57 bottles of beer.
  90. Take one down and pass it around, 56 bottles of beer on the wall.
  91. 56 bottles of beer on the wall, 56 bottles of beer.
  92. Take one down and pass it around, 55 bottles of beer on the wall.
  93. 55 bottles of beer on the wall, 55 bottles of beer.
  94. Take one down and pass it around, 54 bottles of beer on the wall.
  95. 54 bottles of beer on the wall, 54 bottles of beer.
  96. Take one down and pass it around, 53 bottles of beer on the wall.
  97. 53 bottles of beer on the wall, 53 bottles of beer.
  98. Take one down and pass it around, 52 bottles of beer on the wall.
  99. 52 bottles of beer on the wall, 52 bottles of beer.
  100. Take one down and pass it around, 51 bottles of beer on the wall.
  101. 51 bottles of beer on the wall, 51 bottles of beer.
  102. Take one down and pass it around, 50 bottles of beer on the wall.
  103. 50 bottles of beer on the wall, 50 bottles of beer.
  104. Take one down and pass it around, 49 bottles of beer on the wall.
  105. 49 bottles of beer on the wall, 49 bottles of beer.
  106. Take one down and pass it around, 48 bottles of beer on the wall.
  107. 48 bottles of beer on the wall, 48 bottles of beer.
  108. Take one down and pass it around, 47 bottles of beer on the wall.
  109. 47 bottles of beer on the wall, 47 bottles of beer.
  110. Take one down and pass it around, 46 bottles of beer on the wall.
  111. 46 bottles of beer on the wall, 46 bottles of beer.
  112. Take one down and pass it around, 45 bottles of beer on the wall.
  113. 45 bottles of beer on the wall, 45 bottles of beer.
  114. Take one down and pass it around, 44 bottles of beer on the wall.
  115. 44 bottles of beer on the wall, 44 bottles of beer.
  116. Take one down and pass it around, 43 bottles of beer on the wall.
  117. 43 bottles of beer on the wall, 43 bottles of beer.
  118. Take one down and pass it around, 42 bottles of beer on the wall.
  119. 42 bottles of beer on the wall, 42 bottles of beer.
  120. Take one down and pass it around, 41 bottles of beer on the wall.
  121. 41 bottles of beer on the wall, 41 bottles of beer.
  122. Take one down and pass it around, 40 bottles of beer on the wall.
  123. 40 bottles of beer on the wall, 40 bottles of beer.
  124. Take one down and pass it around, 39 bottles of beer on the wall.
  125. 39 bottles of beer on the wall, 39 bottles of beer.
  126. Take one down and pass it around, 38 bottles of beer on the wall.
  127. 38 bottles of beer on the wall, 38 bottles of beer.
  128. Take one down and pass it around, 37 bottles of beer on the wall.
  129. 37 bottles of beer on the wall, 37 bottles of beer.
  130. Take one down and pass it around, 36 bottles of beer on the wall.
  131. 36 bottles of beer on the wall, 36 bottles of beer.
  132. Take one down and pass it around, 35 bottles of beer on the wall.
  133. 35 bottles of beer on the wall, 35 bottles of beer.
  134. Take one down and pass it around, 34 bottles of beer on the wall.
  135. 34 bottles of beer on the wall, 34 bottles of beer.
  136. Take one down and pass it around, 33 bottles of beer on the wall.
  137. 33 bottles of beer on the wall, 33 bottles of beer.
  138. Take one down and pass it around, 32 bottles of beer on the wall.
  139. 32 bottles of beer on the wall, 32 bottles of beer.
  140. Take one down and pass it around, 31 bottles of beer on the wall.
  141. 31 bottles of beer on the wall, 31 bottles of beer.
  142. Take one down and pass it around, 30 bottles of beer on the wall.
  143. 30 bottles of beer on the wall, 30 bottles of beer.
  144. Take one down and pass it around, 29 bottles of beer on the wall.
  145. 29 bottles of beer on the wall, 29 bottles of beer.
  146. Take one down and pass it around, 28 bottles of beer on the wall.
  147. 28 bottles of beer on the wall, 28 bottles of beer.
  148. Take one down and pass it around, 27 bottles of beer on the wall.
  149. 27 bottles of beer on the wall, 27 bottles of beer.
  150. Take one down and pass it around, 26 bottles of beer on the wall.
  151. 26 bottles of beer on the wall, 26 bottles of beer.
  152. Take one down and pass it around, 25 bottles of beer on the wall.
  153. 25 bottles of beer on the wall, 25 bottles of beer.
  154. Take one down and pass it around, 24 bottles of beer on the wall.
  155. 24 bottles of beer on the wall, 24 bottles of beer.
  156. Take one down and pass it around, 23 bottles of beer on the wall.
  157. 23 bottles of beer on the wall, 23 bottles of beer.
  158. Take one down and pass it around, 22 bottles of beer on the wall.
  159. 22 bottles of beer on the wall, 22 bottles of beer.
  160. Take one down and pass it around, 21 bottles of beer on the wall.
  161. 21 bottles of beer on the wall, 21 bottles of beer.
  162. Take one down and pass it around, 20 bottles of beer on the wall.
  163. 20 bottles of beer on the wall, 20 bottles of beer.
  164. Take one down and pass it around, 19 bottles of beer on the wall.
  165. 19 bottles of beer on the wall, 19 bottles of beer.
  166. Take one down and pass it around, 18 bottles of beer on the wall.
  167. 18 bottles of beer on the wall, 18 bottles of beer.
  168. Take one down and pass it around, 17 bottles of beer on the wall.
  169. 17 bottles of beer on the wall, 17 bottles of beer.
  170. Take one down and pass it around, 16 bottles of beer on the wall.
  171. 16 bottles of beer on the wall, 16 bottles of beer.
  172. Take one down and pass it around, 15 bottles of beer on the wall.
  173. 15 bottles of beer on the wall, 15 bottles of beer.
  174. Take one down and pass it around, 14 bottles of beer on the wall.
  175. 14 bottles of beer on the wall, 14 bottles of beer.
  176. Take one down and pass it around, 13 bottles of beer on the wall.
  177. 13 bottles of beer on the wall, 13 bottles of beer.
  178. Take one down and pass it around, 12 bottles of beer on the wall.
  179. 12 bottles of beer on the wall, 12 bottles of beer.
  180. Take one down and pass it around, 11 bottles of beer on the wall.
  181. 11 bottles of beer on the wall, 11 bottles of beer.
  182. Take one down and pass it around, 10 bottles of beer on the wall.
  183. 10 bottles of beer on the wall, 10 bottles of beer.
  184. Take one down and pass it around, 9 bottles of beer on the wall.
  185. 9 bottles of beer on the wall, 9 bottles of beer.
  186. Take one down and pass it around, 8 bottles of beer on the wall.
  187. 8 bottles of beer on the wall, 8 bottles of beer.
  188. Take one down and pass it around, 7 bottles of beer on the wall.
  189. 7 bottles of beer on the wall, 7 bottles of beer.
  190. Take one down and pass it around, 6 bottles of beer on the wall.
  191. 6 bottles of beer on the wall, 6 bottles of beer.
  192. Take one down and pass it around, 5 bottles of beer on the wall.
  193. 5 bottles of beer on the wall, 5 bottles of beer.
  194. Take one down and pass it around, 4 bottles of beer on the wall.
  195. 4 bottles of beer on the wall, 4 bottles of beer.
  196. Take one down and pass it around, 3 bottles of beer on the wall.
  197. 3 bottles of beer on the wall, 3 bottles of beer.
  198. Take one down and pass it around, 2 bottles of beer on the wall.
  199. 2 bottles of beer on the wall, 2 bottles of beer.
  200. Take one down and pass it around, 1 bottle of beer on the wall.
  201. 1 bottle of beer on the wall, 1 bottle of beer.
  202. Take it down and pass it around, no more bottles of beer on the wall.
  203. No more bottles of beer on the wall, no more bottles of beer.
  204. Go to the store and buy some more, 99 bottles of beer on the wall.
  205. ```
  206. ## For bonus points
  207. Did you get the tests passing and the code clean? If you want to, these
  208. are some additional things you could try:
  209. * Remove as much duplication as you possibly can.
  210. * Optimize for readability, even if it means introducing duplication.
  211. * If you've removed all the duplication, do you have a lot of
  212. conditionals? Try replacing the conditionals with polymorphism, if it
  213. applies in this language. How readable is it?
  214. Then please share your thoughts in a comment on the submission. Did this
  215. experiment make the code better? Worse? Did you learn anything from it?
  216. ## Rust Installation
  217. Refer to the [exercism help page][help-page] for Rust installation and learning
  218. resources.
  219. ## Writing the Code
  220. Execute the tests with:
  221. ```bash
  222. $ cargo test
  223. ```
  224. All but the first test have been ignored. After you get the first test to
  225. pass, open the tests source file which is located in the `tests` directory
  226. and remove the `#[ignore]` flag from the next test and get the tests to pass
  227. again. Each separate test is a function with `#[test]` flag above it.
  228. Continue, until you pass every test.
  229. If you wish to run all ignored tests without editing the tests source file, use:
  230. ```bash
  231. $ cargo test -- --ignored
  232. ```
  233. To run a specific test, for example `some_test`, you can use:
  234. ```bash
  235. $ cargo test some_test
  236. ```
  237. If the specific test is ignored use:
  238. ```bash
  239. $ cargo test some_test -- --ignored
  240. ```
  241. To learn more about Rust tests refer to the [online test documentation][rust-tests]
  242. Make sure to read the [Modules][modules] chapter if you
  243. haven't already, it will help you with organizing your files.
  244. ## Further improvements
  245. After you have solved the exercise, please consider using the additional utilities, described in the [installation guide](https://exercism.io/tracks/rust/installation), to further refine your final solution.
  246. To format your solution, inside the solution directory use
  247. ```bash
  248. cargo fmt
  249. ```
  250. To see, if your solution contains some common ineffective use cases, inside the solution directory use
  251. ```bash
  252. cargo clippy --all-targets
  253. ```
  254. ## Submitting the solution
  255. Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
  256. ## Feedback, Issues, Pull Requests
  257. The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
  258. If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/main/contributing-to-language-tracks/README.md).
  259. [help-page]: https://exercism.io/tracks/rust/learning
  260. [modules]: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html
  261. [cargo]: https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html
  262. [rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
  263. ## Source
  264. Learn to Program by Chris Pine [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06)
  265. ## Submitting Incomplete Solutions
  266. It's possible to submit an incomplete solution so you can see how others have completed the exercise.