Skip to content

Instantly share code, notes, and snippets.

@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
@0racle
0racle / jprofile.md
Last active June 2, 2025 02:47
J Profile Definitions

Here's a rundown of definitions in my .jprofile.ijs, which get loaded in all J sessions.

Some of these are so simple they don't need names, but sometimes I just put things in here so I don't forget how to spell them.

Not all the functions are the most efficient, they're just there for playing with data. Often in a script, I will copy a function in, or re-write one that is more specific to the given problem domain.

Names

Alphanumerics

@0racle
0racle / OUTPUT
Created May 31, 2023 00:14
JGetM on Boxed array
┌───┬───┐
│abc│def│
└───┴───┘
e300000000000000
2000000000000000
0200000000000000
0100000000000000
0200000000000000
3800000000000000
6800000000000000
@0racle
0racle / jrepl.js
Last active May 11, 2023 03:04
J REPL in Node
//!/usr/bin/env node
var ffi = require('ffi-napi');
const BIN = '/opt/j904/bin';
const LIB = `${BIN}/libj.so`;
const PRO = `${BIN}/profile.ijs`;
var libj = ffi.Library(LIB, {
'JInit': [ 'pointer', [ ] ],
@0racle
0racle / image.png
Last active June 30, 2023 07:15
J REPL with syntax highlighting
image.png
@0racle
0racle / vim-things.md
Last active May 4, 2023 05:23
Vim Things

For most languages, I will have a "shebang" line at the top.

The shebang could be #!/usr/bin/env python3, but it could just as easily be -- !/usr/bin/env runhaskell or // !cargo run

This function reads everthing after the ! and uses that command to run the curent file

function! RunBang()
    if (&modified)
        :write
@0racle
0racle / eval-test.raku
Last active May 2, 2023 02:46
Raku EVAL Test
sub infix:<p>($a, $b) is assoc<left> { $a + $b }
sub infix:<t>($a, $b) is assoc<left> { $a * $b }
for $=finish.lines -> $line {
say $line.trans('+*' => 'pt').&EVAL;
}
=finish
2 * 3 + (4 * 5)
@0racle
0racle / 2016-08.ijs
Created February 16, 2023 01:51
Parsing 2 ways
Parse =. (' ' joinstring ])@((3 1 0 { ])`(6 4 1 { ])@.(5 < #@]))@;:
<@Parse;._2 'x-' rplc~ fread 'input'
NB. or
Parse =. (' ' joinstring |.@}. , {.)@('rect|row|column|\d+'&rxall)
<@Parse"1 'm' fread 'input'
@0racle
0racle / solve.ijs
Last active February 6, 2023 22:24
Aoc 2019 day 3 in J
Parse =. +/\@;@(<@(".@}. # 0j1 ^ 'RDLU' i. {.);._2)@,&','
w =. Parse;._2 fread 'input'
echo <./ +/@:|@+. isects =. (e. # [)/ w
echo <./ +/ >: i.&isects"1 w