commit ad9ebb8920cd0609e2fd0b3e2505f07880660108 Author: mollusk Date: Tue Feb 5 07:08:31 2019 -0700 Init commit diff --git a/branches/.gitignore b/branches/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/branches/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/branches/Cargo.lock b/branches/Cargo.lock new file mode 100644 index 0000000..a9b4d7e --- /dev/null +++ b/branches/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "branches" +version = "0.1.0" + diff --git a/branches/Cargo.toml b/branches/Cargo.toml new file mode 100644 index 0000000..4fc4a1e --- /dev/null +++ b/branches/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "branches" +version = "0.1.0" +authors = ["mollusk "] +edition = "2018" + +[dependencies] diff --git a/branches/src/main.rs b/branches/src/main.rs new file mode 100644 index 0000000..80a4428 --- /dev/null +++ b/branches/src/main.rs @@ -0,0 +1,62 @@ +fn conditionals_test() { + let number = 6; + + if number % 4 == 0 { + println!("number is divisible by 4"); + } else if number % 3 == 0 { + println!("number is divisible by 3"); + } else if number % 2 == 0 { + println!("number is divisible by 2"); + } else { + println!("number is not divisible by 4, 3, or 2"); + } + + let condition = true; + let number = if condition { 5 } else { 6 }; + + println!("The value of number is: {}", number); +} + +fn loop_test(){ + loop { + println!("again!"); + break + } +} + + +fn while_loop_test(){ + let mut number = 3; + + while number != 0 { + println!("{}!", number); + + number = number -1; + } + + println!("LIFTOFF!!!"); +} + + +fn for_loop_test(){ + let a = [10, 20, 30, 40, 50]; + let mut index = 0; + + for element in a.iter() { + println!("the value is: {}", element); + } + + for number in (1..4).rev() { + println!("{}!", number); + } + + println!("LIFTOFF!"); +} + +fn main(){ + conditionals_test(); + loop_test(); + while_loop_test(); + for_loop_test(); + +} \ No newline at end of file diff --git a/functions/.gitignore b/functions/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/functions/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/functions/Cargo.lock b/functions/Cargo.lock new file mode 100644 index 0000000..89a654d --- /dev/null +++ b/functions/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "functions" +version = "0.1.0" + diff --git a/functions/Cargo.toml b/functions/Cargo.toml new file mode 100644 index 0000000..b70882e --- /dev/null +++ b/functions/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "functions" +version = "0.1.0" +authors = ["mollusk "] +edition = "2018" + +[dependencies] diff --git a/functions/src/main.rs b/functions/src/main.rs new file mode 100644 index 0000000..aa7d305 --- /dev/null +++ b/functions/src/main.rs @@ -0,0 +1,30 @@ +fn main() { + + println!("Function 1\n"); + another_function(5, 6); + + let x = five(); + + println!("Function 2\n"); + println!("The value of x is: {}\n", x); + + let x = plus_one(5); + + println!("Function 3\n"); + + println!("The value of x is {}: ", x); +} + + +fn another_function(x: i32, y: i32) { + println!("The value of x is: {}", x); + println!("The value of y is: {}\n", y); +} + +fn five() -> i32 { + 5 +} + +fn plus_one(x: i32) -> i32 { + x + 1 +} \ No newline at end of file diff --git a/guessing_game/.gitignore b/guessing_game/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/guessing_game/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/guessing_game/Cargo.lock b/guessing_game/Cargo.lock new file mode 100644 index 0000000..590889e --- /dev/null +++ b/guessing_game/Cargo.lock @@ -0,0 +1,79 @@ +[[package]] +name = "fuchsia-cprng" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "guessing_game" +version = "0.1.0" +dependencies = [ + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.48" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31" +"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/guessing_game/Cargo.toml b/guessing_game/Cargo.toml new file mode 100644 index 0000000..19e6d7e --- /dev/null +++ b/guessing_game/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "guessing_game" +version = "0.1.0" +authors = ["mollusk "] +edition = "2018" + +[dependencies] + +rand = "0.4.0" diff --git a/guessing_game/src/main.rs b/guessing_game/src/main.rs new file mode 100644 index 0000000..cbe7a81 --- /dev/null +++ b/guessing_game/src/main.rs @@ -0,0 +1,36 @@ +use std::io; +use std::cmp::Ordering; +use rand::Rng; + +fn main() { + println!("Guess the number!"); + + let secret_number = rand::thread_rng() + .gen_range(1, 101); + + + loop { + println!("Please input your guess."); + + let mut guess = String::new(); + + io::stdin().read_line(&mut guess) + .expect("Failed to read line"); + + let guess: u32 = match guess.trim().parse() { + Ok(num) => num, + Err(_) => continue, + }; + + println!("You guessed: {}", guess); + + match guess.cmp(&secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { + println!("You win!"); + break; + } + } + } +} diff --git a/hello_cargo/.gitignore b/hello_cargo/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/hello_cargo/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/hello_cargo/Cargo.lock b/hello_cargo/Cargo.lock new file mode 100644 index 0000000..bd8a836 --- /dev/null +++ b/hello_cargo/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "hello_cargo" +version = "0.1.0" + diff --git a/hello_cargo/Cargo.toml b/hello_cargo/Cargo.toml new file mode 100644 index 0000000..e85a82f --- /dev/null +++ b/hello_cargo/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hello_cargo" +version = "0.1.0" +authors = ["mollusk "] +edition = "2018" + +[dependencies] diff --git a/hello_cargo/src/main.rs b/hello_cargo/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/hello_cargo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/hello_world/main b/hello_world/main new file mode 100755 index 0000000..395789b Binary files /dev/null and b/hello_world/main differ diff --git a/hello_world/main.rs b/hello_world/main.rs new file mode 100644 index 0000000..942454f --- /dev/null +++ b/hello_world/main.rs @@ -0,0 +1,4 @@ +fn main() { + println!("Hello, World"); + +} \ No newline at end of file diff --git a/variables/.gitignore b/variables/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/variables/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/variables/Cargo.lock b/variables/Cargo.lock new file mode 100644 index 0000000..8201289 --- /dev/null +++ b/variables/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "variable" +version = "0.1.0" + diff --git a/variables/Cargo.toml b/variables/Cargo.toml new file mode 100644 index 0000000..c91b791 --- /dev/null +++ b/variables/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "variable" +version = "0.1.0" +authors = ["mollusk "] +edition = "2018" + +[dependencies] diff --git a/variables/src/main.rs b/variables/src/main.rs new file mode 100644 index 0000000..40ede6e --- /dev/null +++ b/variables/src/main.rs @@ -0,0 +1,52 @@ +fn main() { + + //manipulate immutable variables + let x = 5; + + let x = x + 1; + + let x = x * 2; + + println!("The value of x is: {}", x); + + + // addition + let sum = 5 + 10; + + // subtraction + let difference = 95.5 - 4.3; + + // multiplication + let product = 4 * 30; + + // division + let quotient = 56.7 / 32.2; + + // remainder + let remainder = 43 % 5; + + //bools + let t = true; + let f: bool = false; // with explicit type annotation + + //characters + let c = 'z'; + let z = 'ℤ'; + let heart_eyed_cat = '😻'; + + //tuples + let tup = (500, 6.4, 1); + + let (x, y, z) = tup; + + println!("The value of y is: {}", y); + + let x: (i32, f64, u8) = (500, 6.4, 1); + + let five_hundred = x.0; + + let six_point_four = x.1; + + let one = x.2; + +}