Skip to content

Commit

Permalink
add exercise-{solutions|templates}/iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelraz committed Jan 14, 2025
1 parent cadae3e commit 8380e40
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exercise-solutions/iterators/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "iterators"
version = "0.1.0"
edition = "2021"

[dependencies]
11 changes: 11 additions & 0 deletions exercise-solutions/iterators/numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//ignore everything that is not a number
1
2
3
4
five
6
7
9
X
15 changes: 15 additions & 0 deletions exercise-solutions/iterators/src/bin/iters1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![allow(unused_imports)]
use std::io::{BufReader};
use std::fs::File;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
use crate::*;
let f = File::open("numbers.txt")?;
let mut reader = BufReader::new(f);
let sum_of_odd_numbers: i32 = todo!("use reader.lines() and Iterator methods");

assert_eq!(sum_of_odd_numbers, 20);
Ok(())
}

6 changes: 6 additions & 0 deletions exercise-templates/iterators/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "iterators"
version = "0.1.0"
edition = "2021"

[dependencies]
11 changes: 11 additions & 0 deletions exercise-templates/iterators/numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//ignore everything that is not a number
1
2
3
4
five
6
7
9
X
18 changes: 18 additions & 0 deletions exercise-templates/iterators/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![allow(unused_imports)]
use std::io::BufReader;
use std::fs::File;
use std::error::Error;

#[test]
fn iterator_test() -> Result<(), Box<dyn Error>> {
use crate::*;
let f = File::open("numbers.txt")?;
let mut reader = BufReader::new(f);

// Write your iterator chain here
let sum_of_odd_numbers: i32 = todo!("use reader.lines() and Iterator methods");

assert_eq!(sum_of_odd_numbers, 20);
Ok(())
}

0 comments on commit 8380e40

Please sign in to comment.