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
#include <stdio.h> | |
unsigned long fib1(unsigned long n) | |
{ | |
return n < 2 ? 1 : fib1(n - 1) + fib1(n - 2); | |
} | |
unsigned long fib2(unsigned long n, unsigned long m) | |
{ | |
return n < 2 ? 1 : fib2(n - 1, m) + fib2(n - 2, m); |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#import <CoreFoundation/CoreFoundation.h> | |
#define KEYSIZE (10 + 1 + 1) | |
int main() | |
{ |
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
# Computes conjugate transpose of M | |
let conjTransp = function conjTransp(M) { | |
return map(range(sizeof M[0]), function(row) { | |
return map(range(sizeof M), function(col) { | |
return cplx_conj(M[col][row]); | |
}); | |
}); | |
}; | |
# Helper for cplxMatMul |
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
#!/usr/local/bin/spn | |
# Playing around with differential geometry is fun! | |
let derivative = function derivative(fn) { | |
return function(x0) { | |
let f = fn; | |
let dx = 1.0e-5; | |
let x = x0 + dx; | |
let y0 = f(x0), y = f(x); |
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
// | |
// WARNING: | |
// a "Greeter" class is a typical BAD example, | |
// an anti-pattern. You shouldn't be making this | |
// a class IRL. I've only come up with this | |
// example because I've run out of creative sauce. | |
// | |
function Greeter(msg) { | |
var self = { |
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
function curry(fn) { | |
let curry_argc = argc - 1; | |
var curry_args = {}; | |
for var i = 0; i < curry_argc; i++ { | |
curry_args[i] = #i; | |
} | |
return function() { | |
for var i = 0; i < argc; i++ { |
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
function rrot(a, begin, k) { | |
var n = k - 1; | |
var tmp = a[begin + n]; | |
for var i = n; i > 0; i-- { | |
a[begin + i % k] = a[begin + (i - 1) % k]; | |
} | |
a[begin] = tmp; | |
} | |
function toFact(n, ndigs) { |
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
// | |
// bf.spn | |
// a Brainfuck parser and interpreter in Sparkling | |
// | |
// by Arpad Goretity (H2CO3) | |
// The "zeroise" optimization is based on the idea of Daniel Silverstone | |
// run as: spn bf.spn foo.bf | |
// | |
global ins_incrmt = 0, |
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
var six_factorial = function(f, x) { | |
return f(f, x); | |
}(function(f, x) { | |
return x < 2 ? 1 : x * f(f, x - 1); | |
}, 6); |
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
// | |
// derive.c | |
// just because | |
// (just because I wanted to demonstrate what the Sparkling API is good for) | |
// | |
// created by H2CO3 on 31/01/2014 | |
// use for good, not for evil | |
// | |
#include <stdio.h> |