mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 05:39:19 +00:00
day one
This commit is contained in:
parent
5336805b74
commit
761945c40c
8
I_have_done/intro/README.md
Normal file
8
I_have_done/intro/README.md
Normal file
@ -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)
|
||||||
21
I_have_done/intro/intro1.rs
Normal file
21
I_have_done/intro/intro1.rs
Normal file
@ -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!");
|
||||||
|
}
|
||||||
7
I_have_done/intro/intro2.rs
Normal file
7
I_have_done/intro/intro2.rs
Normal file
@ -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!");
|
||||||
|
}
|
||||||
2
I_have_done/intro/mod.rs
Normal file
2
I_have_done/intro/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mod intro1;
|
||||||
|
mod intro2;
|
||||||
9
I_have_done/variables/README.md
Normal file
9
I_have_done/variables/README.md
Normal file
@ -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)
|
||||||
6
I_have_done/variables/mod.rs
Normal file
6
I_have_done/variables/mod.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
mod variables1;
|
||||||
|
mod variables2;
|
||||||
|
mod variables3;
|
||||||
|
mod variables4;
|
||||||
|
mod variables5;
|
||||||
|
mod variables6;
|
||||||
9
I_have_done/variables/variables1.rs
Normal file
9
I_have_done/variables/variables1.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
12
I_have_done/variables/variables2.rs
Normal file
12
I_have_done/variables/variables2.rs
Normal file
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
10
I_have_done/variables/variables3.rs
Normal file
10
I_have_done/variables/variables3.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
8
I_have_done/variables/variables4.rs
Normal file
8
I_have_done/variables/variables4.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
10
I_have_done/variables/variables5.rs
Normal file
10
I_have_done/variables/variables5.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
9
I_have_done/variables/variables6.rs
Normal file
9
I_have_done/variables/variables6.rs
Normal file
@ -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);
|
||||||
|
}
|
||||||
@ -2,9 +2,8 @@
|
|||||||
// Make me compile!
|
// Make me compile!
|
||||||
// Execute the command `rustlings hint variables1` if you want a hint :)
|
// Execute the command `rustlings hint variables1` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
x = 5;
|
let x = 5;
|
||||||
println!("x has the value {}", x);
|
println!("x has the value {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
// variables2.rs
|
// variables2.rs
|
||||||
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
|
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x;
|
let x = 10;
|
||||||
if x == 10 {
|
if x == 10 {
|
||||||
println!("Ten!");
|
println!("Ten!");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
// variables3.rs
|
// variables3.rs
|
||||||
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
|
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 3;
|
let mut x = 3;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
x = 5; // don't change this line
|
x = 5; // don't change this line
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
// variables4.rs
|
// variables4.rs
|
||||||
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
|
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: i32;
|
let x: i32 = 100;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
// variables5.rs
|
// variables5.rs
|
||||||
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
|
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let number = "T-H-R-E-E"; // don't change this line
|
let number = "T-H-R-E-E"; // don't change this line
|
||||||
println!("Spell a Number : {}", number);
|
println!("Spell a Number : {}", number);
|
||||||
number = 3;
|
let mut number = 3;
|
||||||
println!("Number plus two is : {}", number + 2);
|
println!("Number plus two is : {}", number + 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
// variables6.rs
|
// variables6.rs
|
||||||
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
|
// 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() {
|
fn main() {
|
||||||
println!("Number {}", NUMBER);
|
println!("Number {}", NUMBER);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user