Skip to content

Instantly share code, notes, and snippets.

View jdan's full-sized avatar
🐫
- : int -> int -> int = <fun>

Jordan Scales jdan

🐫
- : int -> int -> int = <fun>
View GitHub Profile
@jdan
jdan / README.md
Last active September 9, 2020 14:52
The houses puzzle

Problem

A certain street has between 50 and 500 houses in a row, numbered 1, 2, 3, 4, … consecutively. There is a certain house on the street such that the sum of all the house numbers to the left side of it is equal to the sum of all the house numbers to its right. Find the number of this house.

source

Solution

If there are k houses and we are at house n, we can relate k and n using the triangular numbers as follows:

@jdan
jdan / output.txt
Created May 25, 2020 17:34
Balanced parentheses with prolog
?- balanced_parens(Q).
Q = "" ;
Q = "()" ;
Q = "(())" ;
Q = "((()))" ;
Q = "(()())" ;
Q = "(((())))" ;
Q = "((()()))" ;
Q = "(()(()))" ;
Q = "(()()())" ;
@jdan
jdan / markov_svg.ml
Created December 8, 2019 23:53
drawing markov chains using ocaml
type point = int * int
type child =
| Line of point * point
| Arc of point * point * bool
type svg = { width : int
; height : int
; stroke : int
; zoom : float
@jdan
jdan / sets.ml
Last active December 3, 2019 18:12
module IntPairs = Set.Make (
struct
type t = int * int
let compare = compare
end
)
let () =
let ips = IntPairs.of_list [(1, 1); (1, 2); (2, 1); (1, 2)]
in
IntPairs.iter
@jdan
jdan / build.sh
Created August 23, 2019 22:04
some electron signing stuff
#!/bin/sh
mkdir App.iconset
sips -z 16 16 Icon1024.png --out App.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out App.iconset/icon_16x16@2x.png
sips -z 32 32 Icon1024.png --out App.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out App.iconset/icon_32x32@2x.png
sips -z 128 128 Icon1024.png --out App.iconset/icon_128x128.png
sips -z 256 256 Icon1024.png --out App.iconset/icon_128x128@2x.png
sips -z 256 256 Icon1024.png --out App.iconset/icon_256x256.png
#lang racket
(define (assert-equal a b)
(if (equal? a b)
(void)
(error "Assertion failure got" a "expected" b)))
(define-syntax-rule (s-cons a b) (lambda () (cons a b)))
(define (s-car stream) (car (stream)))
(define (s-cdr stream) (cdr (stream)))
@jdan
jdan / streams.js
Created May 3, 2019 14:18
Intro to the stream data structure in JS
const assert = require("assert");
// Utilities for building and using linked lists
const cons = (a, b) => [a, b];
const car = ([a, b]) => a;
const cdr = ([a, b]) => b;
function toArray(ls, acc = []) {
if (ls.length === 0) {
return acc;
}
@jdan
jdan / y
Last active May 22, 2020 17:51
(λ (f)
((λ (x) (f (x x)))
(λ (x) (f (x x)))))
@jdan
jdan / game.txt
Created June 13, 2018 20:22
flickgame
{"gameLink":"www.flickgame.org","canvasses":[[4430,"0",11,"5",147,"0",15,"5",135,"0",4,"5",5,"0",17,"5",126,"0",6,"5",1,"0",6,"5",3,"0",19,"5",124,"0",14,"5",3,"0",19,"5",94,"0",8,"5",21,"0",16,"5",1,"0",7,"5",7,"0",6,"5",68,"0",8,"5",17,"0",10,"5",20,"0",23,"5",9,"0",5,"5",65,"0",12,"5",2,"0",6,"5",7,"0",13,"5",16,"0",24,"5",10,"0",5,"5",64,"0",13,"5",1,"0",8,"5",5,"0",15,"5",14,"0",24,"5",9,"0",7,"5",63,"0",24,"5",3,"0",17,"5",12,"0",41,"5",63,"0",25,"5",2,"0",6,"5",4,"0",8,"5",11,"0",41,"5",63,"0",7,"5",3,"0",15,"5",1,"0",6,"5",6,"0",7,"5",10,"0",8,"5",1,"0",32,"5",64,"0",5,"5",5,"0",9,"5",1,"0",5,"5",1,"0",6,"5",5,"0",8,"5",10,"0",8,"5",1,"0",31,"5",65,"0",5,"5",5,"0",9,"5",1,"0",25,"5",10,"0",7,"5",2,"0",15,"5",1,"0",12,"5",67,"0",6,"5",5,"0",8,"5",2,"0",24,"5",11,"0",7,"5",2,"0",15,"5",80,"0",6,"5",5,"0",7,"5",3,"0",23,"5",12,"0",6,"5",3,"0",6,"5",1,"0",8,"5",80,"0",6,"5",5,"0",7,"5",3,"0",21,"5",14,"0",6,"5",3,"0",6,"5",1,"0",8,"5",80,"0",5,"5",6,"0",6,"5",4,"0",19,"5",16,"0",6,"5",3,"0",5,"5",2,"0",9,
@jdan
jdan / .zshrc
Created November 14, 2017 04:41
function shorthand() {
echo "${PWD/$HOME/~}" | tr "/" "\n" | cut -c 1 | tr "\n" "/" | rev | cut -c2- | rev
}
export PROMPT='%{$fg[cyan]%}$(shorthand)%{$reset_color%} $ '