From 29f8ac1da4330bbf27f839ac454fa6fca87df81c Mon Sep 17 00:00:00 2001 From: Divlo Date: Fri, 30 Dec 2022 01:20:04 +0100 Subject: [PATCH] feat(solutions): add `is-prime-number/rust/function` --- .../solutions/rust/function/Cargo.lock | 7 +++++++ .../solutions/rust/function/Cargo.toml | 6 ++++++ .../solutions/rust/function/README.md | 3 +++ .../solutions/rust/function/src/main.rs | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 challenges/is-prime-number/solutions/rust/function/Cargo.lock create mode 100644 challenges/is-prime-number/solutions/rust/function/Cargo.toml create mode 100644 challenges/is-prime-number/solutions/rust/function/README.md create mode 100644 challenges/is-prime-number/solutions/rust/function/src/main.rs diff --git a/challenges/is-prime-number/solutions/rust/function/Cargo.lock b/challenges/is-prime-number/solutions/rust/function/Cargo.lock new file mode 100644 index 0000000..c8ae10e --- /dev/null +++ b/challenges/is-prime-number/solutions/rust/function/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust_application" +version = "1.0.0" diff --git a/challenges/is-prime-number/solutions/rust/function/Cargo.toml b/challenges/is-prime-number/solutions/rust/function/Cargo.toml new file mode 100644 index 0000000..a119ace --- /dev/null +++ b/challenges/is-prime-number/solutions/rust/function/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust_application" +version = "1.0.0" +edition = "2021" + +[dependencies] diff --git a/challenges/is-prime-number/solutions/rust/function/README.md b/challenges/is-prime-number/solutions/rust/function/README.md new file mode 100644 index 0000000..1bafe56 --- /dev/null +++ b/challenges/is-prime-number/solutions/rust/function/README.md @@ -0,0 +1,3 @@ +# is-prime-number/rust/function + +Created by [@Divlo](https://github.com/Divlo) on 29 December 2022. diff --git a/challenges/is-prime-number/solutions/rust/function/src/main.rs b/challenges/is-prime-number/solutions/rust/function/src/main.rs new file mode 100644 index 0000000..749b359 --- /dev/null +++ b/challenges/is-prime-number/solutions/rust/function/src/main.rs @@ -0,0 +1,19 @@ +use std::io; + +fn is_prime_number(number: u32) -> bool { + for iteration in 2..number { + if number % iteration == 0 { + return false; + } + } + return true; +} + +fn main() { + let mut number = String::new(); + io::stdin() + .read_line(&mut number) + .expect("Failed to read `stdin` line."); + let number: u32 = number.trim().parse().expect("Please type a number!"); + println!("{}", is_prime_number(number)); +}