This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct IntcodeVM { | |
memory: Vec<usize>, | |
ip: usize | |
} | |
impl IntcodeVM { | |
pub fn new(state: Vec<usize>) -> IntcodeVM { | |
IntcodeVM { memory: state, ip: 0 } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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(); |