mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 09:19:18 +00:00
commit
9e81d06e8a
@ -1,8 +1,10 @@
|
|||||||
// functions1.rs
|
// functions1.rs
|
||||||
// Make me compile! Execute `rustlings hint functions1` for hints :)
|
// Make me compile! Execute `rustlings hint functions1` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me();
|
||||||
}
|
}
|
||||||
|
fn call_me(){
|
||||||
|
println!("do that is what you want?");
|
||||||
|
}
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
// functions2.rs
|
// functions2.rs
|
||||||
// Make me compile! Execute `rustlings hint functions2` for hints :)
|
// Make me compile! Execute `rustlings hint functions2` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me(3);
|
call_me(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num) {
|
fn call_me(num : i32) {
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
println!("Ring! Call number {}", i + 1);
|
println!("Ring! Call number {}", i + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
// functions3.rs
|
// functions3.rs
|
||||||
// Make me compile! Execute `rustlings hint functions3` for hints :)
|
// Make me compile! Execute `rustlings hint functions3` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num: i32) {
|
fn call_me(num: i32) {
|
||||||
|
|||||||
@ -4,18 +4,17 @@
|
|||||||
// This store is having a sale where if the price is an even number, you get
|
// This store is having a sale where if the price is an even number, you get
|
||||||
// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let original_price = 51;
|
let original_price = 1;
|
||||||
println!("Your sale price is {}", sale_price(original_price));
|
println!("Your sale price is {}", sale_price(original_price));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sale_price(price: i32) -> {
|
fn sale_price(price: i32) -> i32{
|
||||||
if is_even(price) {
|
if is_even(price) {
|
||||||
price - 10
|
price - 10 // no semicolon means a return value
|
||||||
} else {
|
} else {
|
||||||
price - 3
|
return price - 3; // java style is fine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
// functions5.rs
|
// functions5.rs
|
||||||
// Make me compile! Execute `rustlings hint functions5` for hints :)
|
// Make me compile! Execute `rustlings hint functions5` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let answer = square(3);
|
let answer = square(3);
|
||||||
@ -9,5 +8,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn square(num: i32) -> i32 {
|
fn square(num: i32) -> i32 {
|
||||||
num * num;
|
num * num // again semicolon should not be used in return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
// if1.rs
|
// if1.rs
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||||
// Complete this function to return the bigger number!
|
// Complete this function to return the bigger number!
|
||||||
@ -8,6 +7,7 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
|||||||
// - another function call
|
// - another function call
|
||||||
// - additional variables
|
// - additional variables
|
||||||
// Execute `rustlings hint if1` for hints
|
// Execute `rustlings hint if1` for hints
|
||||||
|
return if a > b {a} else {b}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't mind this for now :)
|
// Don't mind this for now :)
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||||
// the price of an order of apples given the order amount. No hints this time!
|
// the price of an order of apples given the order amount. No hints this time!
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
// Put your function here!
|
// Put your function here!
|
||||||
// fn ..... {
|
// fn ..... {
|
||||||
@ -21,3 +20,6 @@ fn verify_test() {
|
|||||||
assert_eq!(70, price1);
|
assert_eq!(70, price1);
|
||||||
assert_eq!(65, price2);
|
assert_eq!(65, price2);
|
||||||
}
|
}
|
||||||
|
fn calculate_apple_price(number : i32) -> i32{
|
||||||
|
if number > 40 {number * 1} else {number * 2}
|
||||||
|
}
|
||||||
|
|||||||
@ -6,9 +6,8 @@
|
|||||||
// even after you already figured it out. If you got everything working and
|
// 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.
|
// feel ready for the next exercise, remove the `I AM NOT DONE` comment below.
|
||||||
|
|
||||||
// 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,11 +1,10 @@
|
|||||||
// 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 x = 3;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
x = 5;
|
let x = 5; // shadowing
|
||||||
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 = 0;// initilization is mandatory for compiler
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
// 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 = "3";
|
let number = "3"; // shadowing can init val with diff type
|
||||||
println!("Number {}", number);
|
println!("Number {}", number);
|
||||||
number = 3;
|
let number = 3;
|
||||||
println!("Number {}", number);
|
println!("Number {}", number);
|
||||||
}
|
}
|
||||||
|
|||||||
0
temp_11118
Normal file
0
temp_11118
Normal file
BIN
temp_11118.2sdmqtm61l4rd3r2.rcgu.o
Normal file
BIN
temp_11118.2sdmqtm61l4rd3r2.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.0.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.0.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.1.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.1.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o
Normal file
Binary file not shown.
BIN
temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o
Normal file
BIN
temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.34m0fptr6ktrfuzi.rcgu.o
Normal file
BIN
temp_13591.34m0fptr6ktrfuzi.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.0.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.0.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.1.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.1.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.10.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.10.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.11.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.11.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.12.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.12.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.13.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.13.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.14.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.14.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.2.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.2.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.3.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.3.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.4.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.4.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.5.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.5.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.6.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.6.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.7.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.7.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.8.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.8.rcgu.o
Normal file
Binary file not shown.
BIN
temp_13591.functions2.7rcbfp3g-cgu.9.rcgu.o
Normal file
BIN
temp_13591.functions2.7rcbfp3g-cgu.9.rcgu.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user