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 pascal_calc(row_num) | |
if row_num == 0 | |
return [1] | |
end | |
previous = pascal_calc(row_num - 1) | |
ret = [] | |
(previous.length - 1).times do |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
DATA: lv_test TYPE STRING. |
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
type TheMap: Map[String, String] | |
// a and b really should have the same keys | |
// If not, entries from b will be lost. | |
def zipToTuples(a: TheMap, b: TheMap) = | |
(a.keys zip (a.values zip b.values)).toMap |
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 'priority_queue' | |
require 'set' | |
=begin | |
- solve the 8 puzzle | |
Basically, we have to treat each "State" as a node in the graph. | |
Add each 'move we can make' from the current state into the frontier | |
but only if we haven't visited it yet. |
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 Graph | |
def initialize | |
@nodes = {} | |
@edges = {} | |
end | |
def add_node(key, node) | |
@nodes[key] = node | |
@edges[key] = {} |
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 sort_and_count(array): | |
if len(array) <= 1: | |
return 0, array | |
mid = len(array) / 2 | |
left_array = array[0:mid] | |
right_array = array[mid:len(array)] | |
left_result = sort_and_count(left_array) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<canvas id="opponent_board" width="800" height="800"></canvas> | |
<script type="text/javascript"> | |
var canvas = document.getElementById('opponent_board'); | |
var context = canvas.getContext("2d"); |
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 String | |
def palindrome? | |
is_p = true | |
ch = self.gsub(/ /,"").chars.to_a | |
compares = ch.length / 2 | |
back_index = ch.length - 1 | |
compares.times do |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
# Don't let capybara reset sessions | |
# See : https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec.rb#L16 | |
module Capybara | |
class << self | |
alias_method :old_reset_sessions!, :reset_sessions! | |
def reset_sessions!; end | |
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
map <silent> <F3> :!clear && bundle exec rspec "%:p"<CR> |
NewerOlder