summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/difference-of-squares/.exercism/config.json41
-rw-r--r--rust/difference-of-squares/.exercism/metadata.json1
-rw-r--r--rust/difference-of-squares/.gitignore8
-rw-r--r--rust/difference-of-squares/Cargo.toml4
-rw-r--r--rust/difference-of-squares/HELP.md86
-rw-r--r--rust/difference-of-squares/README.md51
-rw-r--r--rust/difference-of-squares/src/lib.rs11
-rw-r--r--rust/difference-of-squares/tests/difference-of-squares.rs54
8 files changed, 256 insertions, 0 deletions
diff --git a/rust/difference-of-squares/.exercism/config.json b/rust/difference-of-squares/.exercism/config.json
new file mode 100644
index 0000000..ac80533
--- /dev/null
+++ b/rust/difference-of-squares/.exercism/config.json
@@ -0,0 +1,41 @@
+{
+ "authors": [
+ "EduardoBautista"
+ ],
+ "contributors": [
+ "ashleygwilliams",
+ "coriolinus",
+ "cwhakes",
+ "eddyp",
+ "EduardoBautista",
+ "efx",
+ "ErikSchierboom",
+ "IanWhitney",
+ "kytrinyx",
+ "leoyvens",
+ "lutostag",
+ "mkantor",
+ "nfiles",
+ "petertseng",
+ "rofrol",
+ "stringparser",
+ "TheDarkula",
+ "xakon",
+ "ZapAnton"
+ ],
+ "files": {
+ "solution": [
+ "src/lib.rs",
+ "Cargo.toml"
+ ],
+ "test": [
+ "tests/difference-of-squares.rs"
+ ],
+ "example": [
+ ".meta/example.rs"
+ ]
+ },
+ "blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.",
+ "source": "Problem 6 at Project Euler",
+ "source_url": "https://projecteuler.net/problem=6"
+}
diff --git a/rust/difference-of-squares/.exercism/metadata.json b/rust/difference-of-squares/.exercism/metadata.json
new file mode 100644
index 0000000..5336300
--- /dev/null
+++ b/rust/difference-of-squares/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"rust","exercise":"difference-of-squares","id":"2db9f6b1b7034e429acda0cce080a18b","url":"https://exercism.org/tracks/rust/exercises/difference-of-squares","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/rust/difference-of-squares/.gitignore b/rust/difference-of-squares/.gitignore
new file mode 100644
index 0000000..db7f315
--- /dev/null
+++ b/rust/difference-of-squares/.gitignore
@@ -0,0 +1,8 @@
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+**/*.rs.bk
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
+Cargo.lock
diff --git a/rust/difference-of-squares/Cargo.toml b/rust/difference-of-squares/Cargo.toml
new file mode 100644
index 0000000..71d56f8
--- /dev/null
+++ b/rust/difference-of-squares/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+edition = "2021"
+name = "difference-of-squares"
+version = "1.2.0"
diff --git a/rust/difference-of-squares/HELP.md b/rust/difference-of-squares/HELP.md
new file mode 100644
index 0000000..67add76
--- /dev/null
+++ b/rust/difference-of-squares/HELP.md
@@ -0,0 +1,86 @@
+# 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
+
+The GitHub [track repository][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!
+
+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/difference-of-squares/README.md b/rust/difference-of-squares/README.md
new file mode 100644
index 0000000..9c59763
--- /dev/null
+++ b/rust/difference-of-squares/README.md
@@ -0,0 +1,51 @@
+# Difference of Squares
+
+Welcome to Difference of Squares on Exercism's Rust Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
+
+The square of the sum of the first ten natural numbers is
+(1 + 2 + ... + 10)² = 55² = 3025.
+
+The sum of the squares of the first ten natural numbers is
+1² + 2² + ... + 10² = 385.
+
+Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is 3025 - 385 = 2640.
+
+You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged.
+Finding the best algorithm for the problem is a key skill in software engineering.
+
+## Source
+
+### Created by
+
+- @EduardoBautista
+
+### Contributed to by
+
+- @ashleygwilliams
+- @coriolinus
+- @cwhakes
+- @eddyp
+- @EduardoBautista
+- @efx
+- @ErikSchierboom
+- @IanWhitney
+- @kytrinyx
+- @leoyvens
+- @lutostag
+- @mkantor
+- @nfiles
+- @petertseng
+- @rofrol
+- @stringparser
+- @TheDarkula
+- @xakon
+- @ZapAnton
+
+### Based on
+
+Problem 6 at Project Euler - https://projecteuler.net/problem=6 \ No newline at end of file
diff --git a/rust/difference-of-squares/src/lib.rs b/rust/difference-of-squares/src/lib.rs
new file mode 100644
index 0000000..fdf2e93
--- /dev/null
+++ b/rust/difference-of-squares/src/lib.rs
@@ -0,0 +1,11 @@
+pub fn square_of_sum(n: u32) -> u32 {
+ todo!("square of sum of 1...{n}")
+}
+
+pub fn sum_of_squares(n: u32) -> u32 {
+ todo!("sum of squares of 1...{n}")
+}
+
+pub fn difference(n: u32) -> u32 {
+ todo!("difference between square of sum of 1...{n} and sum of squares of 1...{n}")
+}
diff --git a/rust/difference-of-squares/tests/difference-of-squares.rs b/rust/difference-of-squares/tests/difference-of-squares.rs
new file mode 100644
index 0000000..672faae
--- /dev/null
+++ b/rust/difference-of-squares/tests/difference-of-squares.rs
@@ -0,0 +1,54 @@
+use difference_of_squares as squares;
+
+#[test]
+fn square_of_sum_1() {
+ assert_eq!(1, squares::square_of_sum(1));
+}
+
+#[test]
+#[ignore]
+fn square_of_sum_5() {
+ assert_eq!(225, squares::square_of_sum(5));
+}
+
+#[test]
+#[ignore]
+fn square_of_sum_100() {
+ assert_eq!(25_502_500, squares::square_of_sum(100));
+}
+
+#[test]
+#[ignore]
+fn sum_of_squares_1() {
+ assert_eq!(1, squares::sum_of_squares(1));
+}
+
+#[test]
+#[ignore]
+fn sum_of_squares_5() {
+ assert_eq!(55, squares::sum_of_squares(5));
+}
+
+#[test]
+#[ignore]
+fn sum_of_squares_100() {
+ assert_eq!(338_350, squares::sum_of_squares(100));
+}
+
+#[test]
+#[ignore]
+fn difference_1() {
+ assert_eq!(0, squares::difference(1));
+}
+
+#[test]
+#[ignore]
+fn difference_5() {
+ assert_eq!(170, squares::difference(5));
+}
+
+#[test]
+#[ignore]
+fn difference_100() {
+ assert_eq!(25_164_150, squares::difference(100));
+}