This file contains 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
def recursive(n) | |
if n < 3 | |
n | |
else | |
recursive(n - 1) + | |
2 * recursive(n - 2) + | |
3 * recursive(n - 3) | |
end | |
end |
This file contains 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
# Returns an array representing a specific level of Pascal's triangle | |
def pascal1(n) | |
if n == 1 | |
[1] | |
else | |
nl = [0] + pascal1(n-1) + [0] | |
l = [] | |
(nl.size - 1).times do |i| | |
l << nl[i] + nl[i+1] | |
end |
This file contains 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
# Iterative O(log n) exponentiation | |
def fast_expt(b, n) | |
a = 1 | |
while n > 0 | |
if even?(n) | |
n /= 2 | |
b *= b | |
else | |
n -= 1 | |
a *= b |
This file contains 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
def even?(n) | |
n % 2 == 0 | |
end | |
def fast_mult(b, n) | |
if n == 0 | |
0 | |
elsif even?(n) | |
fast_mult(b, n / 2) * 2 | |
else |
This file contains 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
def even?(n) | |
n % 2 == 0 | |
end | |
def fast_mult(b, n) | |
a = 0 | |
while n > 0 | |
if even?(n) | |
n /= 2 | |
b *= 2 |
This file contains 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
# Fibonacci numbers in logarithmic time | |
def even?(n) | |
n % 2 == 0 | |
end | |
def fib(n) | |
a = 1 | |
b = 0 |
This file contains 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 <event.h> | |
#include <evhttp.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <sys/time.h> | |
typedef struct { | |
const char * uri; | |
struct evhttp_request * ev_req; |
This file contains 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
class Scanner | |
class << self | |
attr_accessor :p, :marker, :line, :line_marker, :data, :output | |
end | |
%%{ | |
machine scanner; | |
variable p self.p; | |
variable data self.data; |
This file contains 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
--- src/http/modules/ngx_http_image_filter_module_old.c 2010-09-01 17:02:17.000000000 -0700 | |
+++ src/http/modules/ngx_http_image_filter_module.c 2010-09-01 17:06:17.000000000 -0700 | |
@@ -16,6 +16,7 @@ | |
#define NGX_HTTP_IMAGE_SIZE 2 | |
#define NGX_HTTP_IMAGE_RESIZE 3 | |
#define NGX_HTTP_IMAGE_CROP 4 | |
+#define NGX_HTTP_IMAGE_BOX 5 | |
#define NGX_HTTP_IMAGE_START 0 |
This file contains 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
from llvm import * | |
from llvm.core import * | |
m = Module.new('lisp') | |
main = m.add_function(Type.function(Type.int(), []), "main") | |
main_block = main.append_basic_block('entry') | |
b = Builder.new(main_block) | |
class ReferenceNotFound(Exception): | |
pass |