Using Advent of Code as a source of toy problems for my first dabblings in Rust. Looking for feedback from more-seasoned Rustaceans on usage of the language.
Advent of Code Day 1: Inverse Captcha
use std::fs::File; use std::io::prelude::*; fn get_input() -> Vec<u8> { let mut file = File::open("input.txt").unwrap(); let mut content = Vec::new(); file.read_to_end(&mut content).unwrap(); for i in 0 .. content.len() { content[i] = content[i] - ('0' as u8); } content } fn offset_sum(input: &[u8], offset: usize) -> i32 { let len = input.len(); let mut sum = 0; for i in 0 .. len { let j = (i + offset) % len; if input[i] == input[j] { sum += input[i] as i32; } } sum } fn main() { let input = get_input(); println!("Part 1 total: {}", offset_sum(&input, 1)); println!("Part 2 total: {}", offset_sum(&input, input.len()/2)); }