Skip to content

Instantly share code, notes, and snippets.

@scythe
scythe / gist:24a697b3c9059ed69d52
Created August 13, 2014 00:47
my terminal colors
<gconf>
<entry name="bold_color_same_as_fg" mtime="1406920645" type="bool" value="false"/>
<entry name="use_theme_colors" mtime="1406919946" type="bool" value="false"/>
<entry name="palette" mtime="1406928675" type="string">
<stringvalue>#1036069804A5:#858514144B4A:#2A2ABBBB3938:#7D7D99993030:#000044437777:#61600D0DC9C9:#3939CCCCAAA9:#BA06B314974C:#6C5F5FE3542B:#FFFF41413636:#0100FFFF7070:#FFFFDCDC0000:#00007473D9D9:#F0F01211BEBE:#6F6FDBDBFFFF:#F241F4E7D0FB</stringvalue>
</entry>
<entry name="alternate_screen_scroll" mtime="1406145628" type="bool" value="true"/>
<entry name="background_color" mtime="1406920886" type="string">
<stringvalue>#1036069804A5</stringvalue>
</entry>
--an implementation of smoothsort.
--the code is in a "monadic" style for fun.
--you should [probably] not actually code like this.
function leonardo(n)
local function lc(i, j, n)
return n > 1 and lc(j, i+j+1, n-1) or j
end
return lc(1, 1, n)
end
//big num library in Rust
static MD: int = 1000000000;
enum BigNumber {
End(int),
Segment(int, ~BigNumber, int)
}
fn make(val: int) -> ~BigNumber {
if(val > MD) { ~Segment(val/MD, ~End(val % MD), 1) }
@scythe
scythe / p357.lua
Created February 12, 2012 02:53
357
--Solves Project Euler problem 357.
function filltablesieve(lim, qf)
local sievetable = {}
for i = 1, lim do sievetable[i] = false end --use optimized tables
for i = 1, lim do
for j = i, lim / i, 1 do
sievetable[j * i] = sievetable[j*i] or qf(i, j)
end
end
@scythe
scythe / bezier.lua
Created June 27, 2011 16:02
de Casteljau's algorithm in lua metatables
--[[a parametric function describing the Bezier curve determined by given control points,
which takes t from 0 to 1 and returns the x, y of the corresponding point on the Bezier curve]]
function bezier(xv, yv)
local reductor = {__index = function(self, ind)
return setmetatable({tree = self, level = ind}, {__index = function(curves, ind)
return function(t)
local x1, y1 = curves.tree[curves.level-1][ind](t)
local x2, y2 = curves.tree[curves.level-1][ind+1](t)
return x1 + (x2 - x1) * t, y1 + (y2 - y1) * t
end
--a line from x1, y1 to x2, y2 as t varies from 0 to 1
function line(x1, y1, x2, y2)
return function(t)
return x1 + (x2 - x1) * t, y1 + (y2 - y1) * t
end
end
--the Bezier curve formed by interpolating between multiple given curves or lines
function curve(c1, c2, c3, ...)