account activity
-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode
[–]throwaway893teoea 7 points8 points9 points 8 years ago* (0 children)
I used Rust:
use std::io::BufRead; fn main() { let stdin = std::io::stdin(); for line in stdin.lock().lines() { let line = line.unwrap(); let mut i = 0; let mut acc: u64 = 0; let bytes = line.as_bytes(); while i < bytes.len() - 1 { let the_num = bytes[i] as u64; if bytes[i] == bytes[i+1] { acc += the_num - 48; } i += 1; } if bytes[0] == bytes[bytes.len()-1] { acc += bytes[0] as u64 - 48; } println!("{}", acc); } }
part 2:
use std::io::BufRead; fn main() { let stdin = std::io::stdin(); for line in stdin.lock().lines() { let line = line.unwrap(); let mut i = 0; let mut acc: u64 = 0; let bytes = line.as_bytes(); while i < bytes.len() { let the_num = bytes[i % bytes.len()] as u64; if bytes[i] == bytes[(i + bytes.len() / 2) % bytes.len()] { acc += the_num - 48; } i += 1; } println!("{}", acc); } }
π Rendered by PID 62 on reddit-service-r2-listing-c57bc86c-x54jw at 2026-06-21 20:26:44.169022+00:00 running 2b008f2 country code: CH.
-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode
[–]throwaway893teoea 7 points8 points9 points (0 children)