Skip to content

Instantly share code, notes, and snippets.

make_game ← {¯2 + {?⍵ ⍵⍴3}⍵}
sum_hv ← {g←⍵ ⋄ (+/¨) ¨ ({⍵⌷g}¨⍳≢g) ({⍵⌷⍉g}¨⍳≢g)}
sum_dlr ← {g←⍵ ⋄ y←≢g ⋄ (+/) ¨ ({⍵ (y-⍵-1)⌷g}¨⍳y) ({⍵ ⍵⌷g}¨⍳y)}
won_hv ← +/¨ 1 ¯1 × { t←≢⍵ ⋄ ∨/ t (¯1×t)∘.=sum_hv ⍵}
won_dg ← 1 ¯1 × {t←≢⍵ ⋄ ∨/ t (¯1×t)∘.=sum_dlr ⍵}
idx_empt_map ← {(⍵=0)×({{⍵∘.,⍵}⍳≢⍵} ⍵)}
idx_empt ← {(,idx_empt_map ⍵)~⊂0 0}
at ← {(g r c)←⍵ ⋄ (r c⌷g)←⍺ ⋄ g}
emul_emp ← {g←⍵ ⋄ ⍺ {(r c)←⍵ ⋄ ⍺ at g r c} ¨idx_empt ⍵}
won_fl ← { { ({⌈/⊃⌈/⍵}⍵) ({⌊/⊃⌊/⍵}⍵) } (won_hv ⍵) (won_dg ⍵)}
@afmika
afmika / amogus.c
Created May 21, 2024 20:33
Among Us
#include <stdio.h>
int main() {
int r = 4;
while (r--) {
for (int o = 7; o >= 0; putchar(" #"[(((0x7cf5 >> 0x4*r) & 0xf) >> o-- & 1)]));
putchar('\n');
}
return 0;
}
@afmika
afmika / Option.hs
Last active April 22, 2024 13:41
Proving that Option is a Functor, a Monad, an Applicative and more!
import Control.Applicative (Alternative)
import Control.Monad
import GHC.Base (Alternative (empty, (<|>)))
-- Proving that Option is a Functor, a Monad, an Applicative and more!
data Option a = Some a | None
deriving (Show, Eq)
-- 1. it is a functor! (surprise)
@afmika
afmika / rina-chan-board-cpu-minimalistic.circ
Created September 23, 2021 18:42
A minimalistic CPU designed to display every Rina-chan board
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0"/>
<lib desc="#Gates" name="1"/>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4">
<tool name="ROM">
<a name="contents">addr/data: 8 8