This file contains hidden or 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
--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, ...) |
This file contains hidden or 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
--[[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 |
This file contains hidden or 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
--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 |
This file contains hidden or 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
//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) } |
This file contains hidden or 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
--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 |
This file contains hidden or 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
<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> |
This file contains hidden or 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
re = require "re" | |
local function condense(keyvals) | |
local obj = {} | |
for i = 1, #keyvals do | |
obj[keyvals[i][1]] = keyvals[i][2] | |
end | |
return obj | |
end |
This file contains hidden or 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
--Rich Hickey's infamous transducers, demonstrating reversed function composition. | |
--Look closely. | |
function transduce(tf, rf, init, iter) | |
for i in iter do | |
init = tf(rf)(init, i) | |
end | |
return init | |
end |
This file contains hidden or 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
/* STR_VA_ARG(...) -- convert variadic arglist to strings | |
* Usage: STR_VA_ARG(phnglui, mglwnafh, cthulhu, rlyeh, wgahnagl, fhtagn) | |
* >> "phnglui", "mglwnafh", "cthulhu", "rlyeh", "wgahnagl", "fhtagn" | |
*/ | |
#ifndef __VA_STRINGIFY_H | |
#define __VA_STRINGIFY_H | |
#define PP_NARG(...) \ | |
PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) |
This file contains hidden or 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
f = {[0] = 1} | |
m = {[0] = 0} | |
len = 100000000 | |
for i = 1, len do | |
m[i] = i - f[m[i-1]] | |
f[i] = i - m[f[i-1]] | |
end |
OlderNewer