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::HashSet; | |
fn parse<'a>(input: &'a str) -> impl Iterator<Item = (&'a str, u32)> + 'a { | |
input.split("\n").map(|line| { | |
let mut split = line.split(" "); | |
let dir = split.next().unwrap(); | |
let steps = split.next().unwrap().parse::<u32>().unwrap(); | |
(dir, steps) | |
}) | |
} |
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 core::num; | |
fn parse(input: &str) -> Vec<Vec<u32>> { | |
let mut grid = vec![]; | |
for line in input.split("\n") { | |
let mut row = vec![]; | |
for c in line.chars() { | |
let i = c.to_digit(10).unwrap(); | |
row.push(i); | |
} |
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::HashMap, iter::Peekable, str::Split}; | |
#[derive(Debug)] | |
struct Dir<'a> { | |
path: Vec<&'a str>, | |
files: HashMap<&'a str, File<'a>>, | |
} | |
#[derive(Debug)] | |
struct File<'a> { |
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::HashSet; | |
fn main() { | |
let input = include_str!("day06_input.txt"); | |
let data: Vec<char> = input.chars().collect(); | |
// just let HashSet do all the work | |
let mut message_set = HashSet::new(); | |
for i in 0..data.len() { | |
if i >= 13 { |
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 main() { | |
let input = include_str!("day05_input.txt"); | |
let lines = input.split("\n").collect::<Vec<&str>>(); | |
// find where the file switches from stacks to instructions | |
let mut split = 0; | |
for (i, line) in lines.iter().enumerate() { | |
if line.is_empty() { | |
split = i; | |
} |
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 parse_line(line: &str) -> (i32, i32, i32, i32) { | |
let mut split = line.split(","); | |
let left = split.next().unwrap(); | |
let mut ls = left.split("-"); | |
let left_from: i32 = ls.next().unwrap().parse().unwrap(); | |
let left_to: i32 = ls.next().unwrap().parse().unwrap(); | |
let right = split.next().unwrap(); | |
let mut rs = right.split("-"); | |
let right_from: i32 = rs.next().unwrap().parse().unwrap(); | |
let right_to: i32 = rs.next().unwrap().parse().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
#[derive(Clone, Copy)] | |
enum Move { | |
Rock, | |
Paper, | |
Scissors | |
} | |
impl Move { | |
pub fn from(s: &str) -> Move{ | |
use Move::*; |
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 main() { | |
let input = include_str!("day01_input.txt"); | |
let mut elf_totals = vec![]; | |
let mut total = 0; | |
for line in input.split('\n') { | |
if line == "" { | |
elf_totals.push(total); | |
total = 0; | |
} else { |
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
/** | |
* We use the convention of zero as an error term, | |
* since we also use `null_ptr()` to indicate an error. | |
* So for consistency, a zero term is an error in both cases. | |
*/ | |
#define polar_POLAR_FAILURE 0 | |
#define polar_POLAR_SUCCESS 1 | |
typedef struct polar_Polar polar_Polar; |
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
BasedOnStyle: LLVM | |
IndentWidth: 4 |