summary refs log tree commit diff stats
path: root/rust
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-08 23:11:02 +0530
committerAndinus <andinus@nand.sh>2021-09-08 23:11:02 +0530
commit9df866b411301652683cfc546fef561a006ea9b1 (patch)
tree56dc085dcc59f22081a84288916e1d760ad7ccdd /rust
parentad9f2bf5df32e800113d0952211535f6798d522d (diff)
downloadexercism-9df866b411301652683cfc546fef561a006ea9b1.tar.gz
Rust: Add Assembly Line
Diffstat (limited to 'rust')
-rw-r--r--rust/assembly-line/Cargo.toml4
-rw-r--r--rust/assembly-line/HELP.md85
-rw-r--r--rust/assembly-line/HINTS.md13
-rw-r--r--rust/assembly-line/README.md86
-rw-r--r--rust/assembly-line/src/lib.rs11
-rw-r--r--rust/assembly-line/tests/assembly-line.rs69
6 files changed, 268 insertions, 0 deletions
diff --git a/rust/assembly-line/Cargo.toml b/rust/assembly-line/Cargo.toml
new file mode 100644
index 0000000..fe09ff3
--- /dev/null
+++ b/rust/assembly-line/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "assembly-line"
+version = "0.1.0"
+edition = "2018"
diff --git a/rust/assembly-line/HELP.md b/rust/assembly-line/HELP.md
new file mode 100644
index 0000000..b4252f8
--- /dev/null
+++ b/rust/assembly-line/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/assembly-line/HINTS.md b/rust/assembly-line/HINTS.md
new file mode 100644
index 0000000..800b9f3
--- /dev/null
+++ b/rust/assembly-line/HINTS.md
@@ -0,0 +1,13 @@
+# Hints
+
+## General
+
+## 1. Calculate the production rate per hour
+
+- Determining the success rate can be done through a [conditional statement](https://doc.rust-lang.org/stable/book/ch03-05-control-flow.html#if-expressions) or with [pattern matching](https://doc.rust-lang.org/stable/book/ch18-01-all-the-places-for-patterns.html#match-arms).
+- As Rust only allows multiplication between values of the same type, some [type casting](https://doc.rust-lang.org/rust-by-example/types/cast.html) will have to be done.
+
+## 2. Calculate the number of working items produced per minute
+
+
+- Just like multiplication, division is only possible between numbers of the same type. By writing a number with a decimal point (e.g. `1.0` instead of `1`) we can write inline constants with a floating point type.
\ No newline at end of file
diff --git a/rust/assembly-line/README.md b/rust/assembly-line/README.md
new file mode 100644
index 0000000..b9bc544
--- /dev/null
+++ b/rust/assembly-line/README.md
@@ -0,0 +1,86 @@
+# Assembly Line
+
+Welcome to Assembly Line on Exercism's Rust Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
+
+## Introduction
+
+## numbers
+
+There are two different categories of numbers in Rust.
+
+The name of a numeric type consists of two parts:
+
+- A letter to specify whether it's a floating-point number (f), unsigned integer (u) or signed integer (i)
+- A number to specify the numbers size in bits. Larger types have a greater range between minimum and maximum values.
+  For floating points it will also allow for more numbers behind the decimal separator.
+
+The following combinations are possible:
+
+- 8 bits: `u8`, `i8`
+- 16 bits: `u16`, `i16`
+- 32 bits: `u32`, `i32`, `f32`
+- 64 bits: `u64`, `i64`, `f64`
+- 128 bits: `u128`, `i128`
+
+Note that there are only 32-bits and 64-bits variants for floating-point numbers.
+
+## Integers
+
+- Integers: numbers with no digits behind the decimal separator (whole numbers).
+  Integer types can either store only positive numbers (unsigned) or store either positive and negative numbers (signed).
+  Examples are -6, 0, 1, 25, 976 and 500000.
+
+## Floating Point Numbers
+
+- Floating-point numbers: numbers with zero or more digits behind the decimal separator.
+  Examples are -2.4, 0.1, 3.14, 16.984025 and 1024.0.
+
+## Converting between number types
+
+Rust doesn't do any implicit type conversion.
+This means that if you need to turn one numeric type into another, you have to do so explicitly.
+When converting from a larger type to a smaller one (for instance `u64` to `u32`) you could lose data.
+Converting from a floating point to an integer **will** lose everything behind the decimal point, effectively rounding down.
+
+## Instructions
+
+In this exercise you'll be writing code to analyze the production of an assembly line in a car factory. The assembly line's speed can range from `0` (off) to `10` (maximum).
+
+At its lowest speed (`1`), `221` cars are produced each hour. The production increases linearly with the speed. So with the speed set to `4`, it should produce `4 * 221 = 884` cars per hour. However, higher speeds increase the likelihood that faulty cars are produced, which then have to be discarded. The following table shows how speed influences the success rate:
+
+- `1` to `4`: 100% success rate.
+- `5` to `8`: 90% success rate.
+- `9` and `10`: 77% success rate.
+
+You have two tasks.
+
+## 1. Calculate the production rate per hour
+
+Implement a method to calculate the assembly line's production rate per hour, taking into account its success rate:
+
+```rust
+numbers::production_rate_per_hour(6)
+// Returns: 1193.4
+```
+
+Note that the value returned is an `f64`.
+
+## 2. Calculate the number of working items produced per minute
+
+Implement a method to calculate how many working cars are produced per minute:
+
+```rust
+numbers::working_items_per_minute(6)
+// Returns: 19
+```
+
+Note that the value returned is an `u32`.
+
+## Source
+
+### Created by
+
+- @LewisClement
+- @efx
\ No newline at end of file
diff --git a/rust/assembly-line/src/lib.rs b/rust/assembly-line/src/lib.rs
new file mode 100644
index 0000000..de29988
--- /dev/null
+++ b/rust/assembly-line/src/lib.rs
@@ -0,0 +1,11 @@
+// This stub file contains items which aren't used yet; feel free to remove this module attribute
+// to enable stricter warnings.
+#![allow(unused)]
+
+pub fn production_rate_per_hour(speed: u8) -> f64 {
+    unimplemented!("calculate hourly production rate at speed: {}", speed)
+}
+
+pub fn working_items_per_minute(speed: u8) -> u32 {
+    unimplemented!("calculate the amount of working items at speed: {}", speed)
+}
diff --git a/rust/assembly-line/tests/assembly-line.rs b/rust/assembly-line/tests/assembly-line.rs
new file mode 100644
index 0000000..746a914
--- /dev/null
+++ b/rust/assembly-line/tests/assembly-line.rs
@@ -0,0 +1,69 @@
+fn process_rate_per_hour(speed: u8, expected_rate: f64) {
+    assert!((assembly_line::production_rate_per_hour(speed) - expected_rate).abs() < f64::EPSILON);
+}
+
+fn process_rate_per_minute(speed: u8, expected_rate: u32) {
+    assert_eq!(
+        assembly_line::working_items_per_minute(speed),
+        expected_rate
+    );
+}
+
+#[test]
+fn production_rate_per_hour_at_speed_zero() {
+    process_rate_per_hour(0, 0.0);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_hour_at_speed_one() {
+    process_rate_per_hour(1, 221.0);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_hour_at_speed_four() {
+    process_rate_per_hour(4, 884.0);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_hour_at_speed_seven() {
+    process_rate_per_hour(7, 1392.3);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_hour_at_speed_nine() {
+    process_rate_per_hour(9, 1531.53);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_minute_at_speed_zero() {
+    process_rate_per_minute(0, 0);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_minute_at_speed_one() {
+    process_rate_per_minute(1, 3);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_minute_at_speed_five() {
+    process_rate_per_minute(5, 16);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_minute_at_speed_eight() {
+    process_rate_per_minute(8, 26);
+}
+
+#[ignore]
+#[test]
+fn production_rate_per_minute_at_speed_ten() {
+    process_rate_per_minute(10, 28);
+}