Skip to content

Instantly share code, notes, and snippets.

View Alwinfy's full-sized avatar

Alwinfy Alwinfy

  • United States
View GitHub Profile
; 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;
(set! *warn-on-reflection* true)
(def data
(with-open [rdr (clojure.java.io/reader "day03.in")]
(reduce conj [] (line-seq rdr))))
(defn access [data [x y]]
(when (< -1 x (count data))
(let [row (nth data x)]
(when (< -1 y (count row))
import Control.Applicative ((<|>), Alternative)
import Control.Arrow ((&&&))
import Control.Monad (guard)
import Data.Bifunctor (bimap)
import Data.Char (digitToInt, isDigit)
import Data.List (findIndex, tails, isPrefixOf)
import Data.Maybe (catMaybes, listToMaybe)
parse :: Alternative f => Char -> f Int
parse s = guard (isDigit s) *> pure (digitToInt s)