Skip to content

Instantly share code, notes, and snippets.

View Alwinfy's full-sized avatar

Alwinfy Alwinfy

  • United States
View GitHub Profile
@Alwinfy
Alwinfy / bake.py
Last active March 25, 2024 19:57
bake a poem into a colourful cake
#!/usr/bin/env python3
# bake.py - score a poem with colourized ANSI codes
# Type a poem at stdin, print the colourized poem at stdout.
# Requires at least 256-color support from the teletype.
import sys
def ansi(*codes):
return "\x1b[" + ";".join(map(str, codes)) + "m"
def color(nib):
def modifyat(ls, ix, fn):
return ls[:ix] + (fn(ls[ix]),) + ls[ix + 1:]
def global_counter():
code = global_counter.__code__
global_counter.__code__ = code.replace(co_consts = modifyat(code.co_consts, len(code.co_consts) - 1, (1).__add__))
return 0
; wavetables
(def andW (make-wt 8000
(fn [x] (if (> x 0.5) 1 -1))))
(def xorW (make-wt 8000
(fn [x] (if (< (abs x) 0.5) 1 -1))))
(def bufferW (make-wt 8000
(fn [x] (if (> x 0.01) 1 -1))))
(def notW (hardsat -10))
; waveshapers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int acc = 0;
int buf = 0;
char *data = NULL;
char *start;
struct {
(define (slurp f . args)
(let loop ()
(define head (apply f args))
(if (eof-object? head)
'()
(cons head (loop)))))
(define (classify ch)
(case ch
[(#\#) #t]
from __future__ import annotations
from dataclasses import dataclass
def prod(args):
out = 1
for i in args:
out *= i
return out
@Alwinfy
Alwinfy / aoc2023_day10.py
Last active December 10, 2023 16:44
deeply silly day
pipe_types = {
"-": [(-1, 0), (1, 0)],
"|": [(0, -1), (0, 1)],
"7": [(-1, 0), (0, 1)],
"F": [(-1, 0), (0, -1)],
"J": [(1, 0), (0, 1)],
"L": [(1, 0), (0, -1)],
}
def nbrs(pos):
import Control.Arrow ((&&&))
trapolate :: ([Integer] -> Integer -> Integer) -> [Integer] -> Integer
trapolate f ls | all (== 0) ls = 0
| otherwise = f ls $ trapolate f (zipWith (-) (tail ls) ls)
main :: IO ()
main = ((sum . map (trapolate ((+) . last)) &&& sum . map (trapolate ((-) . head))) . map (map read . words) . lines <$> getContents) >>= print
#include <stdio.h>
#include <stdlib.h>
typedef enum {
C_ACE, C_KING, C_QUEEN, C_JACK,
C_TEN, C_NINE, C_EIGHT, C_SEVEN,
C_SIX, C_FIVE, C_FOUR, C_THREE,
C_TWO
} card_t;
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <limits>
#include <map>
#include <algorithm>
struct Range {
int64_t start, end;