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)] | |
struct Note { | |
grid: Vec<Vec<char>>, | |
} | |
impl From<&str> for Note { | |
fn from(s: &str) -> Self { | |
let grid = s.lines().map(|line| line.chars().collect()).collect(); | |
Self { grid } | |
} |
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, | |
sync::{Mutex, OnceLock}, | |
}; | |
use nom::{ | |
bytes::complete::tag, | |
character::complete::{digit1, newline, one_of, space1}, | |
multi::{many1, separated_list1}, | |
IResult, |
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(Debug)] | |
struct Point { | |
x: isize, | |
y: isize, | |
} | |
impl Point { | |
// https://en.wikipedia.org/wiki/Taxicab_geometry | |
fn manhattan_distance(&self, other: &Point) -> usize { | |
((self.x - other.x).abs() + (self.y - other.y).abs()) as usize |
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 colored::*; | |
use std::collections::{HashMap, HashSet}; | |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | |
struct Point { | |
x: i32, | |
y: i32, | |
} | |
impl std::ops::Add for Point { |
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::VecDeque; | |
fn find_next(history: &[isize], lasts: &mut VecDeque<isize>) -> isize { | |
let diffs = history.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>(); | |
if diffs.iter().sum::<isize>() == 0 { | |
return lasts.iter().sum::<isize>(); | |
} | |
lasts.push_back(diffs[diffs.len() - 1]); | |
find_next(&diffs, lasts) | |
} |
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; | |
use nom::{ | |
bytes::complete::tag, | |
character::complete::{alpha1, newline, one_of}, | |
multi::{many1, separated_list0}, | |
sequence::tuple, | |
IResult, | |
}; |
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; | |
#[derive(Debug, PartialEq, Eq)] | |
struct Hand { | |
cards: Vec<u8>, | |
bid: usize, | |
jokers: bool, | |
} | |
impl PartialOrd for Hand { |
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 nom::{ | |
bytes::complete::tag, | |
character::complete::{digit1, space1}, | |
multi::separated_list0, | |
sequence::tuple, | |
IResult, | |
}; | |
#[derive(Debug)] | |
struct Race { |
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 nom::{ | |
bytes::complete::{tag, take_until}, | |
character::complete::digit1, | |
multi::separated_list0, | |
sequence::tuple, | |
IResult, | |
}; | |
use rayon::prelude::*; |
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
import Data.Bits (shift) | |
import Data.List (foldl') | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import Data.Set (Set) | |
import qualified Data.Set as Set | |
import qualified Text.Parsec as Parsec | |
data Card = Card | |
{ winners :: Set Int, |