Created
December 2, 2017 00:04
-
-
Save Rydgel/59f1945ed69981e9ef0e02ba60cd83d8 to your computer and use it in GitHub Desktop.
Day1 - Advent of Code
This file contains 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
const INPUT: &str = include_str!("../input.txt"); | |
fn convert_input(input: &str) -> Vec<u32> { | |
input | |
.to_owned() | |
.chars() | |
.filter_map(|s| s.to_digit(10)) | |
.collect() | |
} | |
fn solver(digits: &[u32], step: usize) -> u32 { | |
digits.iter().enumerate().fold(0, |acc, (index, ¤t)| { | |
let next = digits[(index + step) % digits.len()]; | |
if current == next { acc + current } else { acc } | |
}) | |
} | |
fn main() { | |
let digits = convert_input(INPUT); | |
println!("{:?}", solver(&digits, 1)); | |
println!("{:?}", solver(&digits, digits.len() / 2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment