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 'set' | |
| class Coord | |
| attr_accessor :x, :y, :n | |
| def initialize(x, y, n) | |
| self.x = x | |
| self.y = y | |
| self.n = n | |
| 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
| require 'rubygems' | |
| require 'nokogiri' | |
| require 'eventmachine' | |
| require 'em-synchrony' | |
| require 'em-synchrony/em-http' | |
| if ARGV.length < 2 | |
| puts 'grab url path' | |
| exit | |
| 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
| data BinaryTree a = EmptyTree | Node a (BinaryTree a) (BinaryTree a) | |
| deriving (Show) | |
| treeInsert :: Ord a => a -> BinaryTree a -> BinaryTree a | |
| treeInsert el EmptyTree = Node el EmptyTree EmptyTree | |
| treeInsert el (Node a left right) | |
| | el == a = Node el left right | |
| | el < a = Node a (treeInsert el left) right | |
| | el > a = Node a left (treeInsert el right) |
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 BinaryTreeSet | |
| class Node | |
| attr_accessor :value | |
| attr_accessor :parent | |
| attr_accessor :right | |
| attr_accessor :left | |
| def initialize(value = nil) | |
| @value = value | |
| 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
| class BinaryTree | |
| class Node | |
| attr_reader :value | |
| attr_accessor :parent | |
| attr_accessor :right | |
| attr_accessor :left | |
| def initialize(value = nil) | |
| @value = value | |
| 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
| class Array | |
| def middle | |
| return self[self.length / 2] | |
| end | |
| def qsort | |
| return self.dup if size <= 1 | |
| l,r = partition { |x| x <= self.middle } | |
| c,l = l.partition { |x| x == self.middle } | |
| l.qsort + c + r.qsort |
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
| qsort :: Ord a => [a] -> [a] | |
| qsort [] = [] | |
| qsort (x:xs) = qsort lesser ++ [x] ++ qsort greater | |
| where | |
| lesser = filter (< x) xs | |
| greater = filter (>= x) xs |
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 PQueue | |
| def initialize | |
| @a = [] | |
| @heapsize = 0 | |
| end | |
| def left(i) | |
| 2 * i + 1 | |
| 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
| import Data.List | |
| swap :: Int -> Int -> [a] -> [a] | |
| swap i j xs | i == j = xs | |
| swap i j xs | otherwise = initial ++ (xs !! b) : middle ++ (xs !! a) : end | |
| where [a,b] = sort [i,j] | |
| initial = take a xs | |
| middle = take (b-a-1) (drop (a+1) xs) | |
| end = drop (b+1) xs |
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 Array | |
| def left(i) | |
| 2 * i + 1 | |
| end | |
| def right(i) | |
| 2 * i + 2 | |
| end | |
| def heapify(i, heapsize) |