This file contains hidden or 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::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); | |
} |
This file contains hidden or 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::env; | |
use std::i32; | |
const FACTOR_A: u32 = 16_807; | |
const FACTOR_B: u32 = 48_271; | |
struct Generator { | |
previous: u32, | |
factor: u32, | |
} |
This file contains hidden or 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; | |
use std::env; | |
struct KnotHasher { | |
current: usize, | |
skip: usize, | |
state: Vec<u8>, | |
} | |
impl Default for KnotHasher { |
This file contains hidden or 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
#[macro_use] | |
extern crate error_chain; | |
mod errors { | |
error_chain! { | |
foreign_links { | |
Io(::std::io::Error); | |
} | |
} | |
} |
This file contains hidden or 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::env; | |
use std::result; | |
struct KnotHasher { | |
current: usize, | |
skip: usize, | |
state: Vec<u8>, | |
} | |
impl Default for KnotHasher { |
This file contains hidden or 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::env; | |
use std::fs::File; | |
use std::io::Read; | |
#[derive(Copy, Clone, Debug, Default)] | |
struct State { | |
level: usize, | |
in_garbage: bool, | |
ignore_next: bool, | |
} |
This file contains hidden or 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
#[macro_use] | |
extern crate error_chain; | |
mod errors { | |
error_chain!{ | |
foreign_links { | |
Io(::std::io::Error); | |
ParseInt(::std::num::ParseIntError); | |
} | |
} |
This file contains hidden or 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::HashMap; | |
use std::env; | |
use std::fs::File; | |
use std::io::{Read, BufReader}; | |
use std::str; | |
fn solve(mut input: Vec<u32>) { | |
let length = input.len(); | |
let mut count = 0; | |
let mut history = HashMap::new(); |
This file contains hidden or 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
extern crate itertools; | |
use itertools::Itertools; | |
use std::env; | |
use std::fs::File; | |
use std::io::{BufRead, BufReader}; | |
use std::result; | |
use std::str; | |
fn part1(input: &[Vec<String>]) { |
This file contains hidden or 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::env; | |
#[derive(Debug)] | |
enum Direction { | |
Left, | |
Right, | |
Up, | |
Down, | |
} |