NB. === Advent of Code [2016] ===
NB. --- Day 2: Bathroom Security ---
moves =. <@:+.@(0j1 ^ 'DRUL'&i.);._2 fread 'input'
Move =. {{
x&{{ p =: p + y * ((< p + y) { x ~: '.') }}"1 y
(< p) { x
}}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass(frozen=True) | |
class Point: | |
x: float | |
y: float | |
def __repr__(self): | |
return f"({self.x},{self.y})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
cx, mx = map(str.splitlines, open('input').read().split("\n\n")) | |
batch = lambda xs, n: (xs[i : n + i] for i in range(0, len(xs), n)) | |
c = [[x[1].strip() for x in batch(line, 4)] for line in cx[:-1]] | |
c = [list(filter(len, x)) for x in zip(*c)] | |
d = [e.copy() for e in c.copy()] # deepcopy for part 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env raku | |
use NativeCall; | |
class J is repr('CPointer') { | |
my constant $BIN = "/opt/j903/bin"; | |
my constant $LIB = "$BIN/libj.so"; | |
my constant $PRO = "$BIN/profile.ijs"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jconsole | |
NB. No space before these tokens | |
bef =: ;: ') @ @. @: & &. &: &.: " ` ;. !. !: / /. \ ~ }' | |
NB. No space after these tokens | |
aft =: ;: '( @ @. @: & &. &: &.: " ` ;. !. !:' | |
Cont =: {{ +./ ((dltb > x) (-: ;)"1 0 y) }} | |
Fmt =: {{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my %ops = (AND => &[+&], OR => &[+|], LSHIFT => &[+<], RSHIFT => &[+>]); | |
my (%cct, %mem); | |
my &get = -> \val { %mem{val} //= +val // %cct{val}() } | |
for $=finish.lines { | |
given .words { | |
when 3 { %cct{.[2]} = { get(.[0]) } } | |
when 4 { %cct{.[3]} = { +^get(.[1]) +& 0xFFFF } } | |
when 5 { %cct{.[4]} = { %ops{.[1]}(get(.[0]), get(.[2])) } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6.d; | |
class A { | |
has $!a = 'private'; | |
method !a { $!a } | |
} | |
multi sub trait_mod:<is>(Mu:U \obj, :$spying!) { | |
A.^add_trustee(obj); | |
A.^compose; |
A "partition" adverb in J (similar to APL's ⊆)
P =: {{ (1, 2 </\ x) u;.1&((0 < x)&#) y }}
Partition on delimiter (à la (≠⊆⊢)
)
',' (~: <P ]) 'comma,separated,values'
┌─────┬─────────┬──────┐
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you want to use this with rlwrap, the following command works for me | |
# > INPUTRC='~/.dyalog/inputrc' rlwrap -a dyalog -s -b | |
# Which can then be aliased to whatever you like | |
"`[": "←" | |
"`-": "×" | |
"`=": "÷" | |
"`p": "*" | |
"`*": "⍟" |
One of the problems in the "2016 International APL Problem Solving Competition (General Computing Category)" was as follows
Write an APL function named 'winner' which
- takes a right argument of a 5x5 character matrix representing a Teeko board
- if there is a winner, returns the appropriate character for the winner, otherwise returns the character representing an unoccupied space
The competition was won by Joshua David and he briefly goes over his solution in this video, but elides most of the details.
A winner can be 4 in a row - either horizontally, vertically, or diagonally - or a square cluster of 4. Below is my attempt at writing this winner
function in both J and BQN.