diff --git a/README.md b/README.md index d303083..10bb30a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 1. **安装Linux的环境**。对于windows的用户,推荐使用wsl2安装Ubuntu 22.04,也可以使用vmware等虚拟机进行安装。如果在这一步存在问题,请联系助教。 2. **创建ssh key,用于ssh方式克隆github代码**。在linux环境下,使用`ssh-keygen -t rsa -b 4096 -C "你的邮箱"`命令,创建ssh key,下面的选项全部直接敲回车即可。 随后使用` cat ~/.ssh/id_rsa.pub` 命令查看生成的公钥,并完整的复制下来。 在github仓库界面点击自己的头像,选择`settings`。进入到设置页面后,点击左侧的`SSH and GPG keys`选项。点击`New SSH key`选项,并将复制下来的内容粘贴上去,添加该ssh key的描述。随后点击`Add SSH key`,并一路点击确认即可。 3. **本地安装rust**。进入linux环境下,参考Arceos 教程 [Rust 开发环境配置 - ArceOS Tutorial Book (rcore-os.cn)](https://rcore-os.cn/arceos-tutorial-book/ch01-02.html) 中,找到Rust 开发环境配置的章节,相应配置即可,你可以同时将后续需要的环境也配置好. - 4. **clone实验仓库到本地。**在前面点击链接生成的仓库中,同样点击醒目的 `code` 绿色按钮,选择`local`下的`ssh`选项,复制下面的链接。随后回到本地linux环境下,使用`git clone 复制的链接`的方式,将目标仓库clone到本地。随后,使用`ls`命令查看自己clone下来的文件夹,再使用`cd`命令进入到该文件夹下,使用 `cargo install --force --path .` 安装rustlings。 + 4. **clone实验仓库到本地。** 在前面点击链接生成的仓库中,同样点击醒目的 `code` 绿色按钮,选择`local`下的`ssh`选项,复制下面的链接。随后回到本地linux环境下,使用`git clone 复制的链接`的方式,将目标仓库clone到本地。随后,使用`ls`命令查看自己clone下来的文件夹,再使用`cd`命令进入到该文件夹下,使用 `cargo install --force --path .` 安装rustlings。 5. **练习rustlings**。使用vscode等编辑器,进入clone下来的目录下的`exercises`文件夹,执行`rustlings watch`依次查看完成情况,并依次完成对应的练习。 执行`rustlings run 练习名称`去运行对应练习,也可以使用`rustlings hint 练习名称`查看题解。 6. **提交完成情况**。当做完部分或所有练习之后,在rustlings目录下执行 `git add .; git commit -m "update"; git push` 命令,把更新提交到GithubClassroom的CI进行自动评测。你可以在github仓库页面的actions页面,看到你的CI提交结果,或者 https://opencamp.ai/Rust/camp/S01/stage/0?tab=rank 上面查看自己的评分。 * 在线环境: diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 40ed9a0..770d4a9 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -2,8 +2,9 @@ // // Execute `rustlings hint functions1` or use the `hint` watch subcommand for a // hint. - -// I AM NOT DONE +fn call_me(){ + +} fn main() { call_me(); diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 5154f34..318f80d 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -3,13 +3,12 @@ // Execute `rustlings hint functions2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() { call_me(3); } -fn call_me(num:) { +fn call_me(num:i32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index 74f44d6..0a01731 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -3,10 +3,9 @@ // Execute `rustlings hint functions3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() { - call_me(); + call_me(3); } fn call_me(num: u32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 77c4b2a..96891ce 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -8,14 +8,13 @@ // Execute `rustlings hint functions4` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() { let original_price = 51; println!("Your sale price is {}", sale_price(original_price)); } -fn sale_price(price: i32) -> { +fn sale_price(price: i32) -> i32 { if is_even(price) { price - 10 } else { diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index f1b63f4..c51bea9 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -3,13 +3,11 @@ // Execute `rustlings hint functions5` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - fn main() { let answer = square(3); println!("The square of 3 is {}", answer); } fn square(num: i32) -> i32 { - num * num; + num * num } diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index d8108a0..a0285f1 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -2,13 +2,18 @@ // // Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! // Do not use: // - another function call // - additional variables + if a>=b{ + a + } + else{ + b + } } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index f512f13..2887762 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -5,13 +5,14 @@ // // Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn foo_if_fizz(fizzish: &str) -> &str { if fizzish == "fizz" { - "foo" - } else { - 1 + return "foo"; + } + if fizzish == "fuzz" { + return "bar"; + }else{ + return "baz"; } } diff --git a/exercises/if/if3.rs b/exercises/if/if3.rs index 73a7025..d81f7bb 100644 --- a/exercises/if/if3.rs +++ b/exercises/if/if3.rs @@ -2,17 +2,16 @@ // // Execute `rustlings hint if3` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE pub fn animal_habitat(animal: &str) -> &'static str { let identifier = if animal == "crab" { 1 } else if animal == "gopher" { - 2.0 + 2 } else if animal == "snake" { 3 } else { - "Unknown" + 4 }; // DO NOT CHANGE THIS STATEMENT BELOW diff --git a/exercises/intro/intro2.rs b/exercises/intro/intro2.rs index 990b20f..6c3f638 100644 --- a/exercises/intro/intro2.rs +++ b/exercises/intro/intro2.rs @@ -5,8 +5,7 @@ // Execute `rustlings hint intro2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() { - println!("Hello {}!"); + println!("Hello world!"); } diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index a9904b8..5980acc 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -13,10 +13,16 @@ // // No hints this time ;) -// I AM NOT DONE // Put your function here! -// fn calculate_price_of_apples { +fn calculate_price_of_apples(num:i32) -> i32 { + if num > 40{ + num + }else{ + num*2 + } + +} // Don't modify this function! #[test] diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index b3e089a..469fd4e 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -5,9 +5,8 @@ // Execute `rustlings hint variables1` or use the `hint` watch subcommand for 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 e1c23ed..59f9a02 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -3,10 +3,8 @@ // Execute `rustlings hint variables2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - fn main() { - let x; + let x = 10; if x == 10 { println!("x is ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 86bed41..c40cf3a 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -3,9 +3,8 @@ // Execute `rustlings hint variables3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() { - let x: i32; + let x: i32 = 1; println!("Number {}", x); } diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 5394f39..2d056da 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -3,10 +3,9 @@ // Execute `rustlings hint variables4` or use the `hint` watch subcommand for 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/variables5.rs b/exercises/variables/variables5.rs index a29b38b..19ce9d6 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -3,11 +3,9 @@ // Execute `rustlings hint variables5` or use the `hint` watch subcommand for 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; // don't rename this variable + let number = 3; // don't rename this variable println!("Number plus two is : {}", number + 2); } diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 853183b..53ebf53 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -3,9 +3,8 @@ // Execute `rustlings hint variables6` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE -const NUMBER = 3; +const NUMBER:i32 = 3; fn main() { println!("Number {}", NUMBER); }