Skip to content

Instantly share code, notes, and snippets.

code:
function Base.getindex{K}(t::TreapNode{K}, index::Int)
1 <= index <= t.size || throw(KeyError(key))
while t.left.size != index - 1
if index <= t.left.size
t = t.left
else
index = index - t.left.size - 1
t = t.right
@yurivish
yurivish / Treap.jl
Last active August 29, 2015 14:01
A Julia implementation of a treap (v6; in progress)
import Base: isempty, start, next, done, length, getindex, minimum, maximum, search, show
export Treap, TreapNode
type TreapNode{K}
priority::Float64
size::Int
key::K
left::TreapNode{K}
right::TreapNode{K}
@yurivish
yurivish / gist:10085175
Last active August 29, 2015 13:58
Artistic design with fractal matrices
NB. http://link.springer.com/article/10.1007%2FBF01908446#page-2
iter =: monad : '(2 * 0 1 { $ +/~y) $, +/~y'
m =: 2 3 $ 0 _4 1 1 _3 2
NB. random matrix with entries from _10 to 10:
NB. m =: 2 3 $ (? 6 $ 20) - 10
viewmat iter^:4 m
xs =: (i: 10) % 10
ys =: (i: 20) % 10
grid =: ys j./ xs
in =: 4 > |
out =: 1 - in
trim =: (* in) + (_ * out)
iter =: trim @ (+ *:)
require 'viewmat'