Skip to content

Instantly share code, notes, and snippets.

@ap29600
ap29600 / font
Last active April 21, 2025 11:31
generate heatmaps from performance data in K
abcdefghijklmnopqrstuvwxyz0123456789.+-_/
a##
#
####
# #
# #
####
b
@ap29600
ap29600 / i.c
Last active September 26, 2024 09:52
a small k-like calculator in Whitney C
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
typedef char c; typedef size_t s; typedef double f; typedef struct A{f s; struct A*r;}A; static const A y={0},r={0};
#define D(f) A f(A x,A y)
#define M(f) A f(A x)
#define i(...) for(s i=0;i<n;++i){__VA_ARGS__;}
#define j(...) for(s j=0;j<m;++j){__VA_ARGS__;}
@ap29600
ap29600 / associative_reduction.bqn
Last active August 31, 2024 14:21
A BQN function performing associative reductions on paths of an array
# s0‿o1 𝔽_associativeReduce 𝕩: 𝔽´¨ on paths in 𝕩 of s steps with stride (=𝕩)↑o1
#
# example:
# m ≡ 4‿(¯1‿1) +_associativeReduce x
# +-------+ +-------------+
# | . . . | | . . . . . . |
# | y . . | | . . . d . . |
# +-------+ | . . c . . . |
# | . b . . . . |
# y ≡ +´a‿b‿c‿d | a . . . . . |
@ap29600
ap29600 / hex_circle.m
Last active August 7, 2024 11:21
A Digital Differential Analyzer-based algorithm for tracing circles on hexagonal grids
function [as, bs, x, y] = hex_circle(r)
%% a,b represents a complex number in the form a + b * zeta, where zeta is the principal third root of unity.
%% therefore, abs(a + b * zeta) = a^2 - a*b + b^2, which gives the DDA equations
a = round(r);
b = 0;
as = [a];
bs = [b];
%% initialize DDA
e = a^2 - r;
da = 2 * a + 1 - b;
@ap29600
ap29600 / euler61.bqn
Created June 5, 2024 11:39
A solution to project euler 61 in BQN
n ← 6
k ← 4
d ← ↕n
poly ← (0.5×d+1)≍¨(-0.5×d-1)
limits ← ⌈{a‿b‿c: (2×a)÷˜-b-√(טb)-4×a×c}¨ poly ∾⌜ -10⋆k-1‿0
values ← poly {+´𝕨×(ט𝕩)‿𝕩}¨ {a‿b:<a+↕b-a}˘limits # the numbers to be tested
perm ← (n-1) ∾˘˜ (≍↕0){∾˝(0∾˘1+𝕩)⊸⊏˘⍒˘=⌜˜↕𝕨}´-⟜↕n-1 # distinct cycles of number class
{
@ap29600
ap29600 / day12.c
Created December 13, 2023 00:30
advent of code 2023 day 12 in C with dynamic programming
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#define ENSURE(p) ({__typeof(p) _p = p; assert(_p); _p; })
typedef struct {
size_t dot;
@ap29600
ap29600 / font.i
Created November 21, 2023 09:17
a bitmap font in motorola syntax assembly
; syntax M68k
Font_height equ 10
Font_width equ 8
font:
dcb.b Font_height*(32-0),$55;
; spc
dc.b %00000000
dc.b %00000000
dc.b %00000000
dc.b %00000000
@ap29600
ap29600 / day23.odin
Last active December 23, 2022 22:40
Advent of Code day 23 in Odin
package main
import "core:os"
import "core:strings"
import "core:fmt"
import "core:slice"
import "core:strconv"
import "core:time"
State :: enum u8 {
@ap29600
ap29600 / day22.odin
Created December 22, 2022 21:40
Advent of Code day 22 in Odin
package main
import "core:fmt"
import "core:math"
import "core:mem"
import "core:os"
import "core:slice"
import "core:unicode"
import "core:strconv"
import "core:strings"
@ap29600
ap29600 / main.odin
Created December 20, 2022 23:08
Advent of Code 2022 day 20 in Odin
package main
import "core:os"
import "core:fmt"
import "core:slice"
import "core:mem"
import "core:strings"
import "core:strconv"
mix :: proc (numbers: []int, mix: int) -> (result: int) {