Skip to content

Instantly share code, notes, and snippets.

@Gordin508
Gordin508 / main.rs
Last active January 8, 2024 10:26
Advent of Code 2022 Day 19 (Rust)
#![allow(unused)]
#![allow(dead_code)]
use regex::Regex;
use lazy_static::lazy_static;
lazy_static! {
// regexes are pretty overkill for this task,
// but since I hadn't used them in Rust I wanted to try them out
static ref RE_BP: Regex = Regex::new(r"Blueprint (?<id>\d+): (?<content>.*)").unwrap();
@Gordin508
Gordin508 / main.rs
Last active January 9, 2024 08:34
Advent of Code 2017 Day04 solution
#![allow(unused)]
#![allow(dead_code)]
/*
* An unoptimized implementation could simply use HashSets to solve the task,
* and the runtime of that is actually fine. However, HashSets are somewhat overkill
* for these inputs (only a handful of words per line).
* Therefore my idea is to implement alternative data structures which behave
* identically, but perform better for small input sets.
@Gordin508
Gordin508 / lib.rs
Last active January 13, 2024 08:37 — forked from icub3d/lib.rs
LeetCode #340 & #76
use std::hash::Hash;
use std::collections::{HashMap, VecDeque};
use std::cmp::max;
// This is meant to be an introductory problem to the technique. 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 {
if nums.len() < k {
// undefined behavior
@Gordin508
Gordin508 / main.rs
Last active January 25, 2024 03:54 — forked from icub3d/main.rs
Advent of Code 2019 - Day 02 // Intcode Computer
pub struct IntcodeVM {
memory: Vec<usize>,
ip: usize
}
impl IntcodeVM {
pub fn new(state: Vec<usize>) -> IntcodeVM {
IntcodeVM { memory: state, ip: 0 }
}
@Gordin508
Gordin508 / main.rs
Last active January 29, 2024 02:25 — forked from icub3d/main.rs
Advent of Code 2019 - Day 05 // Intcode Computer
use std::collections::{VecDeque, HashSet};
use std::fmt::{self, Display, Formatter};
use std::io;
use std::process::exit;
// This implementation is needlessly complicated,
// but it comes with a simple debugger which I find kinda neat.
// Just invoke vm.add_breakpoint(0) before vm.run() and use
// simple commands via stdin.