This file contains hidden or 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
const INPUT: &'static str = include_str!("inputs/day12.txt"); | |
pub fn p1(input: &Value) -> i64 { | |
match input { | |
Value::Number(n) => n.as_i64().unwrap(), | |
Value::Array(a) => a.iter().map(p1).sum(), | |
Value::Object(o) => o.values().map(p1).sum(), | |
_ => 0, | |
} | |
} |
This file contains hidden or 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
const INPUT: &'static str = include_str!("inputs/day11.txt"); | |
fn increment(cur: &Vec<u8>) -> Vec<u8> { | |
let mut next = cur.clone(); | |
let mut pos = next.len() - 1; | |
loop { | |
if next[pos] != b'z' { | |
next[pos] += 1; | |
// If you need to optimize for longer increments, this part would help: |
This file contains hidden or 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
const INPUT: &'static str = include_str!("inputs/day10.txt"); | |
fn look_and_say_len(input: &str, n: usize) -> usize { | |
let mut cur = input | |
.trim() | |
.bytes() | |
.map(|b| b - b'1' + 1) // Turn the char into a u8 (integer) | |
.collect::<Vec<u8>>(); | |
for _ in 0..n { | |
let mut next = Vec::new(); |
This file contains hidden or 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
const INPUT: &'static str = include_str!("inputs/day09.txt"); | |
fn parse(input: &str) -> (HashMap<(&str, &str), usize>, Vec<&str>) { | |
let distances = input | |
.lines() | |
.flat_map(|l| { | |
let parts = l.split_ascii_whitespace().collect::<Vec<&str>>(); | |
let dist = parts[4].parse().unwrap(); | |
vec![((parts[0], parts[2]), dist), ((parts[2], parts[0]), dist)] | |
}) |
This file contains hidden or 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
const INPUT: &'static str = include_str!("inputs/day08.txt"); | |
pub fn p1(input: &str) -> anyhow::Result<usize> { | |
let lines = input.lines().collect::<Vec<&str>>(); | |
Ok(lines.iter().map(|l| l.len() - in_memory_size(l)).sum()) | |
} | |
fn in_memory_size(s: &str) -> usize { | |
let mut in_slash = false; | |
s.chars() |
This file contains hidden or 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::collections::HashMap; | |
use std::time::Instant; | |
use nom::bytes::complete::tag; | |
use nom::character::complete::{alpha1, u16}; | |
use nom::{IResult, Parser, branch::alt, combinator::map}; | |
const INPUT: &'static str = include_str!("inputs/day07.txt"); | |
#[derive(Debug, Copy, Clone)] |
This file contains hidden or 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::time::Instant; | |
const INPUT: &'static str = include_str!("inputs/day06.txt"); | |
#[derive(Debug, PartialEq, Eq, Copy, Clone)] | |
struct Point { | |
x: usize, | |
y: usize, | |
} | |
This file contains hidden or 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::time::Instant; | |
const INPUT: &'static str = include_str!("inputs/day05.txt"); | |
pub fn p1(input: &str) -> anyhow::Result<i32> { | |
let mut p1 = 0; | |
for line in input.lines().map(|l| l.chars().collect::<Vec<char>>()) { | |
// Check for vowels | |
let vowels = line | |
.clone() |
This file contains hidden or 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 md5::{Digest, Md5}; | |
use rayon::prelude::*; | |
const INPUT: &'static str = include_str!("inputs/day04.txt"); | |
#[allow(dead_code)] | |
fn find_hash_no_format(input: &str, start_size: usize) -> anyhow::Result<i32> { | |
let input = input.trim(); | |
let zeros = start_size / 2; |
This file contains hidden or 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::collections::HashSet; | |
const INPUT: &'static str = include_str!("inputs/day03.txt"); | |
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | |
struct Point { | |
x: isize, | |
y: isize, | |
} | |
NewerOlder