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
| 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 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
| 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
| 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
| 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
| (defun replace-rockets () | |
| (interactive) | |
| (goto-char (point-min)) | |
| (while (re-search-forward ":\\([_A-Za-z0-9]+\\)[\t\n ]+=>" nil t) | |
| (replace-match "\\1:"))) |
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 InfiniteCycleEnumerator | |
| def self.enum(num) | |
| Enumerator.new do |y| | |
| idx = 0 | |
| loop do | |
| y << idx % num | |
| idx = idx + 1 | |
| end | |
| end | |
| 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 Node | |
| attr_accessor :next | |
| attr_accessor :value | |
| def initialize(value) | |
| @next = nil | |
| @value = value | |
| end | |
| 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 'find' | |
| class Expression | |
| def |(other) | |
| Or.new(self,other) | |
| end | |
| def &(other) | |
| And.new(self,other) | |
| end |