Skip to content

Instantly share code, notes, and snippets.

View icub3d's full-sized avatar

Joshua Marsh icub3d

  • Optum
  • USA
View GitHub Profile
@icub3d
icub3d / day12.rs
Created September 12, 2025 22:52
Advent of Code 2015 Day 12 Solution
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,
}
}
@icub3d
icub3d / day11.rs
Created September 12, 2025 21:31
Advent of Code 2015 Day 11 Solution
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:
@icub3d
icub3d / day10.rs
Created September 12, 2025 19:37
Advent of Code 2015 Day 10 Solution
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();
@icub3d
icub3d / day09.rs
Created September 12, 2025 18:32
Advent of Code 2015 Day 9 Solution
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)]
})
@icub3d
icub3d / day08.rs
Created September 12, 2025 17:09
Advent of Code 2015 Day 8 Solution
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()
@icub3d
icub3d / day07.rs
Created September 7, 2025 21:45
Advent of Code 2015 Day 7 Solution
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)]
@icub3d
icub3d / day06.rs
Created September 7, 2025 19:22
Advent of Code 2015 Day 6 Solution
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,
}
@icub3d
icub3d / day05.rs
Created September 7, 2025 18:45
Advent of Code 2015 Day 5 Solution
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()
@icub3d
icub3d / day04.rs
Created September 3, 2025 23:08
Advent of Code 2015 Day 4 Solution
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;
@icub3d
icub3d / day03.rs
Created September 2, 2025 19:19
Advent of Code 2015 Day 3 Solution
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,
}