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 / Cargo.toml
Last active January 29, 2024 02:22
Advent of Code 2019 - Day 07 // Intcode + Ratatui
[package]
authors = ["icub3d"]
name = "day07"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.79"
@icub3d
icub3d / main.rs
Last active January 25, 2024 00:59
Advent of Code 2019 - Day 05 // Intcode Computer
use std::collections::VecDeque;
fn main() {
let input = include_str!("../input");
// Part 1 - Once we've added the given features to our Intcode computer, we can simply run it.
// We'll want to make sure we get all zeros except for the last value. Then the last value is
// the answer.
let mut computer = Computer::new_with_program_and_input(input, &[1]);
computer.run();
@icub3d
icub3d / main.rs
Last active January 20, 2024 20:58
Advent of Code 2019 - Day 02 // Intcode Computer
fn main() {
let input = include_str!("../input");
// For part 1, we can simply run the program with the two given inputs.
let mut computer = Computer::new_with_program(input);
computer[1] = 12;
computer[2] = 2;
computer.run();
println!("p1: {}", computer[0]);
@icub3d
icub3d / main.rs
Created January 18, 2024 03:46
Byes vs Chars in Rust
// A helper function to print some details about a string.
fn string_details(string: &str) {
println!("string: {}", string);
println!("char details (char: index byte_index bytes)");
// The index and byte_index may be different for non-ASCII characters.
for (index, (byte_index, c)) in string.char_indices().enumerate() {
println!(
" {:?}: {:02} {:02} {:?}",
c,
@icub3d
icub3d / lib.rs
Last active January 16, 2024 01:06
LeetCode #340 & #76
// This is meant to be an introductory problem. The question is, given
// a list of numbers and a number k, return the largest sum of k
// consecutive numbers in the list.
pub fn largest_continuous_sum(nums: Vec<isize>, k: usize) -> isize {
// *state*
//
// In this case, it's just the max sum we've seen so far.
let mut largest = std::isize::MIN;
// *iterate*
@icub3d
icub3d / main.rs
Created January 9, 2024 19:10
Advent of Code 2017 - Day 4 // Optimization & Performance
#![allow(dead_code)]
#![feature(test)]
extern crate test;
use std::collections::HashSet;
use std::ops::BitXor;
use rayon::prelude::*;
fn p1_simple(input: &str) -> usize {
@icub3d
icub3d / main.rs
Created January 8, 2024 01:04
Branch and Bound // Advent of Code 2023 - Day 19
// https://adventofcode.com/2022/day/19
// https://en.wikipedia.org/wiki/Branch_and_bound
use std::ops::{Add, Index, IndexMut, Mul, Sub};
// We are going to use rayon here to parallelize the work. This is
// especially beneficial for part 1 where there are many blueprints.
use rayon::prelude::*;
// These are the different mineral types. We'll use them to iterate.
@icub3d
icub3d / graph.rs
Created January 4, 2024 00:56
A* // LeetCode - Open the Lock
use std::collections::{BinaryHeap, HashMap};
use std::hash::Hash;
#[derive(Clone, Debug, Eq, PartialEq)]
struct State<N>
where
N: Clone + Eq + PartialEq,
{
node: N,
cost: usize,
@icub3d
icub3d / day25.py
Last active December 31, 2023 20:35
Advent of Code 2023 - Day 25
import networkx as nx
import time
# Create our graph.
G = nx.Graph()
# Add all the nodes.
for line in open("input").readlines():
k, vv = line.split(": ")
for v in vv.split():
@icub3d
icub3d / main.rs
Last active December 27, 2023 22:25
Advent of Code 2023 - Day 24
use std::{ops::Sub, str::FromStr};
use nalgebra::{Matrix6, Matrix6x1, RowVector6};
use num::Num;
// Represents a point in 3D space.
#[derive(Debug, Copy, Clone)]
struct Point<N> {
x: N,
y: N,