diff --git a/I_have_done/intro/README.md b/I_have_done/intro/README.md new file mode 100644 index 00000000..d32e4a8b --- /dev/null +++ b/I_have_done/intro/README.md @@ -0,0 +1,8 @@ +# Intro + +Rust uses the `print!` and `println!` macros to print text to the console. + +## Further information + +- [Hello World](https://doc.rust-lang.org/rust-by-example/hello.html) +- [Formatted print](https://doc.rust-lang.org/rust-by-example/hello/print.html) diff --git a/I_have_done/intro/intro1.rs b/I_have_done/intro/intro1.rs new file mode 100644 index 00000000..3b11d4a2 --- /dev/null +++ b/I_have_done/intro/intro1.rs @@ -0,0 +1,21 @@ +// intro1.rs +// About this `I AM NOT DONE` thing: +// We sometimes encourage you to keep trying things on a given exercise, even +// after you already figured it out. If you got everything working and feel +// ready for the next exercise, remove the `I AM NOT DONE` comment below. +// Execute the command `rustlings hint intro1` for a hint. + +fn main() { + println!("Hello and"); + println!(r#" welcome to... "#); + println!(r#" _ _ _ "#); + println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#); + println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#); + println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#); + println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#); + println!(r#" |___/ "#); + println!(); + println!("This exercise compiles successfully. The remaining exercises contain a compiler"); + println!("or logic error. The central concept behind Rustlings is to fix these errors and"); + println!("solve the exercises. Good luck!"); +} diff --git a/I_have_done/intro/intro2.rs b/I_have_done/intro/intro2.rs new file mode 100644 index 00000000..60cc87a8 --- /dev/null +++ b/I_have_done/intro/intro2.rs @@ -0,0 +1,7 @@ +// intro2.rs +// Make the code print a greeting to the world. +// Execute `rustlings hint intro2` for a hint. + +fn main() { + println!("Hello!"); +} diff --git a/I_have_done/intro/mod.rs b/I_have_done/intro/mod.rs new file mode 100644 index 00000000..445c47ab --- /dev/null +++ b/I_have_done/intro/mod.rs @@ -0,0 +1,2 @@ +mod intro1; +mod intro2; diff --git a/I_have_done/variables/README.md b/I_have_done/variables/README.md new file mode 100644 index 00000000..11a7a78a --- /dev/null +++ b/I_have_done/variables/README.md @@ -0,0 +1,9 @@ +# Variables + +In Rust, variables are immutable by default. +When a variable is immutable, once a value is bound to a name, you can’t change that value. +You can make them mutable by adding mut in front of the variable name. + +## Further information + +- [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html) diff --git a/I_have_done/variables/mod.rs b/I_have_done/variables/mod.rs new file mode 100644 index 00000000..a25f477e --- /dev/null +++ b/I_have_done/variables/mod.rs @@ -0,0 +1,6 @@ +mod variables1; +mod variables2; +mod variables3; +mod variables4; +mod variables5; +mod variables6; diff --git a/I_have_done/variables/variables1.rs b/I_have_done/variables/variables1.rs new file mode 100644 index 00000000..7ef36fd0 --- /dev/null +++ b/I_have_done/variables/variables1.rs @@ -0,0 +1,9 @@ +// variables1.rs +// Make me compile! +// Execute the command `rustlings hint variables1` if you want a hint :) + + +fn main() { + let x = 5; + println!("x has the value {}", x); +} diff --git a/I_have_done/variables/variables2.rs b/I_have_done/variables/variables2.rs new file mode 100644 index 00000000..be2ca14e --- /dev/null +++ b/I_have_done/variables/variables2.rs @@ -0,0 +1,12 @@ +// variables2.rs +// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) + + +fn main() { + let x = 10; + if x == 10 { + println!("Ten!"); + } else { + println!("Not ten!"); + } +} diff --git a/I_have_done/variables/variables3.rs b/I_have_done/variables/variables3.rs new file mode 100644 index 00000000..3566ef22 --- /dev/null +++ b/I_have_done/variables/variables3.rs @@ -0,0 +1,10 @@ +// variables3.rs +// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) + + +fn main() { + let mut x = 3; + println!("Number {}", x); + x = 5; // don't change this line + println!("Number {}", x); +} diff --git a/I_have_done/variables/variables4.rs b/I_have_done/variables/variables4.rs new file mode 100644 index 00000000..ee24119e --- /dev/null +++ b/I_have_done/variables/variables4.rs @@ -0,0 +1,8 @@ +// variables4.rs +// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) + + +fn main() { + let x: i32 = 100; + println!("Number {}", x); +} diff --git a/I_have_done/variables/variables5.rs b/I_have_done/variables/variables5.rs new file mode 100644 index 00000000..b1aa6909 --- /dev/null +++ b/I_have_done/variables/variables5.rs @@ -0,0 +1,10 @@ +// variables5.rs +// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) + + +fn main() { + let number = "T-H-R-E-E"; // don't change this line + println!("Spell a Number : {}", number); + let mut number = 3; + println!("Number plus two is : {}", number + 2); +} diff --git a/I_have_done/variables/variables6.rs b/I_have_done/variables/variables6.rs new file mode 100644 index 00000000..e2bc90f7 --- /dev/null +++ b/I_have_done/variables/variables6.rs @@ -0,0 +1,9 @@ +// variables6.rs +// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) + + +const NUMBER : i32 = 3; + +fn main() { + println!("Number {}", NUMBER); +} diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index d1af8311..7ef36fd0 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -2,9 +2,8 @@ // Make me compile! // Execute the command `rustlings hint variables1` if you want a hint :) -// I AM NOT DONE fn main() { - x = 5; + let x = 5; println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..be2ca14e 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,9 @@ // variables2.rs // Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) -// I AM NOT DONE fn main() { - let x; + let x = 10; if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 30ec48ff..3566ef22 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,10 +1,9 @@ // variables3.rs // Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) -// I AM NOT DONE fn main() { - let x = 3; + let mut x = 3; println!("Number {}", x); x = 5; // don't change this line println!("Number {}", x); diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..ee24119e 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,8 @@ // variables4.rs // Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) -// I AM NOT DONE fn main() { - let x: i32; + let x: i32 = 100; println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 175eebb3..b1aa6909 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,11 +1,10 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) -// I AM NOT DONE fn main() { let number = "T-H-R-E-E"; // don't change this line println!("Spell a Number : {}", number); - number = 3; + let mut number = 3; println!("Number plus two is : {}", number + 2); } diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 98666914..e2bc90f7 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,9 +1,9 @@ // variables6.rs // Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) -// I AM NOT DONE -const NUMBER = 3; +const NUMBER : i32 = 3; + fn main() { println!("Number {}", NUMBER); }