Showing
9 changed files
with
156 additions
and
0 deletions
.gitignore
0 → 100644
1 | +**/.cargo/* |
guessing_game/.gitignore
0 → 100644
guessing_game/Cargo.lock
0 → 100644
1 | +# This file is automatically @generated by Cargo. | ||
2 | +# It is not intended for manual editing. | ||
3 | +[[package]] | ||
4 | +name = "fuchsia-cprng" | ||
5 | +version = "0.1.1" | ||
6 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
7 | + | ||
8 | +[[package]] | ||
9 | +name = "guessing_game" | ||
10 | +version = "0.1.0" | ||
11 | +dependencies = [ | ||
12 | + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", | ||
13 | +] | ||
14 | + | ||
15 | +[[package]] | ||
16 | +name = "libc" | ||
17 | +version = "0.2.65" | ||
18 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
19 | + | ||
20 | +[[package]] | ||
21 | +name = "rand" | ||
22 | +version = "0.3.23" | ||
23 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
24 | +dependencies = [ | ||
25 | + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", | ||
26 | + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
27 | +] | ||
28 | + | ||
29 | +[[package]] | ||
30 | +name = "rand" | ||
31 | +version = "0.4.6" | ||
32 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
33 | +dependencies = [ | ||
34 | + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
35 | + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", | ||
36 | + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
37 | + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
38 | + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
39 | +] | ||
40 | + | ||
41 | +[[package]] | ||
42 | +name = "rand_core" | ||
43 | +version = "0.3.1" | ||
44 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
45 | +dependencies = [ | ||
46 | + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
47 | +] | ||
48 | + | ||
49 | +[[package]] | ||
50 | +name = "rand_core" | ||
51 | +version = "0.4.2" | ||
52 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
53 | + | ||
54 | +[[package]] | ||
55 | +name = "rdrand" | ||
56 | +version = "0.4.0" | ||
57 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
58 | +dependencies = [ | ||
59 | + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
60 | +] | ||
61 | + | ||
62 | +[[package]] | ||
63 | +name = "winapi" | ||
64 | +version = "0.3.8" | ||
65 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
66 | +dependencies = [ | ||
67 | + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
68 | + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
69 | +] | ||
70 | + | ||
71 | +[[package]] | ||
72 | +name = "winapi-i686-pc-windows-gnu" | ||
73 | +version = "0.4.0" | ||
74 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
75 | + | ||
76 | +[[package]] | ||
77 | +name = "winapi-x86_64-pc-windows-gnu" | ||
78 | +version = "0.4.0" | ||
79 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
80 | + | ||
81 | +[metadata] | ||
82 | +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" | ||
83 | +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" | ||
84 | +"checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" | ||
85 | +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" | ||
86 | +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" | ||
87 | +"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" | ||
88 | +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" | ||
89 | +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" | ||
90 | +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
91 | +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
guessing_game/Cargo.toml
0 → 100644
guessing_game/src/main.rs
0 → 100644
1 | +use std::io; | ||
2 | +use std::cmp::Ordering; | ||
3 | +use rand::Rng; | ||
4 | + | ||
5 | +fn main() { | ||
6 | + println!("Guess the number!"); | ||
7 | + | ||
8 | + let secret_number = rand::thread_rng() | ||
9 | + .gen_range(1, 101); | ||
10 | + | ||
11 | + loop { | ||
12 | + println!("Please input your guess."); | ||
13 | + | ||
14 | + let mut guess = String::new(); | ||
15 | + | ||
16 | + io::stdin() | ||
17 | + .read_line(&mut guess) | ||
18 | + .expect("Failed to read line"); | ||
19 | + | ||
20 | + let guess: u32 = match guess.trim().parse() { | ||
21 | + Ok(num) => num, | ||
22 | + Err(_) => continue, | ||
23 | + }; | ||
24 | + | ||
25 | + println!("You guessed: {}", guess); | ||
26 | + | ||
27 | + match guess.cmp(&secret_number) { | ||
28 | + Ordering::Less => println!("Too small!"), | ||
29 | + Ordering::Greater => println!("Too big!"), | ||
30 | + Ordering::Equal => { | ||
31 | + println!("You win!"); | ||
32 | + break; | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | +} |
hello/.gitignore
0 → 100644
hello/Cargo.lock
0 → 100644
hello/Cargo.toml
0 → 100644
hello/src/main.rs
0 → 100644
Please
register
or
login
to post a comment