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
//https://www.youtube.com/watch?v=BdXWlQsd7RI&t=8s | |
use core::marker::PhantomData; | |
trait Nat {} | |
struct Zero {} | |
struct Succ<N: Nat> { | |
number: PhantomData<N>, | |
} |
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
const std = @import("std"); | |
pub fn ArrayList(comptime T: type) type { | |
return struct { | |
const Self = @This(); | |
items: []T, | |
length: usize = 0, | |
pub fn init(comptime SIZE: usize) Self { |
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
#![allow(incomplete_features)] | |
#![feature( | |
const_trait_impl, | |
const_fn_trait_bound, | |
const_generics, | |
const_evaluatable_checked, | |
specialization | |
)] | |
use core::mem::ManuallyDrop; |
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
#![allow(incomplete_features)] | |
#![feature( | |
const_trait_impl, | |
const_fn_trait_bound, | |
const_generics, | |
const_evaluatable_checked, | |
specialization | |
)] | |
trait RemoveRef { |
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
mod std { | |
use std::ops::Shl; | |
use std::fmt::Display; | |
pub struct cout; | |
impl<T: Display> Shl<T> for cout { | |
type Output = cout; | |
fn shl(self, data: T) -> cout { | |
print!("{}", data); | |
self |
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
extern crate alloc; | |
use { | |
alloc::alloc::dealloc, | |
core::{ | |
alloc::Layout, | |
cell::Cell, | |
marker::PhantomData, | |
ops::{Add, Sub}, | |
ptr::{self, NonNull}, |
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
const std = @import("std"); | |
const Node = struct { | |
next: ?*Node = null, | |
frame: anyframe = undefined, | |
}; | |
const List = struct { | |
const Self = @This(); |
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
macro_rules! monadic { | |
( | |
[$($e:tt)*] | [$head:ident : $tail:ident <- tails $origin:ident, | |
$($heads:ident : $tails:ident <- tails $origins:ident),*], $condition:expr | |
) => {{ | |
let mut f = move || { | |
monadic![@INNER [$($e)*] | [$head : $tail <- tails $origin $(,$heads : $tails <- tails $origins)*], $condition ]; | |
None | |
}; | |
f() |
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
const input = @embedFile("../../../Inputs/day01.txt"); | |
const std = @import("std"); | |
const mem = std.mem; | |
const fmt = std.fmt; | |
const ArrayList = std.ArrayList; | |
const TARGET = @as(usize, 2020); | |
pub fn parseInput(slice: []const u8, allocator: *mem.Allocator) !ArrayList(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
usingnamespace closure: { | |
var hashes: []const usize = &[0]usize{}; | |
break :closure struct { | |
pub fn ctStrHash(comptime str: []const u8) usize { | |
const hash = yourAlgo(str); | |
comptime { | |
for (hashes) |existing| { | |
if (existing == hash) @compileError("collision"); | |
} |