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
| (* This module, [S], defines a very minimal syntax tree that we are going to try to | |
| convert into A-normal form (ANF). ANF is an intermediate form that makes control flow | |
| explicit and lifts intermediate values into named variables. We are going to start with | |
| a very basic lowering algorithm and gradually refine it until it is robust. *) | |
| module S = struct | |
| type name = string [@@deriving show] | |
| type t = | |
| | Var of name | |
| | Int of int |
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 core::cell::Cell; | |
| use core::mem::MaybeUninit; | |
| use core::pin::Pin; | |
| use core::ptr::NonNull; | |
| use core::{fmt, marker, ptr}; | |
| /// Linked list node containing `T`. Uses a circular doubly-linked list. May be used | |
| /// without heap allocations by initializing in-place, see [`Linked::init_in_place`]. | |
| /// | |
| /// Linked list nodes are automatically unlinked when dropped. |
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
| #lang racket | |
| (define (macro-expand s) | |
| (match s | |
| [(list 'let vs b) | |
| (define xs (map car vs)) | |
| (define es (map cadr vs)) | |
| (macro-expand `((lambda ,xs ,b) ,@es))] | |
| [(list 'let* vs b) | |
| (define xs (map car vs)) |
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
| <html> | |
| <head> | |
| <title>Tiles</title> | |
| <style> | |
| html { | |
| --alt1: oklch(0.68 0.17 276); | |
| --alt2: oklch(0.68 0.17 40); | |
| } | |
| .tiles { |
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
| # expected rate to get n drops | |
| def true_exp(n): | |
| if n <= 0: | |
| return 0 | |
| p2 = 1/100 # 2 drops | |
| p1 = 18/100 # 1 drop | |
| p0 = 81/100 # 0 drops |
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
| # expected rate to get n drops | |
| def true_exp(n): | |
| if n <= 0: | |
| return 0 | |
| p_2 = 1/100 # 2 drops | |
| p_1 = 18/100 # 1 drop | |
| p_0 = 81/100 # 0 drops | |
| # E_n = 1 + p_2 E_(n-2) + p_1 E_(n-1) + p_0 E_n |
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
| import random | |
| def simulate(): | |
| kc = 0 | |
| N = 100000 | |
| for i in range(N): | |
| n = 0 | |
| while n < 10: | |
| # roll 1 | |
| if random.randint(1, 10) == 1: |
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
| /// Returns the next smallest integer with the same hamming weight as the input. | |
| pub fn snoob(x: u32) -> u32 { | |
| let mut ntz = x.trailing_zeros(); | |
| if x == 0 { | |
| ntz = 0; | |
| } | |
| let least_one = x & x.wrapping_neg(); // nightly: x.isolate_least_significant_one() | |
| let ripple = x + least_one; | |
| let ones = (x ^ ripple).unbounded_shr(2 + ntz); | |
| ripple | ones |
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
| class Clock { | |
| constructor() { | |
| this.time = 0; | |
| this.bucket = new Array(32); | |
| for (let i = 0; i < 32; i++) { | |
| this.bucket[i] = []; | |
| } | |
| this.dirty = []; | |
| } |
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
| xxx $ yarn run --help | |
| Multiple commands match your selection: | |
| 0. yarn run | |
| 1. yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ... | |
| Run again with -h=<index> to see the longer details of any of those commands. | |
| xxx $ yarn run --help -h=1 | |
| Unknown Syntax Error: Unsupported option name ("--help"). |
NewerOlder