Skip to content

Instantly share code, notes, and snippets.

@lynaghk
lynaghk / sketch systems grammar.md
Last active March 20, 2022 20:11
Sketch.systems grammar

Sketch.systems uses the wonderful Instaparse Clojure(Script) library to parse statechart specifications. Unfortunately, the current grammar is quite memory intensive and on larger specs suffers from multi-second garbage collection pauses.

Suggestions welcome!

@lynaghk
lynaghk / 1-readme.md
Created November 25, 2018 00:31
shipping puzzle in minizinc

First pass at shipping puzzle in MiniZinc. See https://kevinlynagh.com/notes/shipping-puzzle/

Runs in 2.5 seconds on my 2013 macbook air. Anything more than 7 routes takes more than a few minutes (and I stopped waiting).

I tried to improve perf by breaking symmetry in the rows of routes by ordering the routes according to the first leg. (i.e., the first non-zero value in a row of routes should be less than the first non-zero value of the next row of routes) But I couldn't figure out how to do that neatly.

1 LOS_ANGELES CHARLOTTE F
2 CHARLOTTE NEW_YORK W
3 NEW_YORK JACKSONVILLE F
4 JACKSONVILLE SAN_JOSE R
5 SAN_JOSE DETROIT T
6 DETROIT SEATTLE R
7 SEATTLE AUSTIN T
8 AUSTIN COLUMBUS W
9 COLUMBUS PHILADELPHIA T
10 PHILADELPHIA PHOENIX T
@lynaghk
lynaghk / gist:f6a25748ca748ddb122146eb7e2e3a3c
Created September 25, 2018 16:53
Sketch systems grammar EBNF
<statechart> = (state / <whitespace> / <comments>)+
state = comments? state-name <whitespace>? <newline> block?
transition = comments? event-name <whitespace>? <'->'> <whitespace>? state-name <newline>
<block> = indent (state / transition / <whitespace> / <comments>)+ dedent
comments = comment (<newline> comment)* <newline>
<comment> = <'#'> #".*"
@lynaghk
lynaghk / jug.als
Last active August 25, 2018 11:25
Another Alloy jug puzzle
open util/ordering[State]
sig Jug {
max: Int
}
abstract sig Op {}
sig Pour extends Op {
@lynaghk
lynaghk / SketchSystems.spec
Last active August 7, 2018 17:28
# Test parallel spec.
# Test parallel spec.
Search Inactive
touch search bar -> Search Active
Search Active&
touch cancel -> Search Inactive
touch result -> View Result
text input -> Loading
@lynaghk
lynaghk / sudoku.als
Created July 18, 2018 11:39
Solving sudoku in alloy
enum V {v1, v2, v3, v4, v5, v6, v7, v8, v9}
sig Cell {
val: V,
row: V,
col: V
}
pred disjointSubgrid[rows: set V, cols: set V]{
@lynaghk
lynaghk / SketchSystems.spec
Created July 2, 2018 12:24
LoadingAnimation
LoadingAnimation
Loading
next -> AlmostDone
AlmostDone
next -> Finished
Finished
next -> App
App
@lynaghk
lynaghk / 0_readme.md
Last active June 27, 2018 11:13
Solving water pouring puzzle with Alloy

Water pouring puzzle

Given a 5 quart jug, a 3 quart jug, and unlimited supply of water, can you measure exactly 4 quarts? (The jugs are irregularly shaped, so you can't eyeball half the volume or anything like that.)

The solution involves pouring water between the jugs.

I wanted to see if I could solve this puzzle with Alloy. My first attempt (specific.als) hardcodes the two jugs as named relations. It solves the puzzle (finds a counterexample) in about 500ms.

@lynaghk
lynaghk / SketchSystems.spec
Last active June 19, 2018 11:25
Commenting
Commenting
# Comments are associated with the state/transition directly below them.
# Hover over the red circle in the diagram to read the comment as a tooltip.
A
B
C