Skip to content

Instantly share code, notes, and snippets.

View chrispsn's full-sized avatar

Chris Pearson chrispsn

View GitHub Profile
@TheFausap
TheFausap / q.k
Last active May 10, 2023 21:56
quantum K
ts:{(./!x)!,,/((./.x)*\:(./.y))}
sp:{+/((,/.x)*(,/.y))}
dim:1025#0
dim[2]:1
dim[4]:2
dim[8]:3
dim[16]:4
dim[32]:5
dim[64]:6
dim[128]:7
@suhr
suhr / nk.csv
Last active April 25, 2023 10:39
Syntax Name Description Example Output
+/x Sum Sum all value in x +/1 2 3 4 5 15
-':x Deltas Pairwise differences in x -':1 2 3 4 1 1 1 1
|+x Rotate matrix Rotate x counterclockwise |+3 3#!9 (2 5 8;1 4 7;0 3 6)
x@<x Sort Sort x {x@<x}@8 3 7 1 1 3 7 8
?x,y Set union Unique elements from x and y ?"abac","adob" "abcdo"
x^x^y Intersection Common elements from x and y {?x^x^y}["abac";"adob"] "aba"
x|-x Absolute value Absolute value of x {x|-x}@-1 1
*/y#x Power x in power of y (y>0) {*/y#x}[2;5] 32
y@(#y)!x+!#y Rotate left Rotate y by x elements to the left {y@(#y)!x+!#y}[3;"abcde"] "deabc"
@bluepichu
bluepichu / aoc22-02.mts
Created December 2, 2022 05:09
aoc22-02.mts
import { Advent, f } from "advent";
const { compute, computeCheck } = await Advent({ day: 2 });
compute(2, async (input) => {
const data = input.parse(f.nl(f.tok(f.str())));
let ans = 0;
for (const [them, us] of data) {

Array algebra stripped down

Let's reduce the operations on rank-1 arrays (lists) down to very basic functions.

Two views on lists:

  • A list is a function from indices to values
  • A list is a free monoid

The first view gives ↕n, i⊑x and x⊏y, which correspond to the identity function, application and composition, and also gives f¨x and x f¨ y.

Function projections

julia> using K

In K if you pass less arguments to a function than it accepts then a function projection is constructed:

julia> k"{x+y}[1]"
*1-pfunction*
@xpqz
xpqz / search.md
Last active September 3, 2022 23:31
Linear vs binary search in Dyalog APL

The following question was asked on the APL Orchard chatroom (https://chat.stackexchange.com/transcript/message/59923809#5992380):

so I was reading https://xpqz.github.io/learnapl/iteration.html a bit ago and was confused by the binary search example, so wanted to test. the numbers I'm seeing for linear search are both nothing like his and don't make a lot of sense. I did randInts ← 100000 ? 100000 and compared execution times of randInts ⍳ 1, 19326, and 46729. the return values of those are 94438, 1001, and 1 respectively. the execution times are 0.13ms, 0.47ms, and 0.12us respectively. can anyone explain what's happening?

Obviously, we can't recreate the randInts exactly, but let's run a few timed iterations:

Background

While the yearly get-togethers are called user meetings (previously known as conferences), I found that the social setting allowed Dyalog's staff to discuss and develop ideas in a way that would not happen in the office setting of Bramley.

I had a vague idea about an operator that would ease working with value tolerances and ranges. During our ride up Mount Etna, I by chance had the pleasure of sitting next to Geoff Streeter. We started discussing some things, and before long I had my laptop out and we were prototyping a new operator.

I discussed my idea with Nick Nickolov, who told me that being a fan of ⎕CT←0, he has considered to denote tolerant equality. I think we then naturally would want , and , and

what k4/k7 k9 example result
---------------------------------------------------------------------------------
each-left a f\:b a f\:b (!3)*\:!2 (0 0;0 1;0 2)
each-right a f/:b a f/:b (!3)*/:!2 (0 0 0;0 1 2)
fold f/v f/v */6 7 42
fold w/initial a f/v a f/v 7*/11 13 1001
scan f\v f\v -\1 1 1 1 0 -1
scan w/initial a f\v a f\v 3-\1 1 1 2 1 0
@darencard
darencard / gnuplot_quickstart.md
Created August 31, 2017 14:20
A quick-start guide for using gnuplot for in-terminal plotting

A quick-start guide for using gnuplot for in-terminal plotting

Sometimes it is really nice to just take a quick look at some data. However, when working on remote computers, it is a bit of a burden to move data files to a local computer to create a plot in something like R. One solution is to use gnuplot and make a quick plot that is rendered in the terminal. It isn't very pretty by default, but it gets the job done quickly and easily. There are also advanced gnuplot capabilities that aren't covered here at all.

gnuplot has it's own internal syntax that can be fed in as a script, which I won't get into. Here is the very simplified gnuplot code we'll be using:

set terminal dumb size 120, 30; set autoscale; plot '-' using 1:3 with lines notitle

Let's break this down:

@BaseCase
BaseCase / dc_2017_biblio.md
Last active January 23, 2020 05:13
List of resources recommended or mentioned by the speakers at Deconstruct 2017

Deconstruct 2017 Bibliography

Here are all of the resources mentioned by Deconstruct 2017 speakers, along with who recommended what. Please post a comment if I missed something or have an error!

DC 2017 Speakers' Choice Gold Medalist

  • Seeing Like a State by James Scott

Books

  • Public Opinion by Walter Lippmann (Evan Czaplicki)
  • A Pattern Language by Christopher Alexander (Brian Marick)
  • Domain Driven Design by Eric Evans (Brian Marick)