Skip to content

Instantly share code, notes, and snippets.

@zoeisnowooze
zoeisnowooze / cpm_truncate.c
Last active August 14, 2024 14:55
Experiment with truncation of CPM values
#include <inttypes.h>
#include <stdio.h>
const double EXPECTED_CPM = 0.758630370209851;
const int TRUNCATE_LEN = 28;
int main(int argc, char **argv) {
uint64_t cpm_i = *(uint64_t *)&EXPECTED_CPM;
// Method 1: round up and truncate the lowest TRUNCATE_LEN bits.
import os
def words(n):
if n >= 1000:
return words(n // 1000) + " thousand " + words(n % 1000)
elif n >= 100:
return words(n // 100) + " hundred " + words(n % 100)
elif n >= 20:
tens = [
#!/bin/bash
slashes=$(sed 's/\([\/\\]\)/\1/g' <<< "$1")
while [ -n "$slashes" ]; do
slash=$(cut -c1 <<< "$slashes")
case "$slash" in
" ")
slashes=$(cut -c2- <<< "$slashes");
if [ "$(cut -c1 <<< "$slashes")" != "/" ]; then
echo -n "$slash"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char randascii() {
while (true) {
char r = rand() & 0x7f;
if (r >= 0x20 && r <= 0x7e) {
return r;
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int number_of_doors = atoi(argv[1]);
int number_of_passes = atoi(argv[2]);
int open_doors = 0;
for (int i = 1; i <= number_of_doors; i++) {
int toggles = 0;
#include <stdbool.h>
#include <stdio.h>
typedef bool (*gen_f)(size_t *i);
gen_f from_to(size_t from, size_t to) {
size_t i = from;
bool g(size_t * j) {
if (i <= to) {
@zoeisnowooze
zoeisnowooze / parens_substring.c
Created August 17, 2022 01:13
Length of the longest valid parenthesis substring.
#include <stdbool.h>
#include <stdio.h>
int main(int argc, char **argv) {
int length, maxlength, stacksize;
length = maxlength = stacksize = 0;
while (true) {
int c;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct node {
int val;
struct node *next;
struct node *random;
} node;
#include <stdio.h>
int count_letters(char *str, char *word) {
char c;
int letters = 0;
while ((c = *str++) && *word) {
if (c == *word) {
letters++;
word++;
@zoeisnowooze
zoeisnowooze / longtext.py
Last active June 14, 2022 02:10
Loooooong teeeeeext
import argparse
import shutil
import subprocess
def main():
parser = argparse.ArgumentParser(description="Multiplies the vowels.")
parser.add_argument("string", metavar="STRING", type=str, help="a string")
parser.add_argument("n", metavar="N", type=int, help="an integer")
parser.add_argument(