Skip to content

Instantly share code, notes, and snippets.

View jtdowney's full-sized avatar

John Downey jtdowney

View GitHub Profile
use std::env;
use std::fs::File;
use std::io::Read;
#[derive(Copy, Clone, Debug, Default)]
struct State {
level: usize,
in_garbage: bool,
ignore_next: bool,
}
use std::env;
use std::result;
struct KnotHasher {
current: usize,
skip: usize,
state: Vec<u8>,
}
impl Default for KnotHasher {
@jtdowney
jtdowney / day11.rs
Last active December 12, 2017 03:43
#[macro_use]
extern crate error_chain;
mod errors {
error_chain! {
foreign_links {
Io(::std::io::Error);
}
}
}
@jtdowney
jtdowney / day14.rs
Last active December 14, 2017 16:25
use std::collections::VecDeque;
use std::env;
struct KnotHasher {
current: usize,
skip: usize,
state: Vec<u8>,
}
impl Default for KnotHasher {
@jtdowney
jtdowney / day15.rs
Last active December 15, 2017 15:28
use std::env;
use std::i32;
const FACTOR_A: u32 = 16_807;
const FACTOR_B: u32 = 48_271;
struct Generator {
previous: u32,
factor: u32,
}
@jtdowney
jtdowney / day17.rs
Last active December 17, 2017 13:42
use std::env;
fn part1(cycle_size: usize) {
let mut current_position = 0;
let mut buffer = vec![0];
for i in 1..2018 {
current_position = ((current_position + cycle_size) % buffer.len()) + 1;
buffer.insert(current_position, i);
}
#[macro_use]
extern crate error_chain;
mod errors {
error_chain! {
foreign_links {
Io(::std::io::Error);
ParseInt(::std::num::ParseIntError);
}
}
@jtdowney
jtdowney / day19.rs
Last active December 19, 2017 18:50
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
#[derive(Copy, Clone, Debug)]
enum Direction {
Up,
Down,
Left,
Right,
#[macro_use]
extern crate error_chain;
mod errors {
error_chain! {
foreign_links {
Io(::std::io::Error);
ParseInt(::std::num::ParseIntError);
}
}
#[macro_use]
extern crate error_chain;
mod errors {
error_chain! {
foreign_links {
Io(::std::io::Error);
}
}
}