diff --git a/Cargo.toml b/Cargo.toml index 0053bbe..df713e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +reqwest = {version = "0.11.10", features = ["blocking"]} \ No newline at end of file diff --git a/src/bin/04-linkedlist.rs b/src/bin/04-linkedlist.rs index e69de29..50029fa 100644 --- a/src/bin/04-linkedlist.rs +++ b/src/bin/04-linkedlist.rs @@ -0,0 +1,36 @@ +use std::collections::HashSet; + + +const REQUEST_URL: &str = "http://www.pythonchallenge.com/pc/def/linkedlist.php"; + + +fn get_next_nothing(current_nothing: String) -> Result +{ + let client = reqwest::blocking::Client::new(); + let resp = client.get(REQUEST_URL) + .query(&[("nothing", current_nothing)]) + .send()?; + + let body = resp.text()?; + let nothing = body.split_ascii_whitespace().last().unwrap(); + Ok(nothing.to_string()) + +} + +fn main() -> Result<(), reqwest::Error> { + + let mut nothings= HashSet::new(); + let mut current_nothing = String::from("12345"); + + + while !nothings.contains(¤t_nothing) + { + nothings.insert(current_nothing.clone()); + current_nothing = get_next_nothing(current_nothing)?; + println!("Next nothing is: {}",current_nothing); + + } + + println!("{:?}", nothings); + Ok(()) +} \ No newline at end of file