Skip to content

Instantly share code, notes, and snippets.

0e4ef622 0e4ef622

Block or report user

Report or block 0e4ef622

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Cargo.toml
[package]
name = "bork"
version = "0.1.0"
authors = ["Matthew Tran <0e4ef622@gmail.com>"]
edition = "2018"
[dependencies]
# conrod_core = "0.63.0"
# conrod_piston = "0.63.0"
conrod_core = { git = "https://github.com/tdaffin/conrod", branch = "fix_crop" }
View differenttext.sh
#!/usr/bin/env bash
declare -A small=(
['W']=''
['A']=''
['B']=''
['D']=''
['E']=''
['G']=''
['H']=''
View typename.rs
pub trait TypeName {
const NAME: &'static str;
}
macro_rules! typename {
($($typ:ty,)*) => {
$(impl TypeName for $typ {
const NAME: &'static str = stringify!($typ);
})*
}
@0e4ef622
0e4ef622 / day5.rs
Last active Dec 28, 2018
aoc 2018 d5p1 in rust's type system
View day5.rs
// 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 types in 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
@0e4ef622
0e4ef622 / gen.rs
Last active Dec 20, 2018
aoc day 16 2018
View gen.rs
const OPERATIONS: [fn(usize, usize, usize, usize) -> usize; 16] = [
|a, ra, b, rb| ra+rb, // addr
|a, ra, b, rb| ra+b, // addi
|a, ra, b, rb| ra*rb, // mulr
|a, ra, b, rb| ra*b, // muli
|a, ra, b, rb| ra & rb, // banr
|a, ra, b, rb| ra & b, // bani
|a, ra, b, rb| ra | rb, // borr
|a, ra, b, rb| ra | b, // bori
|a, ra, _, rb| ra, // setr
@0e4ef622
0e4ef622 / solution.rs
Last active Dec 16, 2018
aoc day 15 2018
View solution.rs
macro_rules! iter {
($item:expr) => (std::iter::once($item));
($item:expr, $($rest:tt)*) => (std::iter::once($item).chain(iter!($($rest)*)));
}
use std::collections::*;
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash, Debug)]
enum Unit {
Elf,
Gnome,
}
@0e4ef622
0e4ef622 / solution.rs
Last active Dec 13, 2018
aoc day 13 2018
View solution.rs
fn load(input: &str) -> (isize, isize, Vec<u8>, Vec<(isize, isize, isize, isize, usize)>) {
let width = input.lines().next().unwrap().len() as isize;
let height = input.lines().count() as isize;
let mut matrix = vec![0; (width*height) as usize];
let mut cars: Vec<(isize, isize, isize, isize, usize)> = vec![]; // (y, x, dx, dy, state) for sorting, down is positive
for (y, line) in input.lines().enumerate() {
for (x, &c) in line.as_bytes().iter().enumerate() {
let x = x as isize;
let y = y as isize;
matrix[(y*width+x) as usize] = c;
@0e4ef622
0e4ef622 / solution.rs
Last active Dec 11, 2018
aoc day 11 2018
View solution.rs
use rayon::iter::{IntoParallelIterator, ParallelIterator};
pub fn part1(serial_number: usize) -> (usize, usize) {unsafe{
let mut cells = vec![[0isize; 300]; 300];
for y in 1..=300 {
let id = 11;
*cells.get_unchecked_mut(y-1).get_unchecked_mut(0) = ((id*y+serial_number)*id/100%10) as isize - 5;
if y != 1 {
*cells.get_unchecked_mut(y-1).get_unchecked_mut(0) += *cells.get_unchecked_mut(y-2).get_unchecked_mut(0);
}
}
View solution.rs
use std::collections::*;
pub fn part1(input: &str) -> usize {
let mut input = input.split_whitespace().peekable();
let mut entries = Vec::new();
parse_node(input.by_ref(), &mut entries);
entries.into_iter().sum()
}
fn parse_node<'a>(input: &mut impl Iterator<Item = &'a str>, entries: &mut Vec<usize>) {
let child_node_count = input.next().unwrap().parse::<usize>().unwrap();
View solution.rs
#[derive(Clone, Copy)]
enum Event {
Begin(usize),
Sleep,
Wake,
}
#[derive(Clone, Copy)]
struct Entry {
minute: usize,
You can’t perform that action at this time.