Skip to content

Instantly share code, notes, and snippets.

@ap29600
ap29600 / fish.m
Last active December 9, 2021 11:20
A solution for Advent of Code 2021 day 6 that comfortably fits in a tweet (matlab)
x = sum(load("in.txt")(:) == [0:8])';
A = diag(ones(1, 8), 1);
A(9, 1) = 1;
A(7, 1) = 1;
format rat
sum(A^80*x)
sum(A^256*x)
@ap29600
ap29600 / iterative.odin
Last active December 14, 2021 16:04
Iterative vs recursive solution to AOC 2021 day 12
package aoc12
import "core:fmt"
import "core:slice"
import "core:strings"
when ODIN_DEBUG {
input :: `start-A
start-b
A-c
@ap29600
ap29600 / main.rs
Created December 16, 2022 00:13
Advent of Code 2022 day 14 with backtracking
use std::ops::{Index, IndexMut};
use itertools::Itertools;
struct Bitmap {
rows: usize,
cols: usize,
backing: Vec<bool>,
boundary: bool,
}
@ap29600
ap29600 / main.rs
Created December 19, 2022 19:45
Advent of Code day 18 in decent time complexity
use itertools::Itertools;
use std::collections::HashSet;
const N6: [(i64, i64, i64); 6] = [
( 1, 0, 0), (0, 1, 0), (0, 0, 1),
(-1, 0, 0), (0, -1, 0), (0, 0, -1)
];
const N14: [(i64, i64, i64); 18]= [
( 1, 0, 0), (0, 1, 0), ( 0, 0, 1),
(-1, 0, 0), (0, -1, 0), ( 0, 0, -1),
@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) {
@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 / 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 / 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 / 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 / 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
{