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
use std::usize; | |
use crate::task_handler::get_task; | |
fn most_common_bit(numbers: &Vec<usize>) -> usize { | |
let mut gamma: usize = 0; | |
for column in 0..12 { | |
let (one, zero): (Vec<usize>, Vec<usize>) = numbers | |
.iter() | |
.map(|x| (x >> column) & 1) |
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
use crate::task_handler::get_task; | |
pub fn task2_1() -> String { | |
let input = get_task(2); | |
let mut depth = 0; | |
let mut horizontal = 0; | |
for line in input.lines() { | |
match line.split(' ').collect::<Vec<&str>>()[..] { | |
["forward", x] => horizontal = horizontal + x.parse::<i32>().unwrap(), |
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
use crate::task_handler::get_task; | |
pub fn task1_1() -> String { | |
let input: Vec<usize> = get_task(1) | |
.lines() | |
.map(|x| x.parse::<usize>().unwrap()) | |
.collect(); | |
input.windows(2).filter(|x| x[0] < x[1]).count().to_string() | |
} | |
pub fn task1_2() -> String { |