Skip to content

Instantly share code, notes, and snippets.

View you-ssk's full-sized avatar

you-ssk you-ssk

  • Japan
  • 01:46 (UTC +09:00)
View GitHub Profile
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)
#include "stdafx.h"
#include <memory.h>
#include <map>
void add(
int *buffer,
std::map<int,int>& plot,
int key,
int value)
{
$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
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('-')
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|
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]