Skip to content

Instantly share code, notes, and snippets.

use std::io::BufRead;
fn main() {
let reader = std::io::BufReader::new(std::fs::File::open(std::env::args().nth(1).unwrap()).unwrap());
let mut input = String::new();
for line in reader.lines() {
for ch in line.unwrap().chars() {
match ch {
'#' => break,
' ' | '\t' | '\r' | '\n' => (),
c => input.push(c),
@0e4ef622
0e4ef622 / solution.rs
Last active December 6, 2019 06:09
aoc 2019 day 6
use std::collections::*;
pub fn part1(input: &str) -> usize {
let mut graph = HashMap::new();
for line in input.lines() {
let mut s = line.split(")");
let c = s.next().unwrap();
let o = s.next().unwrap();
@0e4ef622
0e4ef622 / fizzbuzz.py
Last active November 20, 2019 02:42
what have you done
from hell import *
y (lambda f: lambda n:
n
(lambda x: lambda x:
f (pred (n)) (lambda x:
and_ (dividesBy (n) (nm(3))) (dividesBy (n) (nm(5)))
(prnts ("FizzBuzz"))
(dividesBy (n) (nm(3))
(prnts ("Fizz"))
@0e4ef622
0e4ef622 / Cargo.toml
Created May 11, 2019 14:45
conrod bug
[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" }
#!/usr/bin/env bash
declare -A small=(
['W']='ⱽ'
['A']='ᴬ'
['B']='ᴮ'
['D']='ᴰ'
['E']='ᴱ'
['G']='ᴳ'
['H']='ᴴ'
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 September 11, 2021 01:00
Advent of Code 2018 day 5 part 1 in rust's type system.
// 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 December 20, 2018 04:59
aoc day 16 2018
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 December 16, 2018 01:22
aoc day 15 2018
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 December 13, 2018 07:10
aoc day 13 2018
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;