Skip to content

Commit

Permalink
Finish day 1 for rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tjpalmer committed Dec 7, 2018
1 parent b03f58c commit 45e4d9f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/notes/
target/
3 changes: 0 additions & 3 deletions 2018/01/julia/repeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ function main()
while !done
for value in values
if total in prevs
# println(prevs)
println(total)
done = true
break
end
union!(prevs, [total])
total += value
# println(total)
# println(prevs)
end
# println("-")
end
Expand Down
4 changes: 4 additions & 0 deletions 2018/01/rust/repeat/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions 2018/01/rust/repeat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "repeat"
version = "0.1.0"
authors = ["Tom <[email protected]>"]
edition = "2018"

[dependencies]
29 changes: 29 additions & 0 deletions 2018/01/rust/repeat/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::collections::HashSet;
use std::io::{self, BufRead, BufReader};
use std::fs::File;

fn main() -> io::Result<()> {
let values = read_values()?;
let mut prevs = HashSet::new();
let mut total = 0;
'outer: loop {
for value in &values {
if prevs.contains(&total) {
println!("{}", total);
break 'outer;
}
prevs.insert(total);
total += value;
}
}
Ok(())
}

fn read_values() -> io::Result<Vec<i32>> {
let file = File::open("../../input/input.txt")?;
let mut values = Vec::new();
for line in BufReader::new(file).lines() {
values.push(line.unwrap().parse::<i32>().unwrap());
}
Ok(values)
}
2 changes: 0 additions & 2 deletions 2018/01/rust/sum/.gitignore

This file was deleted.

0 comments on commit 45e4d9f

Please sign in to comment.