Skip to content

Instantly share code, notes, and snippets.

View tbarusseau's full-sized avatar
🦀
Rust evangelism strike force, one compile error at a time

Thomas Barusseau tbarusseau

🦀
Rust evangelism strike force, one compile error at a time
  • theTribe
  • Rouen, France
View GitHub Profile
static RE: OnceLock<Regex> = OnceLock::new();
fn process_input(input: &str) -> Vec<(i64, i64)> {
let re = RE.get_or_init(|| Regex::new(r"(\d+)\s*").unwrap());
let r: Vec<Vec<i64>> = input
.trim_end()
.lines()
.map(|l| {
re.captures_iter(l)
#[derive(Debug)]
struct Rules {
seeds: Vec<i64>,
maps: Vec<Vec<(i64, i64, i64)>>,
}
impl Rules {
fn compute_next_location(n: i64, map: &(i64, i64, i64)) -> Option<i64> {
let (dest_range, source_range, range_length) = *map;
#[derive(Debug)]
struct Game {
winning: Vec<String>,
rolled: Vec<String>,
}
impl From<&str> for Game {
fn from(value: &str) -> Self {
let colon_index = value.find(':').unwrap();
fn process_input(input: &str) -> Vec<Vec<char>> {
input
.trim_end()
.lines()
.map(|l| l.chars().collect())
.collect()
}
fn is_symbol(c: char) -> bool {
!c.is_alphanumeric() && c != '.'
struct Game {
game_index: i32,
subsets: Vec<(i32, i32, i32)>,
}
impl TryFrom<&str> for Game {
type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
let mut subsets = vec![];
fn compute_result(input: &str) -> u32 {
input
.replace(char::is_alphabetic, "")
.lines()
.map(|l| {
let mut iter = l.chars().flat_map(|c| char::to_digit(c, 10)).peekable();
let first = *iter.peek().expect("no first numerical character");
let last = iter.last().expect("no last numerical character");
fn find_side_digit(digits: &[&str], line: &str, left: bool) -> usize {
let map = digits.iter().enumerate().flat_map(|(i, d)| {
if left {
if let Some(min_index) = line.find(d) {
Some((min_index, i % 9 + 1))
} else {
None
}
} else {
if let Some(max_index) = line.rfind(d) {
@group(0) @binding(0) var<storage, read_write> moon_height_data: MoonHeightData;
fn smooth_min(a: f32, b: f32, t: f32) -> f32 {
let h: f32 = clamp(0.5 + 0.5 * (b - a) / t, 0.0, 1.0);
return mix(b, a, h) - t * h * (1.0 - h);
}
fn smooth_max(a: f32, b: f32, t: f32) -> f32 {
return smooth_min(a, b, -t);
fn sum(vector: &mut Vec<i32>) -> i32 {
let mut sum = 0;
vector.iter_mut().map(|e| e.add(1));
for item in vector {
sum = sum + *item
}
sum
fn sum(vector: &Vec<i32>) -> i32 {
let mut sum = 0;
// vector.iter_mut().map(|e| e.add(1));
// ERROR: cannot borrow `*vector` as mutable, as it is behind a `&` reference
for item in vector {
sum = sum + item
}