Compare commits

..

No commits in common. "b519e0bad2f6b79d3e5bb0d705388a4dec0e3ce8" and "7681bbc760d58979facfa30acd0dbe5984766153" have entirely different histories.

3 changed files with 4 additions and 40 deletions

View File

@ -19,7 +19,7 @@ struct MoveCmd {
} }
impl FromStr for MoveCmd { impl<'a> FromStr for MoveCmd {
type Err = eyre::Report; type Err = eyre::Report;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {

View File

@ -1,36 +0,0 @@
use color_eyre::eyre;
pub fn part1(numbers: &Vec<u16>) -> u64 {
let mut bit_diffs: [isize; 12] = [0; 12];
for num in numbers {
for i in 0..11 {
if num & (1 << i) > 0 {
bit_diffs[i] += 1
}
else {
bit_diffs[i] -= 1
}
}
}
let mut gamma = 0u16;
for (i, sum) in bit_diffs.iter().enumerate() {
let bit = if *sum >= 0 {1} else {0};
gamma |= bit << i;
}
let epsilon = !gamma & (65535 >> 4); // since these are really only 12-bit numbers we have to clear the 4 spurious 1's that come from inverting epsilon
epsilon as u64 * gamma as u64
}
pub fn run(data: &str) -> eyre::Result<()> {
let mut nums = Vec::new();
for line in data.lines() {
nums.push(u16::from_str_radix(line, 2)?);
}
println!("One: {}", part1(&nums));
Ok(())
}

View File

@ -4,13 +4,13 @@ use color_eyre::eyre;
mod lib; mod lib;
use lib::load; use lib::load;
mod day3; mod day2;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let data = load("data/03.txt")?; let data = load("data/02.txt")?;
let start = Instant::now(); let start = Instant::now();
day3::run(&data)?; day2::run(&data)?;
let (dur, unit) = format_ns(start.elapsed().as_nanos()); let (dur, unit) = format_ns(start.elapsed().as_nanos());
println!("Completed in {}{}", dur, unit); println!("Completed in {}{}", dur, unit);
Ok(()) Ok(())