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 measure(in_a) | |
rule = { 0=>[-1, 0], 1=>[ 0,-1], 2=>[ 1 ,0], 3=>[ 0, 1] } | |
m = {0=>[0,0]} | |
in_a.each_with_index do |a,i| | |
b = m[a[0]] | |
d = a[1] | |
m[i+1] = [b[0]+rule[d][0],b[1]+rule[d][1]] | |
end | |
t = m.values.transpose | |
[t[0].max-t[0].min+1, t[1].max-t[1].min+1] |
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 Maze | |
def initialize(w,h,input) | |
@len_map = Hash.new | |
@len_map[[w-1,h-1]] = 1 | |
make_fence(input) | |
end | |
def make_fence(input) | |
lr, tb = [], [] | |
input.each_with_index do |e,i| |
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 format(a) | |
a.inject([a.shift]){|r,e| | |
if r[-1] == e-1 | |
r.pop(2) if r[-2] == '-' | |
r << '-' | |
else | |
r << ',' | |
end | |
r << e | |
}.join.squeeze('-') |
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
$tetra_num = Hash.new{|h,k| h[k] = k*(k+1)*(k+2)/6} | |
def tetra_array(n) | |
i,t = 1,[] | |
while n >= $tetra_num[i] | |
t << $tetra_num[i] | |
i += 1 | |
end | |
t | |
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
#include "stdafx.h" | |
#include <memory.h> | |
#include <map> | |
void add( | |
int *buffer, | |
std::map<int,int>& plot, | |
int key, | |
int value) | |
{ |
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
require 'pp' | |
def neighbor(s) | |
[[s[0],s[1]-1], | |
[s[0],s[1]+1], | |
[s[0]+1,s[1]], | |
[s[0]-1,s[1]]] | |
end | |
def upper(s) |
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
require 'scanf' | |
require 'pp' | |
class Node | |
def initialize(id) | |
@id = id | |
@edges = Array.new | |
@done = false | |
@word = nil | |
@from = nil |
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 "stdio.h" | |
#include "stdlib.h" | |
#include "string.h" | |
#include <algorithm> | |
int bs_enc(int len, char* input, int* index, char** bwt); | |
int bs_dec(int index, char* bwt, int len, char** output); | |
class CompEnc{ | |
public: |
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
require 'matrix' | |
def centroid points | |
base = points[0] | |
z = (points[1] - base).cross(points[2] - base).normalize | |
ds = [] | |
total_area = 0.0 | |
points.drop(1).each_cons(2) do |cons| | |
a, b = cons[0] - base, cons[1] - base | |
c = (base + cons[0] + cons[1])/3.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
require 'matrix' | |
def line_intersection line1, line2 | |
l1 = line1.map{|v|v.map(&:to_f)} | |
l2 = line2.map{|v|v.map(&:to_f)} | |
a = l1[1]-l1[0] | |
b = l2[1]-l2[0] | |
ab = l1[0]-l2[0] | |
cab = a.cross(b) | |
nA = b.cross(ab).dot(cab) |
OlderNewer