DEV Community

Discussion on: AoC Day 1: Chronal Calibration

shritesh profile image
Shritesh Bhattarai • Edited on

I'm doing AoC with Rust too and the solution I came up with looks almost exactly like yours.

Part 1

pub fn callibrate(input: &[&str]) -> i32 {
    input.iter().map(|s| s.parse::<i32>().unwrap()).sum()

Part 2: I used a HashSet

pub fn twice(input: &[&str]) -> i32 {
    let mut numbers = input.iter().map(|s| s.parse::<i32>().unwrap()).cycle();

    let mut seen_results = HashSet::new();

    let mut sum = 0;

    loop {
        let num =;
        sum += num;

        if seen_results.contains(&sum) {
            return sum;
        } else {

Instead of changing the file every day, I'll suggest creating a separate file for each day inside src/bin directory. That way, you can execute them using cargo run --bin day_1. Small but well thought out features like this is why I love Rust so much. For example, you can look at my repo at

I hope to get through all of the challenges this year and learn from everyone here.

rpalo profile image
Ryan Palo Author

Oooh! Good idea! I’m definitely doing that. Thanks!