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 / main.rs
Created December 13, 2023 18:39
Advent of Code 2023 - Day 13
#[derive(Clone)]
struct Note {
grid: Vec<Vec<char>>,
}
impl From<&str> for Note {
fn from(s: &str) -> Self {
let grid = s.lines().map(|line| line.chars().collect()).collect();
Self { grid }
}
@icub3d
icub3d / main.rs
Created December 12, 2023 20:23
Advent of Code 2023 - Day 12
use std::{
collections::HashMap,
sync::{Mutex, OnceLock},
};
use nom::{
bytes::complete::tag,
character::complete::{digit1, newline, one_of, space1},
multi::{many1, separated_list1},
IResult,
@icub3d
icub3d / main.rs
Created December 11, 2023 18:33
Advent of Code 2023 - Day 11
#[derive(Debug)]
struct Point {
x: isize,
y: isize,
}
impl Point {
// https://en.wikipedia.org/wiki/Taxicab_geometry
fn manhattan_distance(&self, other: &Point) -> usize {
((self.x - other.x).abs() + (self.y - other.y).abs()) as usize
@icub3d
icub3d / main.rs
Created December 10, 2023 21:28
Advent of Code 2023 - Day 10
use colored::*;
use std::collections::{HashMap, HashSet};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct Point {
x: i32,
y: i32,
}
impl std::ops::Add for Point {
@icub3d
icub3d / main.rs
Created December 9, 2023 17:49
Advent of Code 2023 - Day 09
use std::collections::VecDeque;
fn find_next(history: &[isize], lasts: &mut VecDeque<isize>) -> isize {
let diffs = history.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>();
if diffs.iter().sum::<isize>() == 0 {
return lasts.iter().sum::<isize>();
}
lasts.push_back(diffs[diffs.len() - 1]);
find_next(&diffs, lasts)
}
@icub3d
icub3d / main.rs
Created December 8, 2023 20:52
Advent of Code 2023 - Day 08
use std::collections::HashMap;
use nom::{
bytes::complete::tag,
character::complete::{alpha1, newline, one_of},
multi::{many1, separated_list0},
sequence::tuple,
IResult,
};
@icub3d
icub3d / main.rs
Created December 8, 2023 00:22
Advent of Code 2023 - Day 07 - Rust
use std::collections::HashMap;
#[derive(Debug, PartialEq, Eq)]
struct Hand {
cards: Vec<u8>,
bid: usize,
jokers: bool,
}
impl PartialOrd for Hand {
@icub3d
icub3d / day06.rs
Created December 7, 2023 00:23
Advent of Code 2023 - Day 06
use nom::{
bytes::complete::tag,
character::complete::{digit1, space1},
multi::separated_list0,
sequence::tuple,
IResult,
};
#[derive(Debug)]
struct Race {
@icub3d
icub3d / day05.rs
Created December 6, 2023 18:58
Advent of Code 2023 - Day 5
use nom::{
bytes::complete::{tag, take_until},
character::complete::digit1,
multi::separated_list0,
sequence::tuple,
IResult,
};
use rayon::prelude::*;
@icub3d
icub3d / day04.hs
Created December 6, 2023 01:11
Advent of Code - Day 04 - Part 1 - Haskell
import Data.Bits (shift)
import Data.List (foldl')
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Text.Parsec as Parsec
data Card = Card
{ winners :: Set Int,