Skip to content

Instantly share code, notes, and snippets.

@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 / ts.md
Created February 9, 2023 07:00
TimeSpaceX wrapper for J

Defined like so

ts =: {{
    echo < 'timespacex * ', ": x
    result =. x&{{ y ; (8!:0) (x, 1) * x timespacex y }}@> cutopen y
    echo ,. ('expr';'time';'space') , result
}}
@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
@0racle
0racle / tacit.md
Last active April 16, 2023 11:52
Tacit Expressions in J

Atop

  (F@G) y ↔ F (G y)
x (F@G) y ↔ F (x G y)

Over

  (F&G) y ↔       F (G y)
x (F&G) y ↔ (G x) F (G y)

Hook/Compose (aka: After)

(F G) y ↔ y F (G y)

@0racle
0racle / OUTPUT
Last active February 4, 2023 02:12
Rehaping Reshape in J
0 1 2 3 0 1 2 3 0 1
==
1 0 3 2 1 0 3 2 1 0
==
MNOP
IJKL
EFGH
ABCD
==
PONM
@0racle
0racle / snake.raku
Created February 1, 2023 02:34
Terminal Snake game in Raku
#!/usr/bin/env raku
use Terminal::Print;
use Terminal::Print::RawInput;
use Terminal::ANSIColor;
use Point;
my constant COLS = 22;
my constant ROWS = 22;
@0racle
0racle / OUTPUT
Last active June 12, 2023 23:03
Inline::BQN
{elems => 24, rank => 3, shape => (2 3 4), type => Array}
┌─
╎ 0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
0 1 2 3
@0racle
0racle / solve.md
Created December 29, 2022 23:21
AoC 2022 Day 10 in J
NB. === Advent of Code [2022] ===
NB. --- Day 10: Cathode-Ray Tube ---

addx =. noop =. 0
s =. +/\ 1, ".@> (LF,' ') cutopen fread 'input'
echo (20 + 40 * i. 6) +/@([ * ] {~ <:@[) s
echo _40 ({&' #')\ 1 >: | (] -~ 40 | i.@#) s