Last active
December 2, 2018 18:04
-
-
Save qubyte/b99a47b75c91044f2b5c9767200389d4 to your computer and use it in GitHub Desktop.
Advent of Code 2018 day 01 task 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{stdin, BufRead}; | |
use std::collections::BTreeSet; | |
fn main() { | |
let shifts: Vec<i32> = stdin().lock() | |
.lines() | |
.filter_map(|line| line.unwrap().parse().ok()) | |
.collect(); | |
let mut frequency = 0; | |
let mut seen_frequencies = BTreeSet::new(); | |
for shift in shifts.iter().cycle() { | |
frequency += shift; | |
if !seen_frequencies.insert(frequency) { | |
break; | |
} | |
} | |
println!("Frequency is {}", frequency); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run (not optimised but fast enough for this task):
where
input.txt
is a file containing the input data.