Skip to content

Instantly share code, notes, and snippets.

View kspalaiologos's full-sized avatar
❤️‍🔥

Kamila Szewczyk kspalaiologos

❤️‍🔥
View GitHub Profile
#include <book.h>
#define CODE_MAX 65534
#define DICT (1 << 17)
#define LZWEOF 256
struct { int32_t parent; int16_t c, code; } dict[DICT];
void encode(FILE * in, FILE * out) {
int nc = LZWEOF + 1, c, sc, i;
COPY(dict[i].code, -1, DICT);
if ((sc = fgetc(in)) == EOF) sc = LZWEOF;
while ((c = fgetc(in)) != EOF) {
@kspalaiologos
kspalaiologos / 2048.hs
Last active August 31, 2023 22:05
funniest 2048 on the planet
import Control.Monad
import System.Random
import Control.Monad.Trans.State
import Control.Lens hiding(under)
import Control.Conditional hiding(unless, when)
import Data.List
import Data.Functor
import Data.Random.Lift
import Control.Monad.IO.Class
import Control.Monad.Fix
@kspalaiologos
kspalaiologos / magic.c
Created August 25, 2023 17:08
practical o(n) {⍵[⍋⍵]} if {645=⎕dr⍵}
void magic(float * x, size_t n) {
uint32_t * result = malloc(n * sizeof(uint32_t)),
* buckets = malloc(0x100*sizeof(uint32_t)),
* si = malloc(0x100*sizeof(uint32_t)),
* y = (uint32_t *) x, key, temp;
for (size_t i = 0; i < n; i++) y[i] ^= 0x80000000;
for (int i = 0; i < n; ++i) ++buckets[y[i] & 0xFF];
si[0] = 0;
for (int j = 1; j < 0x100; ++j) si[j] = si[j - 1] + buckets[j - 1];
for (int i = n-1; i >= 0; --i) key = y[i] & 0xFF, result[si[key] + --buckets[key]] = y[i];
@kspalaiologos
kspalaiologos / ph1.apl
Created August 3, 2023 10:14
Phase 1 of the Dyalog APL competition.
e1←{⍵/⍨⍵≥⌈\⍵}
e2←⌽⍷⍥⌽
e3←{(⍺∘⌽⌷⍨∘⊂⍵⍳⍨⊢)' ',⎕A}
e4←×2⊥>-<
e5←{n,l-n←(l↑⍺)+.≤⍵↑⍨l←⍺⌊⍥≢⍵}
e6←(⊢⍴⍨2,⍨2÷⍨⍴)~⍤∊⍨⊆⊢
e7←(,÷∨)∘1
e8←{3↑⊃¯2⎕dt(1⎕dt⊂⍵)+⌊/644 924 759|⍺-⍥(1⎕dt⊆)⍵}
e9←{↑,/⌽¨⍵⊂⍨1 0⍴⍨≢⍵}
e0←{(⊢,(⊂'')↑⍨⍺-≢)1↓¨(' ',⍵)⊂⍨(⊢∧⍺≥+\)1,' '=⍵}
template<typename T>
struct artificially_constructible {
template<typename... Args>
explicit artificially_constructible(Args&&... args) {
new (&storage) T(std::forward<Args>(args)...);
}
~artificially_constructible() {
get_ptr()->~T();
}
<p id="p"></p>
<canvas style="border: 1px solid black"></canvas>
<script defer>
const q = document.querySelector("canvas")
let canstart = true
J=q.width=q.height=Math.min(500, document.querySelector("#p").clientWidth);Q='50px monospace';with(Math)with(C=q.getContext`2d`)with(X=Y=R=0,init=e=(e=>{w=f=Y=X=0,R=1,H=250,q.focus(),canstart=false,V=-10,P=[],(F=(e=>{e-w>1/60&&(Y&&(V=-10,Y=0),H+=V,V+=.8,P.forEach(e=>e.P-=3),f%50||P.push({P:J,L:150+(0|200*random()),C:'rgb('+255*random()+','+255*random()+','+255*random()+')'}),(P.some(e=>abs(e.L-H+2)>60&&0<e.P&&e.P<25)||H>J||H<0)&&(R=0,setTimeout(e=>{font=Q,fillStyle='red',fillText(':(',50,90),canstart=true},99)),clearRect(0,0,J,J),P.forEach(e=>{with(e){fillStyle=C,fillRect(P,0,20,L-60),fillRect(P,L+60,20,J-(L+60))}}),fillStyle='red',fillRect(20,H,10,10),font=Q,fillStyle='red',fillText(ceil(f/50-10/3),40,40),f++,w=e),R&&requestAnimationFrame(F)}))()}),document)onkeydown=(e=>{' '==e.key&&R?++Y:' '==e.key; if (canstart) {init()}}),onmousedown=(e=>{R&&++Y; if (canstart) {in
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char ** split(char * string, char * delim) {
int count = 0;
char * tmp = string;
while (strstr(tmp, delim))
tmp = strstr(tmp, delim) + strlen(delim), count++;
@kspalaiologos
kspalaiologos / mandelbrot.mb
Created March 26, 2023 13:10
Mandelbrot fractal viewer in Malbolge.
D'`_M?>n<5Gz276vStPPr/LKml*jFhWDfecc>`v_)yxwvuWm3210/.-,+*)('&%$\[`Y}|{zyxwvutsrqpo2NGLEDCgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFED$#"!~}v<;:987654lTpih.lNjihg`&dcba`Y}|\[Z<;WVONrqpoIHMFEihgfed>CB;_^]\[ZYXW70/43,10)MLKJIHGFEDCBA@?>=<;:9876543210hgfejiba'e^]b[ZY}|{zyxwvutsrqpoO10LKDhgfedcba`_^]\<;492VUTSRQPONMLKJIHGFEDCBA@?>=<;:987654rkpoh.-,+*)('&%]\a`Y}|{[ZSXQPUTMqQJnNGFjiIHG@?cC<;@?>7[Z:9870/SRQ10p(-&JIHGFEDC#zy?>=<;:987on43210/.-,+*)('&%$#"!~}|{zyYR:u8TSRQPONGkjihgfedcba`_?8=<;43WVUTSRQPONML,+$#(!&}CBA@?>=<;:9876543210/.-,+*)('&%$#"Z_X|{zyxwvutsrq4PONGLEihgfF?>C<A:^]\<|:3W76v43,+O).'&+$)(!E%|#zy?}|u]sxq765Vrqj0nmlNjihg`&^c\a`Y}W\UTYXQutsrqponmGFKDhgfedcba`@?87[ZYXWVUTSRQPONMLKJIHGFEf$#"!x}v<]yxwpon43210/.-,+*)gI_d]\"!~}|{zyxwW9ONrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQ10p(-&JIHGFEDCBA@?>={tyxq76543kSinmlkd*)g`e^cb[!_^@?UTxXQVONMq4JIHMLEiCHA@?DC<`@"!=<;4X810T43sr*N(n,+*#G'gf${zy?w|{tyr8vonsrkj0/mfkjchgf_%$#"!~}|{[TSRQPtsrqponmlFEDCHAFE>ba`_^]\[ZYXWVUTSRQPON.-m%*#G'&%$#"baw=<;:9876543qSong-,+*)('&%c\aZ~}|{zyxwvutsrqpon
@kspalaiologos
kspalaiologos / jelly-dataset.csv
Created March 10, 2023 15:59
5165 Jelly answers from CodeGolf StackExchange site.
We can't make this file beautiful and searchable because it's too large.
Author,Code
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1>
<pre><code>Ḥ‘$3СẒḄ=ʋƇ13
</code></pre>
<p><a href=""https://tio.run/##y0rNyan8///hjiWPGmaoGB@ecGjhw12THu5osT3Vfazd0Pi/zuF2b5WsRw1zFGztFB41zNWM/P/f0EBHwdDUAEQaAAEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p>
<h2>How it works</h2>
<pre><code>Ḥ‘$3СẒḄ=ʋƇ13 - Main link. Takes an integer n on the left
ʋ 13 - Last 4 links as a dyad f(i, 13):
$ - Last 2 links as a monad g(i):
Ḥ - 2i

Keybase proof

I hereby claim:

  • I am kspalaiologos on github.
  • I am kspalaiologos (https://keybase.io/kspalaiologos) on keybase.
  • I have a public key whose fingerprint is 6C22 2EA6 B2BD 216A A406 516A C868 F0B6 DE38 409D

To claim this, I am signing this object: