From 782185e3170ba2ac22f276fa7cb35cf14b1de4f7 Mon Sep 17 00:00:00 2001 From: Rorik Star Platinum Date: Wed, 17 Dec 2025 23:43:57 +0300 Subject: [PATCH] easiest --- rust/raindrops/.exercism/config.json | 42 ++++++++ rust/raindrops/.gitignore | 2 + rust/raindrops/Cargo.toml | 9 ++ rust/raindrops/HELP.md | 89 ++++++++++++++++ rust/raindrops/README.md | 66 ++++++++++++ rust/raindrops/src/lib.rs | 14 +++ rust/raindrops/tests/raindrops.rs | 145 +++++++++++++++++++++++++++ 7 files changed, 367 insertions(+) create mode 100644 rust/raindrops/.exercism/config.json create mode 100644 rust/raindrops/.gitignore create mode 100644 rust/raindrops/Cargo.toml create mode 100644 rust/raindrops/HELP.md create mode 100644 rust/raindrops/README.md create mode 100644 rust/raindrops/src/lib.rs create mode 100644 rust/raindrops/tests/raindrops.rs diff --git a/rust/raindrops/.exercism/config.json b/rust/raindrops/.exercism/config.json new file mode 100644 index 0000000..fee65d4 --- /dev/null +++ b/rust/raindrops/.exercism/config.json @@ -0,0 +1,42 @@ +{ + "authors": [ + "EduardoBautista" + ], + "contributors": [ + "ashleygwilliams", + "ClashTheBunny", + "coriolinus", + "cwhakes", + "eddyp", + "EduardoBautista", + "efx", + "ErikSchierboom", + "IanWhitney", + "kytrinyx", + "leoyvens", + "lutostag", + "mkantor", + "nfiles", + "petertseng", + "rofrol", + "stevejb71", + "stringparser", + "xakon", + "ZapAnton" + ], + "files": { + "solution": [ + "src/lib.rs", + "Cargo.toml" + ], + "test": [ + "tests/raindrops.rs" + ], + "example": [ + ".meta/example.rs" + ] + }, + "blurb": "Convert a number into its corresponding raindrop sounds - Pling, Plang and Plong.", + "source": "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.", + "source_url": "https://en.wikipedia.org/wiki/Fizz_buzz" +} diff --git a/rust/raindrops/.gitignore b/rust/raindrops/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/rust/raindrops/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/rust/raindrops/Cargo.toml b/rust/raindrops/Cargo.toml new file mode 100644 index 0000000..a297d15 --- /dev/null +++ b/rust/raindrops/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "raindrops" +version = "0.1.0" +edition = "2024" + +# Not all libraries from crates.io are available in Exercism's test runner. +# The full list of available libraries is here: +# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml +[dependencies] diff --git a/rust/raindrops/HELP.md b/rust/raindrops/HELP.md new file mode 100644 index 0000000..22a6c00 --- /dev/null +++ b/rust/raindrops/HELP.md @@ -0,0 +1,89 @@ +# Help + +## Running the tests + +Execute the tests with: + +```bash +$ cargo test +``` + +All but the first test have been ignored. After you get the first test to +pass, open the tests source file which is located in the `tests` directory +and remove the `#[ignore]` flag from the next test and get the tests to pass +again. Each separate test is a function with `#[test]` flag above it. +Continue, until you pass every test. + +If you wish to run _only ignored_ tests without editing the tests source file, use: + +```bash +$ cargo test -- --ignored +``` + +If you are using Rust 1.51 or later, you can run _all_ tests with + +```bash +$ cargo test -- --include-ignored +``` + +To run a specific test, for example `some_test`, you can use: + +```bash +$ cargo test some_test +``` + +If the specific test is ignored, use: + +```bash +$ cargo test some_test -- --ignored +``` + +To learn more about Rust tests refer to the online [test documentation][rust-tests]. + +[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html + +## Submitting your solution + +You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Rust track's documentation](https://exercism.org/docs/tracks/rust) +- The [Rust track's programming category on the forum](https://forum.exercism.org/c/programming/rust) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +## Rust Installation + +Refer to the [exercism help page][help-page] for Rust installation and learning +resources. + +## Submitting the solution + +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. + +## Feedback, Issues, Pull Requests + +Head to [the forum](https://forum.exercism.org/c/programming/rust/) and create a post to provide feedback about an exercise or if you want to help implement new exercises. +Members of the rust track team are happy to help! + +The GitHub [track repository][github] is the home for all of the Rust exercises. + +If you want to know more about Exercism, take a look at the [contribution guide]. + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. + +[help-page]: https://exercism.org/tracks/rust/learning +[github]: https://github.com/exercism/rust +[contribution guide]: https://exercism.org/docs/community/contributors \ No newline at end of file diff --git a/rust/raindrops/README.md b/rust/raindrops/README.md new file mode 100644 index 0000000..9a6d1a2 --- /dev/null +++ b/rust/raindrops/README.md @@ -0,0 +1,66 @@ +# Raindrops + +Welcome to Raindrops on Exercism's Rust Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Introduction + +Raindrops is a slightly more complex version of the FizzBuzz challenge, a classic interview question. + +## Instructions + +Your task is to convert a number into its corresponding raindrop sounds. + +If a given number: + +- is divisible by 3, add "Pling" to the result. +- is divisible by 5, add "Plang" to the result. +- is divisible by 7, add "Plong" to the result. +- **is not** divisible by 3, 5, or 7, the result should be the number as a string. + +## Examples + +- 28 is divisible by 7, but not 3 or 5, so the result would be `"Plong"`. +- 30 is divisible by 3 and 5, but not 7, so the result would be `"PlingPlang"`. +- 34 is not divisible by 3, 5, or 7, so the result would be `"34"`. + +~~~~exercism/note +A common way to test if one number is evenly divisible by another is to compare the [remainder][remainder] or [modulus][modulo] to zero. +Most languages provide operators or functions for one (or both) of these. + +[remainder]: https://exercism.org/docs/programming/operators/remainder +[modulo]: https://en.wikipedia.org/wiki/Modulo_operation +~~~~ + +## Source + +### Created by + +- @EduardoBautista + +### Contributed to by + +- @ashleygwilliams +- @ClashTheBunny +- @coriolinus +- @cwhakes +- @eddyp +- @EduardoBautista +- @efx +- @ErikSchierboom +- @IanWhitney +- @kytrinyx +- @leoyvens +- @lutostag +- @mkantor +- @nfiles +- @petertseng +- @rofrol +- @stevejb71 +- @stringparser +- @xakon +- @ZapAnton + +### Based on + +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 \ No newline at end of file diff --git a/rust/raindrops/src/lib.rs b/rust/raindrops/src/lib.rs new file mode 100644 index 0000000..b6e98ea --- /dev/null +++ b/rust/raindrops/src/lib.rs @@ -0,0 +1,14 @@ +pub fn raindrops(n: u32) -> String { + let mut res = String::new(); + if 0 == n % 3 { + res.push_str("Pling"); + } + if 0 == n % 5 { + res.push_str("Plang"); + } + if 0 == n % 7 { + res.push_str("Plong"); + } + + if res.is_empty() { n.to_string() } else { res } +} diff --git a/rust/raindrops/tests/raindrops.rs b/rust/raindrops/tests/raindrops.rs new file mode 100644 index 0000000..95507a0 --- /dev/null +++ b/rust/raindrops/tests/raindrops.rs @@ -0,0 +1,145 @@ +use raindrops::*; + +#[test] +fn the_sound_for_1_is_1() { + let input = 1; + let output = raindrops(input); + let expected = "1"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_3_is_pling() { + let input = 3; + let output = raindrops(input); + let expected = "Pling"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_5_is_plang() { + let input = 5; + let output = raindrops(input); + let expected = "Plang"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_7_is_plong() { + let input = 7; + let output = raindrops(input); + let expected = "Plong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_6_is_pling_as_it_has_a_factor_3() { + let input = 6; + let output = raindrops(input); + let expected = "Pling"; + assert_eq!(output, expected); +} + +#[test] +fn test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base() { + let input = 8; + let output = raindrops(input); + let expected = "8"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_9_is_pling_as_it_has_a_factor_3() { + let input = 9; + let output = raindrops(input); + let expected = "Pling"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_10_is_plang_as_it_has_a_factor_5() { + let input = 10; + let output = raindrops(input); + let expected = "Plang"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_14_is_plong_as_it_has_a_factor_of_7() { + let input = 14; + let output = raindrops(input); + let expected = "Plong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5() { + let input = 15; + let output = raindrops(input); + let expected = "PlingPlang"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7() { + let input = 21; + let output = raindrops(input); + let expected = "PlingPlong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_25_is_plang_as_it_has_a_factor_5() { + let input = 25; + let output = raindrops(input); + let expected = "Plang"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_27_is_pling_as_it_has_a_factor_3() { + let input = 27; + let output = raindrops(input); + let expected = "Pling"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7() { + let input = 35; + let output = raindrops(input); + let expected = "PlangPlong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_49_is_plong_as_it_has_a_factor_7() { + let input = 49; + let output = raindrops(input); + let expected = "Plong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_52_is_52() { + let input = 52; + let output = raindrops(input); + let expected = "52"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7() { + let input = 105; + let output = raindrops(input); + let expected = "PlingPlangPlong"; + assert_eq!(output, expected); +} + +#[test] +fn the_sound_for_3125_is_plang_as_it_has_a_factor_5() { + let input = 3125; + let output = raindrops(input); + let expected = "Plang"; + assert_eq!(output, expected); +}