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
| 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 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 "stdafx.h" | |
| #include <memory.h> | |
| #include <map> | |
| void add( | |
| int *buffer, | |
| std::map<int,int>& plot, | |
| int key, | |
| int value) | |
| { |
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
| $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 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
| 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 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
| 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 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
| 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] |
NewerOlder