summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--rust/armstrong-numbers/.gitignore8
-rw-r--r--rust/armstrong-numbers/Cargo.toml4
-rw-r--r--rust/armstrong-numbers/HELP.md85
-rw-r--r--rust/armstrong-numbers/README.md44
-rw-r--r--rust/armstrong-numbers/src/lib.rs3
-rw-r--r--rust/armstrong-numbers/tests/armstrong-numbers.rs54
6 files changed, 198 insertions, 0 deletions
diff --git a/rust/armstrong-numbers/.gitignore b/rust/armstrong-numbers/.gitignore
new file mode 100644
index 0000000..db7f315
--- /dev/null
+++ b/rust/armstrong-numbers/.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/armstrong-numbers/Cargo.toml b/rust/armstrong-numbers/Cargo.toml
new file mode 100644
index 0000000..22e66de
--- /dev/null
+++ b/rust/armstrong-numbers/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+edition = "2018"
+name = "armstrong_numbers"
+version = "1.1.0"
diff --git a/rust/armstrong-numbers/HELP.md b/rust/armstrong-numbers/HELP.md
new file mode 100644
index 0000000..b4252f8
--- /dev/null
+++ b/rust/armstrong-numbers/HELP.md
@@ -0,0 +1,85 @@
+# 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` 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)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- 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.io/tracks/rust/learning
+[github]: https://github.com/exercism/rust
+[contribution guide]: https://exercism.io/docs/community/contributors
\ No newline at end of file
diff --git a/rust/armstrong-numbers/README.md b/rust/armstrong-numbers/README.md
new file mode 100644
index 0000000..bbeea2b
--- /dev/null
+++ b/rust/armstrong-numbers/README.md
@@ -0,0 +1,44 @@
+# Armstrong Numbers
+
+Welcome to Armstrong Numbers on Exercism's Rust Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits.
+
+For example:
+
+- 9 is an Armstrong number, because `9 = 9^1 = 9`
+- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1`
+- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153`
+- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
+
+Write some code to determine whether a number is an Armstrong number.
+
+## Source
+
+### Created by
+
+- @shingtaklam1324
+
+### Contributed to by
+
+- @AndrewKvalheim
+- @coriolinus
+- @cwhakes
+- @eddyp
+- @efx
+- @ErikSchierboom
+- @lutostag
+- @ocstl
+- @petertseng
+- @rofrol
+- @sputnick1124
+- @stringparser
+- @xakon
+- @ZapAnton
+
+### Based on
+
+Wikipedia - https://en.wikipedia.org/wiki/Narcissistic_number
\ No newline at end of file
diff --git a/rust/armstrong-numbers/src/lib.rs b/rust/armstrong-numbers/src/lib.rs
new file mode 100644
index 0000000..41de1c3
--- /dev/null
+++ b/rust/armstrong-numbers/src/lib.rs
@@ -0,0 +1,3 @@
+pub fn is_armstrong_number(num: u32) -> bool {
+    unimplemented!("true if {} is an armstrong number", num)
+}
diff --git a/rust/armstrong-numbers/tests/armstrong-numbers.rs b/rust/armstrong-numbers/tests/armstrong-numbers.rs
new file mode 100644
index 0000000..2163451
--- /dev/null
+++ b/rust/armstrong-numbers/tests/armstrong-numbers.rs
@@ -0,0 +1,54 @@
+use armstrong_numbers::*;
+
+#[test]
+fn test_zero_is_an_armstrong_number() {
+    assert!(is_armstrong_number(0))
+}
+
+#[test]
+#[ignore]
+fn test_single_digit_numbers_are_armstrong_numbers() {
+    assert!(is_armstrong_number(5))
+}
+
+#[test]
+#[ignore]
+fn test_there_are_no_2_digit_armstrong_numbers() {
+    assert!(!is_armstrong_number(10))
+}
+
+#[test]
+#[ignore]
+fn test_three_digit_armstrong_number() {
+    assert!(is_armstrong_number(153))
+}
+
+#[test]
+#[ignore]
+fn test_three_digit_non_armstrong_number() {
+    assert!(!is_armstrong_number(100))
+}
+
+#[test]
+#[ignore]
+fn test_four_digit_armstrong_number() {
+    assert!(is_armstrong_number(9474))
+}
+
+#[test]
+#[ignore]
+fn test_four_digit_non_armstrong_number() {
+    assert!(!is_armstrong_number(9475))
+}
+
+#[test]
+#[ignore]
+fn test_seven_digit_armstrong_number() {
+    assert!(is_armstrong_number(9_926_315))
+}
+
+#[test]
+#[ignore]
+fn test_seven_digit_non_armstrong_number() {
+    assert!(!is_armstrong_number(9_926_316))
+}