I have setup the docker container to run the model evaluation.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Here's a self-contained Rust program that meets your requirements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let num_lines = lines.len(); let num_threads = 4; let chunk_size = (num_lines + num_threads - 1) / num_threads; let shared_map: Arc<Mutex<HashMap<String, usize>>> = Arc::new(Mutex::new(HashMap::new())); let mut threads = Vec::new(); for chunk in lines.chunks(chunk_size) { let map = Arc::clone(&shared_map); let thread = thread::spawn(move || { let mut local_map = HashMap::new(); for line in chunk { let words: Vec<_> = line.split_whitespace().map(str::to_string).collect(); for word in words { *local_map.entry(word).or_insert(0) += 1; } } let mut shared_map = map.lock().unwrap(); for (word, count) in local_map.drain() { *shared_map.entry(word).or_insert(0) += count; } }); threads.push(thread); } for thread in threads { thread.join().unwrap(); } let shared_map = shared_map.lock().unwrap(); for (word, count) in &*shared_map { println!("{{"{}": {}}}", word, count); } } |
1 2 | rustc word_count.rs ./word_count |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let num_lines = lines.len(); let num_threads = 4; let chunk_size = (num_lines + num_threads - 1) / num_threads; let shared_map: Arc<Mutex<HashMap<String, usize>>> = Arc::new(Mutex::new(HashMap::new())); let mut threads = Vec::new(); for chunk in lines.chunks(chunk_size) { let map = Arc::clone(&shared_map); let thread = thread::spawn(move || { let mut local_map = HashMap::new(); for line in chunk { let words: Vec<_> = line.split_whitespace().map(str::to_string).collect(); for word in words { *local_map.entry(word).or_insert(0) += 1; } } let mut shared_map = map.lock().unwrap(); for (word, count) in local_map.drain() { *shared_map.entry(word).or_insert(0) += count; } }); threads.push(thread); } for thread in threads { thread.join().unwrap(); } let shared_map = shared_map.lock().unwrap(); for (word, count) in &*shared_map { println!("{{"{}": {}}}", word, count); } } |
Below is some student's code. I asked them to parallelize some code. Do not judge if it is correct, I have test cases for that. Logic errors are okay. So are synatx errors. Just tell me if they tried to parallelize it. use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let num_lines = lines.len(); let num_threads = 4; let chunk_size = (num_lines + num_threads - 1) / num_threads; let shared_map: Arc<Mutex<HashMap<String, usize>>> = Arc::new(Mutex::new(HashMap::new())); let mut threads = Vec::new(); for chunk in lines.chunks(chunk_size) { let map = Arc::clone(&shared_map); let thread = thread::spawn(move || { let mut local_map = HashMap::new(); for line in chunk { let words: Vec<_> = line.split_whitespace().map(str::to_string).collect(); for word in words { *local_map.entry(word).or_insert(0) += 1; } } let mut shared_map = map.lock().unwrap(); for (word, count) in local_map.drain() { *shared_map.entry(word).or_insert(0) += count; } }); threads.push(thread); } for thread in threads { thread.join().unwrap(); } let shared_map = shared_map.lock().unwrap(); for (word, count) in &*shared_map { println!("{{"{}": {}}}", word, count); } } Answer either 'The student passes' or 'The student fails'.
The student passes.
Testing if the previous output contains the string student passes
: True
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let num_lines = lines.len(); let num_threads = 4; let chunk_size = (num_lines + num_threads - 1) / num_threads; let shared_map: Arc<Mutex<HashMap<String, usize>>> = Arc::new(Mutex::new(HashMap::new())); let mut threads = Vec::new(); for chunk in lines.chunks(chunk_size) { let map = Arc::clone(&shared_map); let thread = thread::spawn(move || { let mut local_map = HashMap::new(); for line in chunk { let words: Vec<_> = line.split_whitespace().map(str::to_string).collect(); for word in words { *local_map.entry(word).or_insert(0) += 1; } } let mut shared_map = map.lock().unwrap(); for (word, count) in local_map.drain() { *shared_map.entry(word).or_insert(0) += count; } }); threads.push(thread); } for thread in threads { thread.join().unwrap(); } let shared_map = shared_map.lock().unwrap(); for (word, count) in &*shared_map { println!("{{"{}": {}}}", word, count); } } |
error: expected `,`, found `{`
--> main.rs:47:22
|
47 | println!("{{"{}": {}}}", word, count);
| ^ expected `,`
warning: unused import: `std::env`
--> main.rs:3:5
|
3 | use std::env;
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error: aborting due to 1 previous error; 1 warning emitted
main.sh: line 2: ./a.out: No such file or directory
Resulting in output: []
Testing if the previous output equals the string [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
: False
I have setup the docker container to run the model evaluation.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Here's a self-contained Rust program that meets your requirements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut handles = Vec::new(); let mut word_counts = Vec::new(); for i in 0..num_threads { let chunk = Arc::new(lines[i * chunk_size..(i + 1) * chunk_size].to_vec()); let word_count = Arc::new(Mutex::new(HashMap::new())); let word_count_clone = Arc::clone(&word_count); let handle = thread::spawn(move || { let mut local_word_count = HashMap::new(); for line in chunk.iter() { for word in line.split_whitespace() { *local_word_count.entry(word.to_string()).or_insert(0) += 1; } } let mut word_count = word_count_clone.lock().unwrap(); for (word, count) in local_word_count { *word_count.entry(word).or_insert(0) += count; } }); handles.push(handle); word_counts.push(word_count); } for handle in handles { handle.join().unwrap(); } for word_count in word_counts { let mut sorted_word_count: Vec<_> = word_count.lock().unwrap().iter().collect(); sorted_word_count.sort_by(|a, b| a.0.cmp(b.0)); let mut json_output = String::from("{"); for (i, (word, count)) in sorted_word_count.iter().enumerate() { if i > 0 { json_output.push_str(", "); } json_output.push_str(&format!("\"{}\": {}", word, count)); } json_output.push_str("}"); println!("{}", json_output); } } |
1 2 | rustc word_count.rs ./word_count |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut handles = Vec::new(); let mut word_counts = Vec::new(); for i in 0..num_threads { let chunk = Arc::new(lines[i * chunk_size..(i + 1) * chunk_size].to_vec()); let word_count = Arc::new(Mutex::new(HashMap::new())); let word_count_clone = Arc::clone(&word_count); let handle = thread::spawn(move || { let mut local_word_count = HashMap::new(); for line in chunk.iter() { for word in line.split_whitespace() { *local_word_count.entry(word.to_string()).or_insert(0) += 1; } } let mut word_count = word_count_clone.lock().unwrap(); for (word, count) in local_word_count { *word_count.entry(word).or_insert(0) += count; } }); handles.push(handle); word_counts.push(word_count); } for handle in handles { handle.join().unwrap(); } for word_count in word_counts { let mut sorted_word_count: Vec<_> = word_count.lock().unwrap().iter().collect(); sorted_word_count.sort_by(|a, b| a.0.cmp(b.0)); let mut json_output = String::from("{"); for (i, (word, count)) in sorted_word_count.iter().enumerate() { if i > 0 { json_output.push_str(", "); } json_output.push_str(&format!("\"{}\": {}", word, count)); } json_output.push_str("}"); println!("{}", json_output); } } |
Below is some student's code. I asked them to parallelize some code. Do not judge if it is correct, I have test cases for that. Logic errors are okay. So are synatx errors. Just tell me if they tried to parallelize it. use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut handles = Vec::new(); let mut word_counts = Vec::new(); for i in 0..num_threads { let chunk = Arc::new(lines[i * chunk_size..(i + 1) * chunk_size].to_vec()); let word_count = Arc::new(Mutex::new(HashMap::new())); let word_count_clone = Arc::clone(&word_count); let handle = thread::spawn(move || { let mut local_word_count = HashMap::new(); for line in chunk.iter() { for word in line.split_whitespace() { *local_word_count.entry(word.to_string()).or_insert(0) += 1; } } let mut word_count = word_count_clone.lock().unwrap(); for (word, count) in local_word_count { *word_count.entry(word).or_insert(0) += count; } }); handles.push(handle); word_counts.push(word_count); } for handle in handles { handle.join().unwrap(); } for word_count in word_counts { let mut sorted_word_count: Vec<_> = word_count.lock().unwrap().iter().collect(); sorted_word_count.sort_by(|a, b| a.0.cmp(b.0)); let mut json_output = String::from("{"); for (i, (word, count)) in sorted_word_count.iter().enumerate() { if i > 0 { json_output.push_str(", "); } json_output.push_str(&format!("\"{}\": {}", word, count)); } json_output.push_str("}"); println!("{}", json_output); } } Answer either 'The student passes' or 'The student fails'.
The student passes.
Testing if the previous output contains the string student passes
: True
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut handles = Vec::new(); let mut word_counts = Vec::new(); for i in 0..num_threads { let chunk = Arc::new(lines[i * chunk_size..(i + 1) * chunk_size].to_vec()); let word_count = Arc::new(Mutex::new(HashMap::new())); let word_count_clone = Arc::clone(&word_count); let handle = thread::spawn(move || { let mut local_word_count = HashMap::new(); for line in chunk.iter() { for word in line.split_whitespace() { *local_word_count.entry(word.to_string()).or_insert(0) += 1; } } let mut word_count = word_count_clone.lock().unwrap(); for (word, count) in local_word_count { *word_count.entry(word).or_insert(0) += count; } }); handles.push(handle); word_counts.push(word_count); } for handle in handles { handle.join().unwrap(); } for word_count in word_counts { let mut sorted_word_count: Vec<_> = word_count.lock().unwrap().iter().collect(); sorted_word_count.sort_by(|a, b| a.0.cmp(b.0)); let mut json_output = String::from("{"); for (i, (word, count)) in sorted_word_count.iter().enumerate() { if i > 0 { json_output.push_str(", "); } json_output.push_str(&format!("\"{}\": {}", word, count)); } json_output.push_str("}"); println!("{}", json_output); } } |
warning: unused import: `std::env`
--> main.rs:3:5
|
3 | use std::env;
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0716]: temporary value dropped while borrowed
--> main.rs:51:45
|
51 | let mut sorted_word_count: Vec<_> = word_count.lock().unwrap().iter().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
52 | sorted_word_count.sort_by(|a, b| a.0.cmp(b.0));
| ----------------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0716`.
main.sh: line 2: ./a.out: No such file or directory
Resulting in output: []
Testing if the previous output equals the string [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
: False
I have setup the docker container to run the model evaluation.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Here's a self-contained Rust program that meets your requirements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | use std::env; use std::fs::File; use std::io::{BufReader, BufRead}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let args: Vec<String> = env::args().collect(); let file_path = if args.len() > 1 { &args[1] } else { "/tmp/file.txt" }; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let mut handles = Vec::new(); let line_counts: Arc<Mutex<Vec<HashMap<String, u32>>>> = Arc::new(Mutex::new(vec![HashMap::new(); 4])); let chunk_size = reader.lines().count() / 4; for i in 0..4 { let line_counts = Arc::clone(&line_counts); let handle = thread::spawn(move || { let mut word_count: HashMap<String, u32> = HashMap::new(); let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size); for line in lines { if let Ok(line) = line { for word in line.split_whitespace() { *word_count.entry(word.to_string()).or_insert(0) += 1; } } } line_counts.lock().unwrap()[i] = word_count; }); handles.push(handle); } for handle in handles { handle.join().unwrap(); } for word_count in line_counts.lock().unwrap().iter() { let json = word_count.iter() .map(|(k, v)| format!("\"{}\": {}", k, v)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json); } } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | use std::env; use std::fs::File; use std::io::{BufReader, BufRead}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let args: Vec<String> = env::args().collect(); let file_path = if args.len() > 1 { &args[1] } else { "/tmp/file.txt" }; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let mut handles = Vec::new(); let line_counts: Arc<Mutex<Vec<HashMap<String, u32>>>> = Arc::new(Mutex::new(vec![HashMap::new(); 4])); let chunk_size = reader.lines().count() / 4; for i in 0..4 { let line_counts = Arc::clone(&line_counts); let handle = thread::spawn(move || { let mut word_count: HashMap<String, u32> = HashMap::new(); let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size); for line in lines { if let Ok(line) = line { for word in line.split_whitespace() { *word_count.entry(word.to_string()).or_insert(0) += 1; } } } line_counts.lock().unwrap()[i] = word_count; }); handles.push(handle); } for handle in handles { handle.join().unwrap(); } for word_count in line_counts.lock().unwrap().iter() { let json = word_count.iter() .map(|(k, v)| format!("\"{}\": {}", k, v)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json); } } |
Below is some student's code. I asked them to parallelize some code. Do not judge if it is correct, I have test cases for that. Logic errors are okay. So are synatx errors. Just tell me if they tried to parallelize it. use std::env; use std::fs::File; use std::io::{BufReader, BufRead}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let args: Vec<String> = env::args().collect(); let file_path = if args.len() > 1 { &args[1] } else { "/tmp/file.txt" }; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let mut handles = Vec::new(); let line_counts: Arc<Mutex<Vec<HashMap<String, u32>>>> = Arc::new(Mutex::new(vec![HashMap::new(); 4])); let chunk_size = reader.lines().count() / 4; for i in 0..4 { let line_counts = Arc::clone(&line_counts); let handle = thread::spawn(move || { let mut word_count: HashMap<String, u32> = HashMap::new(); let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size); for line in lines { if let Ok(line) = line { for word in line.split_whitespace() { *word_count.entry(word.to_string()).or_insert(0) += 1; } } } line_counts.lock().unwrap()[i] = word_count; }); handles.push(handle); } for handle in handles { handle.join().unwrap(); } for word_count in line_counts.lock().unwrap().iter() { let json = word_count.iter() .map(|(k, v)| format!("\"{}\": {}", k, v)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json); } } Answer either 'The student passes' or 'The student fails'.
The student passes.
Testing if the previous output contains the string student passes
: True
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | use std::env; use std::fs::File; use std::io::{BufReader, BufRead}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread; fn main() { let args: Vec<String> = env::args().collect(); let file_path = if args.len() > 1 { &args[1] } else { "/tmp/file.txt" }; let file = File::open(file_path).expect("Failed to open file"); let reader = BufReader::new(file); let mut handles = Vec::new(); let line_counts: Arc<Mutex<Vec<HashMap<String, u32>>>> = Arc::new(Mutex::new(vec![HashMap::new(); 4])); let chunk_size = reader.lines().count() / 4; for i in 0..4 { let line_counts = Arc::clone(&line_counts); let handle = thread::spawn(move || { let mut word_count: HashMap<String, u32> = HashMap::new(); let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size); for line in lines { if let Ok(line) = line { for word in line.split_whitespace() { *word_count.entry(word.to_string()).or_insert(0) += 1; } } } line_counts.lock().unwrap()[i] = word_count; }); handles.push(handle); } for handle in handles { handle.join().unwrap(); } for word_count in line_counts.lock().unwrap().iter() { let json = word_count.iter() .map(|(k, v)| format!("\"{}\": {}", k, v)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json); } } |
warning: variable does not need to be mutable
--> main.rs:25:17
|
25 | let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size);
| ----^^^^^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` on by default
error[E0382]: use of moved value: `reader`
--> main.rs:23:36
|
14 | let reader = BufReader::new(file);
| ------ move occurs because `reader` has type `BufReader<File>`, which does not implement the `Copy` trait
...
19 | let chunk_size = reader.lines().count() / 4;
| ------- `reader` moved due to this method call
...
23 | let handle = thread::spawn(move || {
| ^^^^^^^ value used here after move
24 | let mut word_count: HashMap<String, u32> = HashMap::new();
25 | let mut lines = reader.lines().skip(i * chunk_size).take(chunk_size);
| ------ use occurs due to use in closure
|
note: `lines` takes ownership of the receiver `self`, which moves `reader`
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/io/mod.rs:2521:14
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0382`.
main.sh: line 2: ./a.out: No such file or directory
Resulting in output: []
Testing if the previous output equals the string [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
: False
I have setup the docker container to run the model evaluation.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Here's a self-contained Rust program that reads the contents of the file `/tmp/file.txt`, counts the occurrences of each word, and prints the results as JSON to stdout. It uses Rust's built-in support for parallelism to process the file on 4 cores simultaneously.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; // Read the file contents into a vector of strings let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<String> = reader.lines().map(|line| line.unwrap()).collect(); // Split the lines into chunks for parallel processing let chunk_size = (lines.len() + num_threads - 1) / num_threads; let line_chunks: Vec<_> = lines.chunks(chunk_size).collect(); // Create a vector to store the word counts from each thread let mut word_counts: Vec<HashMap<String, usize>> = Vec::with_capacity(num_threads); // Spawn threads to process each chunk of lines let handles: Vec<_> = line_chunks .into_iter() .map(|chunk| { let chunk: Vec<String> = chunk.iter().cloned().collect(); thread::spawn(move || count_words(chunk)) }) .collect(); // Wait for threads to finish and collect their word counts for handle in handles { word_counts.push(handle.join().unwrap()); } // Print the word counts as JSON to stdout for word_count in word_counts { let json_output = word_count .into_iter() .map(|(word, count)| format!("\"{}\": {}", word, count)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json_output); } } fn count_words(lines: Vec<String>) -> HashMap<String, usize> { let mut word_count: HashMap<String, usize> = HashMap::new(); for line in lines { for word in line.split_whitespace() { let word = word.to_string(); *word_count.entry(word).or_insert(0) += 1; } } word_count } |
1 2 3 4 | {"This": 1} {"is": 2, "is,": 1} {"an": 1} {"example": 1} |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; // Read the file contents into a vector of strings let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<String> = reader.lines().map(|line| line.unwrap()).collect(); // Split the lines into chunks for parallel processing let chunk_size = (lines.len() + num_threads - 1) / num_threads; let line_chunks: Vec<_> = lines.chunks(chunk_size).collect(); // Create a vector to store the word counts from each thread let mut word_counts: Vec<HashMap<String, usize>> = Vec::with_capacity(num_threads); // Spawn threads to process each chunk of lines let handles: Vec<_> = line_chunks .into_iter() .map(|chunk| { let chunk: Vec<String> = chunk.iter().cloned().collect(); thread::spawn(move || count_words(chunk)) }) .collect(); // Wait for threads to finish and collect their word counts for handle in handles { word_counts.push(handle.join().unwrap()); } // Print the word counts as JSON to stdout for word_count in word_counts { let json_output = word_count .into_iter() .map(|(word, count)| format!("\"{}\": {}", word, count)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json_output); } } fn count_words(lines: Vec<String>) -> HashMap<String, usize> { let mut word_count: HashMap<String, usize> = HashMap::new(); for line in lines { for word in line.split_whitespace() { let word = word.to_string(); *word_count.entry(word).or_insert(0) += 1; } } word_count } |
Below is some student's code. I asked them to parallelize some code. Do not judge if it is correct, I have test cases for that. Logic errors are okay. So are synatx errors. Just tell me if they tried to parallelize it. use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; // Read the file contents into a vector of strings let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<String> = reader.lines().map(|line| line.unwrap()).collect(); // Split the lines into chunks for parallel processing let chunk_size = (lines.len() + num_threads - 1) / num_threads; let line_chunks: Vec<_> = lines.chunks(chunk_size).collect(); // Create a vector to store the word counts from each thread let mut word_counts: Vec<HashMap<String, usize>> = Vec::with_capacity(num_threads); // Spawn threads to process each chunk of lines let handles: Vec<_> = line_chunks .into_iter() .map(|chunk| { let chunk: Vec<String> = chunk.iter().cloned().collect(); thread::spawn(move || count_words(chunk)) }) .collect(); // Wait for threads to finish and collect their word counts for handle in handles { word_counts.push(handle.join().unwrap()); } // Print the word counts as JSON to stdout for word_count in word_counts { let json_output = word_count .into_iter() .map(|(word, count)| format!("\"{}\": {}", word, count)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json_output); } } fn count_words(lines: Vec<String>) -> HashMap<String, usize> { let mut word_count: HashMap<String, usize> = HashMap::new(); for line in lines { for word in line.split_whitespace() { let word = word.to_string(); *word_count.entry(word).or_insert(0) += 1; } } word_count } Answer either 'The student passes' or 'The student fails'.
The student passes.
Testing if the previous output contains the string student passes
: True
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; // Read the file contents into a vector of strings let file = File::open(file_path).unwrap(); let reader = BufReader::new(file); let lines: Vec<String> = reader.lines().map(|line| line.unwrap()).collect(); // Split the lines into chunks for parallel processing let chunk_size = (lines.len() + num_threads - 1) / num_threads; let line_chunks: Vec<_> = lines.chunks(chunk_size).collect(); // Create a vector to store the word counts from each thread let mut word_counts: Vec<HashMap<String, usize>> = Vec::with_capacity(num_threads); // Spawn threads to process each chunk of lines let handles: Vec<_> = line_chunks .into_iter() .map(|chunk| { let chunk: Vec<String> = chunk.iter().cloned().collect(); thread::spawn(move || count_words(chunk)) }) .collect(); // Wait for threads to finish and collect their word counts for handle in handles { word_counts.push(handle.join().unwrap()); } // Print the word counts as JSON to stdout for word_count in word_counts { let json_output = word_count .into_iter() .map(|(word, count)| format!("\"{}\": {}", word, count)) .collect::<Vec<_>>() .join(", "); println!("{{{}}}", json_output); } } fn count_words(lines: Vec<String>) -> HashMap<String, usize> { let mut word_count: HashMap<String, usize> = HashMap::new(); for line in lines { for word in line.split_whitespace() { let word = word.to_string(); *word_count.entry(word).or_insert(0) += 1; } } word_count } |
{"Heaven,": 1, "us,": 2, "season": 2, "best": 1, "times,": 2, "worst": 1, "belief,": 1, "hope,": 1, "to": 1, "going": 2, "all": 2, "incredulity,": 1, "wisdom,": 1, "the": 11, "direct": 2, "other": 1, "way": 1, "before": 2, "winter": 1, "were": 2, "despair,": 1, "it": 10, "Light,": 1, "had": 2, "was": 10, "epoch": 2, "foolishness,": 1, "everything": 1, "of": 10, "nothing": 1, "Darkness,": 1, "we": 4, "spring": 1, "age": 2}
warning: unused import: `std::env`
--> main.rs:3:5
|
3 | use std::env;
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: 1 warning emitted
Resulting in output: [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
Testing if the previous output equals the string [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
: True
I have setup the docker container to run the model evaluation.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Write a self-contained Rust program that prints a JSON output of how often each word appears in a text file located in /tmp/file.txt. So if the file contains "This is is is, an example" then the program should print to stdout. {"This": 1, "is": 2, "is,": 1, "an": 1, "example": 1} Don't import any crates that would require a Cargo.toml file. I'll just compile it with `rustc yourfile.rs` and it should work. The program should be run by calling /path/to/rust_word_count with no arguments. Make it run in parallel on 4 cores at the same time, each job taking ~1/4 of the file. Print out 4 differnt json dicts, one per line. I'll do the merging.
Here's a self-contained Rust program that reads the file `/tmp/file.txt`, counts the occurrences of each word, and prints four separate JSON dictionaries to stdout, one per line. The program uses Rust's built-in threads to run in parallel on four cores, with each thread processing approximately one-fourth of the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Barrier, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let barrier = Arc::new(Barrier::new(num_threads)); let file = match File::open(file_path) { Ok(file) => file, Err(e) => { eprintln!("Error opening file: {}", e); return; } }; let reader = BufReader::new(file); let mut lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut thread_word_counts: Vec<_> = (0..num_threads) .map(|_| { let barrier = Arc::clone(&barrier); let word_count = Mutex::new(HashMap::new()); (barrier, word_count) }) .collect(); for (i, (barrier, word_count)) in thread_word_counts.iter().enumerate() { let start = i * chunk_size; let end = if i == num_threads - 1 { lines.len() } else { (i + 1) * chunk_size }; let thread_lines = lines[start..end].to_vec(); let thread_barrier = barrier.clone(); let thread_word_count = word_count.clone(); thread::spawn(move || { count_words(&thread_lines, &thread_word_count); thread_barrier.wait(); print_word_count(&thread_word_count); }); } barrier.wait(); } fn count_words(lines: &[String], word_count: &Mutex<HashMap<String, usize>>) { for line in lines { let mut word_map = word_count.lock().unwrap(); for word in line.split_whitespace() { *word_map.entry(word.to_string()).or_insert(0) += 1; } } } fn print_word_count(word_count: &Mutex<HashMap<String, usize>>) { let word_map = word_count.lock().unwrap(); let json_str = serde_json::to_string(&*word_map).unwrap(); println!("{}", json_str); } |
1 | rustc word_count.rs && ./word_count |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Barrier, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let barrier = Arc::new(Barrier::new(num_threads)); let file = match File::open(file_path) { Ok(file) => file, Err(e) => { eprintln!("Error opening file: {}", e); return; } }; let reader = BufReader::new(file); let mut lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut thread_word_counts: Vec<_> = (0..num_threads) .map(|_| { let barrier = Arc::clone(&barrier); let word_count = Mutex::new(HashMap::new()); (barrier, word_count) }) .collect(); for (i, (barrier, word_count)) in thread_word_counts.iter().enumerate() { let start = i * chunk_size; let end = if i == num_threads - 1 { lines.len() } else { (i + 1) * chunk_size }; let thread_lines = lines[start..end].to_vec(); let thread_barrier = barrier.clone(); let thread_word_count = word_count.clone(); thread::spawn(move || { count_words(&thread_lines, &thread_word_count); thread_barrier.wait(); print_word_count(&thread_word_count); }); } barrier.wait(); } fn count_words(lines: &[String], word_count: &Mutex<HashMap<String, usize>>) { for line in lines { let mut word_map = word_count.lock().unwrap(); for word in line.split_whitespace() { *word_map.entry(word.to_string()).or_insert(0) += 1; } } } fn print_word_count(word_count: &Mutex<HashMap<String, usize>>) { let word_map = word_count.lock().unwrap(); let json_str = serde_json::to_string(&*word_map).unwrap(); println!("{}", json_str); } |
Below is some student's code. I asked them to parallelize some code. Do not judge if it is correct, I have test cases for that. Logic errors are okay. So are synatx errors. Just tell me if they tried to parallelize it. use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Barrier, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let barrier = Arc::new(Barrier::new(num_threads)); let file = match File::open(file_path) { Ok(file) => file, Err(e) => { eprintln!("Error opening file: {}", e); return; } }; let reader = BufReader::new(file); let mut lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut thread_word_counts: Vec<_> = (0..num_threads) .map(|_| { let barrier = Arc::clone(&barrier); let word_count = Mutex::new(HashMap::new()); (barrier, word_count) }) .collect(); for (i, (barrier, word_count)) in thread_word_counts.iter().enumerate() { let start = i * chunk_size; let end = if i == num_threads - 1 { lines.len() } else { (i + 1) * chunk_size }; let thread_lines = lines[start..end].to_vec(); let thread_barrier = barrier.clone(); let thread_word_count = word_count.clone(); thread::spawn(move || { count_words(&thread_lines, &thread_word_count); thread_barrier.wait(); print_word_count(&thread_word_count); }); } barrier.wait(); } fn count_words(lines: &[String], word_count: &Mutex<HashMap<String, usize>>) { for line in lines { let mut word_map = word_count.lock().unwrap(); for word in line.split_whitespace() { *word_map.entry(word.to_string()).or_insert(0) += 1; } } } fn print_word_count(word_count: &Mutex<HashMap<String, usize>>) { let word_map = word_count.lock().unwrap(); let json_str = serde_json::to_string(&*word_map).unwrap(); println!("{}", json_str); } Answer either 'The student passes' or 'The student fails'.
The student passes
Testing if the previous output contains the string student passes
: True
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | use std::collections::HashMap; use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::{Arc, Barrier, Mutex}; use std::thread; fn main() { let file_path = "/tmp/file.txt"; let num_threads = 4; let barrier = Arc::new(Barrier::new(num_threads)); let file = match File::open(file_path) { Ok(file) => file, Err(e) => { eprintln!("Error opening file: {}", e); return; } }; let reader = BufReader::new(file); let mut lines: Vec<_> = reader.lines().flatten().collect(); let chunk_size = lines.len() / num_threads; let mut thread_word_counts: Vec<_> = (0..num_threads) .map(|_| { let barrier = Arc::clone(&barrier); let word_count = Mutex::new(HashMap::new()); (barrier, word_count) }) .collect(); for (i, (barrier, word_count)) in thread_word_counts.iter().enumerate() { let start = i * chunk_size; let end = if i == num_threads - 1 { lines.len() } else { (i + 1) * chunk_size }; let thread_lines = lines[start..end].to_vec(); let thread_barrier = barrier.clone(); let thread_word_count = word_count.clone(); thread::spawn(move || { count_words(&thread_lines, &thread_word_count); thread_barrier.wait(); print_word_count(&thread_word_count); }); } barrier.wait(); } fn count_words(lines: &[String], word_count: &Mutex<HashMap<String, usize>>) { for line in lines { let mut word_map = word_count.lock().unwrap(); for word in line.split_whitespace() { *word_map.entry(word.to_string()).or_insert(0) += 1; } } } fn print_word_count(word_count: &Mutex<HashMap<String, usize>>) { let word_map = word_count.lock().unwrap(); let json_str = serde_json::to_string(&*word_map).unwrap(); println!("{}", json_str); } |
warning: unused import: `std::env`
--> main.rs:3:5
|
3 | use std::env;
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0433]: failed to resolve: use of undeclared crate or module `serde_json`
--> main.rs:68:20
|
68 | let json_str = serde_json::to_string(&*word_map).unwrap();
| ^^^^^^^^^^ use of undeclared crate or module `serde_json`
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0433`.
main.sh: line 2: ./a.out: No such file or directory
Resulting in output: []
Testing if the previous output equals the string [('Darkness,', 1), ('Heaven,', 1), ('Light,', 1), ('age', 2), ('all', 2), ('before', 2), ('belief,', 1), ('best', 1), ('despair,', 1), ('direct', 2), ('epoch', 2), ('everything', 1), ('foolishness,', 1), ('going', 2), ('had', 2), ('hope,', 1), ('incredulity,', 1), ('it', 10), ('nothing', 1), ('of', 10), ('other', 1), ('season', 2), ('spring', 1), ('the', 11), ('times,', 2), ('to', 1), ('us,', 2), ('was', 10), ('way', 1), ('we', 4), ('were', 2), ('winter', 1), ('wisdom,', 1), ('worst', 1)]
: False