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 / lib.rs
Created February 22, 2025 01:15
Leetcode 1980 - Cantor's Diagonal Argument
use std::collections::HashSet;
pub struct Solution;
impl Solution {
pub fn find_different_binary_string(nums: Vec<String>) -> String {
let n = nums.len();
let nums = nums
.iter()
.map(|s| usize::from_str_radix(s, 2).unwrap())
@icub3d
icub3d / keybindings.json
Created December 31, 2024 22:26
Code Settings
[
{
// "ctrl+h": Focuses on the left editor group when the text editor is focused, Vim extension is active, and Vim is not in Insert mode.
"key": "ctrl+h",
"command": "workbench.action.focusLeftGroup",
"when": "editorTextFocus && vim.active && vim.mode != 'Insert'"
},
{
// "ctrl+l": Focuses on the right editor group when the text editor is focused, Vim extension is active, and Vim is not in Insert mode.
"key": "ctrl+l",
@icub3d
icub3d / main.rs
Created December 31, 2024 04:41
Advent of Code 2024 - Day 25
fn height(input: &str) -> Vec<isize> {
input
.lines()
.flat_map(|line| line.chars().enumerate())
.filter(|(_, c)| *c == '#')
.fold(vec![-1; 5], |mut heights, (i, _)| {
heights[i] += 1;
heights
})
}
@icub3d
icub3d / main.rs
Created December 31, 2024 02:59
Advent of Code 2024 - Day 24
use std::collections::{HashMap, HashSet, VecDeque};
use std::fmt::Display;
use std::io::Write;
use nom::{
branch::alt, bytes::complete::tag, character::complete::alphanumeric1, combinator::map,
multi::separated_list1, sequence::tuple, IResult,
};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
@icub3d
icub3d / main.rs
Created December 24, 2024 05:58
Advent of Code 2024 - Day 23
use std::collections::{HashMap, HashSet, VecDeque};
use itertools::Itertools;
fn main() {
let now = std::time::Instant::now();
let input = include_str!("input.txt");
// Parse the input into a graph keeping track of vertices and edges.
let (vertices, edges) = input.lines().fold(
@icub3d
icub3d / main.rs
Created December 22, 2024 18:33
Advent of Code 2024 - Day 22
use std::{collections::HashMap, iter::once};
use rayon::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input = include_str!("input.txt");
// Find the 2000th secret for each value and sum them up.
let now = std::time::Instant::now();
let p1 = input
@icub3d
icub3d / main.rs
Created December 21, 2024 19:16
Advent of Code 2024 - Day 21
use std::{
collections::{HashMap, HashSet, VecDeque},
sync::OnceLock,
};
use cached::proc_macro::cached;
use itertools::Itertools;
// The next two functions basically find all the possible shortest paths between
// any two points on each of the keypads. Because the combinations are small, we
@icub3d
icub3d / main.rs
Created December 20, 2024 23:49
Advent of Code 2024 - Day 20
use std::collections::HashSet;
use pathfinding::directed::dijkstra::dijkstra;
use rayon::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct Point {
x: isize,
y: isize,
}
@icub3d
icub3d / main.rs
Created December 19, 2024 20:26
Advent of Code 2024 - Day 19
use std::collections::HashMap;
const INPUT: &'static str = include_str!("input.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> {
// This was a fairly simply input, so I just split_once on the double
// newline and then split the patterns by comma and the problems by newline.
let (patterns, problems) = INPUT
.split_once("\r\n\r\n")
.ok_or("Failed to split input")?;
@icub3d
icub3d / main.rs
Created December 18, 2024 19:21
Advent of Code 2024 - Day 18
use std::collections::{BinaryHeap, HashMap, HashSet};
use std::hash::Hash;
use nom::{
bytes::complete::tag, character::complete::digit1, combinator::map_res, multi::separated_list1,
sequence::separated_pair, IResult,
};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]