Skip to content

Instantly share code, notes, and snippets.

@0racle
0racle / bounce.ijs
Last active May 13, 2025 22:57
J-80 Examples
n =: 100
z =: 136 240
pos =: 5 + (? n # ,: 10 -~ z)
vel =: 5 * 0.5 -~ (? n # ,: 0 0)
col =: >: 15 | i. n
R =: [: >./ (2 2 -~"1 ($ #: I.@,)#:14 31 31 31 14)&(|.!.0)
F =: {{)d
pos =: pos + vel
vel =: vel * <: +: ((z-3)&> *. 3&<)"1 pos
R col (<. pos)} z $ 0
@0racle
0racle / greedy-map-coloring.md
Last active April 29, 2025 11:33
Greedy Map Coloring
require 'viewmat plot'
colorxy =: colorxy_jzplot_

dm =. ,~ 200                    NB. dimensions
np =. 50                        NB. number of points
ps =. ? np $ ,: dm              NB. points

NB. Voronoi tesselation
Dist =: +/"1@(*:@-"1/)
@0racle
0racle / flat-array-programming.md
Last active April 8, 2025 12:39
Flat Array Programming
@0racle
0racle / times.ijs
Created June 19, 2024 09:06
J translation of BQN datetime lib
cocurrent 'times'
dz_times_ =. 24 * *~ mz_times_ =. 60
ot_times_ =. 719469
dur_times_ =. ((100 * 365.25) - 0.75), 365.25, 30.6
off_times_ =. (ot_times_ - 0.25), 0.75, 0.41
T_times_ =. {{
'day sec' =. (0, dz) #: y

Some horribly hacky Raku code that pretends to be a barely functional logic language

use lib 'lib';
use Logos;

enum < tom sally bob mark floppy book >;

fact :person(sally);
fact :person(mark);
@0racle
0racle / find-forks.pl
Last active April 28, 2024 07:51
Searching for Forks
use v5.36;
use warnings FATAL => 'all';
use Path::Tiny qw< path >;
my $v = qr{ ( [A-Za-z][.:] | [0-9][:] | [^ A-Za-z0-9()] )+ }nx;
my $p = qr{ \( ($v \s+ $v)+ \s+ $v \) }nx;
my $iter = path('code/aoc')->iterator({ recurse => 1 });
my %seen;
@0racle
0racle / raytest.ijs
Last active January 31, 2024 13:43
Demo raylib bindings for J
nixlib =. '/usr/local/lib/libraylib.so'
winlib =. jpath '~/raylib/lib/raylib.dll'
raylib =: IFUNIX {:: winlib;nixlib
Uh =: 0 {:: ] f. NB. Unbox head
NB. Window-related functions
InitWindow =: (raylib,' InitWindow n i i *c') cd ]
CloseWindow =: (raylib,' CloseWindow n') cd ]
WindowShouldClose =: Uh (raylib,' WindowShouldClose i') cd ]
@0racle
0racle / dither-test.ijs
Last active January 9, 2024 23:41
Dithering with Error Diffusion in J
require 'media/imagekit/color_space'
require 'graphics/png'
require 'graphics/pplatimg'
coinsert 'pplatimg'
ParseDiff =: {{
'p d' =. (}: ; {:) ];._2 y
t =. ". '/%' rplc~ d
c =. (+./@(' ' ~: ]) {{ (1, 2 </\ x) <;.1&(x&#) y }}"1 ]) p
a =. {. ($ #: I.@,) > 'X' +./@e.~L:0 c
@0racle
0racle / solve.md
Last active December 15, 2023 04:13
AoC 2023 Day 2 - Parsing input in J in multiple ways

Just an exploration of parsing this days input without regex.

Given the following code

c =. Parse;._2 fread 'input'

echo +/ (* #\) 12 13 14 *./@:>:"1 c
echo +/ */"1 c
@0racle
0racle / k.vim
Created September 16, 2023 11:00
k.vim
if exists('b:current_syntax')|fini|en
sy clear|sy case match |sy sync fromstart |if&l:syn==#'k'|setl com=:/ isk=a-z,A-Z,48-57 |en
" sy clear|sy case match |sy sync fromstart |if&l:syn==#'k'|en
sy match k_e /\i\+\|\S/
sy match k_s /\(`\(\I\i*\>\|:[A-Za-z0-9.:/]*\)\=\)\+/ nextgroup=@k_vw |hi link k_s constant
sy match k_w /[\\\/']:\=/ nextgroup=k_w contained |hi link k_w operator
sy match k_c1 /.\+/ contained |hi link k_c1 special
sy match k_c0 /\\\(\w\+\|\\\|$\)/ nextgroup=k_c1 |hi link k_c0 statement
sy match k_c0 /\\[tw]\>\(:\d\+\)\=/
sy match k_e /"/ nextgroup=k_es |hi link k_e error