Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
- }
- $ ./program <input.txt
- $ ./program $(cat input.txt)
Add Comment
Please, Sign In to add comment