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
fn next_phase(nums: &[i64], strt: usize) -> Vec<i64> { | |
let mut pfs = vec![0]; | |
pfs.extend(nums); | |
for i in 1..pfs.len() { | |
pfs[i] += pfs[i-1]; | |
} | |
let mut newl = Vec::with_capacity(nums.len()); | |
for n in strt..nums.len()+strt { |
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 fn part2(input: &str) -> i64 { | |
// parse input | |
let onums = input | |
.trim() | |
.bytes() | |
.map(|x| (x - b'0') as i64) | |
.collect::<Vec<_>>(); | |
let offset = input[..7].parse::<usize>().unwrap(); |
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::*; | |
pub fn part1(input: &str) -> impl std::fmt::Display { | |
let prog = input.trim().split(",").map(|x| x.parse().unwrap()).collect(); | |
let mut vm = ic::Icvm::new(prog); | |
vm.run(); | |
let mut map = HashMap::new(); | |
let a = vm.drain_outputs().collect::<Vec<_>>(); | |
for ch in a.chunks(3) { | |
map.insert((ch[0], ch[1]), ch[2]); | |
} |
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::*; | |
pub fn part1(input: &str) -> impl std::fmt::Display { | |
let mut botp = (0i128, 0i128); | |
let mut botd = 0i32; // 0 = up, 1 = right, 2 = down, 3 = left | |
let mut vm = ic::Icvm::new(input.trim().split(",").map(|x| x.parse::<i128>().unwrap()).collect()); | |
let mut paint = HashMap::new(); | |
while vm.status() != ic::Status::Finished { | |
vm.run(); |
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::io::Read; | |
mod solution; | |
// const INPUT: &'static str = include_str!("../in"); | |
fn main() { | |
let mut input = String::new(); | |
std::io::stdin().read_to_string(&mut input); | |
let p1 = solution::part1(&input); | |
println!("part 1: {}", p1); | |
let p2 = solution::part2(&input); | |
println!("part 2: {}", p2); |
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; | |
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | |
pub enum Status { | |
Ready, | |
WaitingForInput, | |
Finished, | |
} | |
#[derive(Clone, Debug)] |
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
[package] | |
name = "day7" | |
version = "0.1.0" | |
authors = ["Matthew Tran <0e4ef622@gmail.com>"] | |
edition = "2018" | |
[dev-dependencies] | |
criterion = "*" | |
[[bench]] |
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
// 100,000 isn't actually required unless you're trying to compile with relatively large inputs | |
// such as the input from AoC | |
#![recursion_limit = "100000"] | |
#![allow(dead_code)] | |
#![allow(non_camel_case_types)] | |
//! The General Idea | |
//! | |
//! Associated typesin traits can be used to make type level functions. A trait of the form shown | |
//! below can be viewed as a function that takes one type, `Self` and returns a new type, `O`. To |
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; | |
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | |
pub enum Status { | |
Ready, | |
WaitingForInput, | |
Finished, | |
} | |
#[derive(Clone, Debug)] |
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 fn part1(input: &str) -> isize { | |
let mut max = 0isize; | |
let mut phases = [0,0,0,0,0]; | |
for a in 0..5 { | |
for b in 0..5 { | |
if a==b { continue;} | |
for c in 0..5 { | |
if c==a { continue;} | |
if c==b { continue;} | |
for d in 0..5 { |