⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
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
# Take a sequence of N numbers. We'll call the sequence a "Clean Chain of length N" | |
# if the sum of the first N - 1 numbers is evenly divisibly by the Nth number. | |
# For example, the sequence [2, 4, 6, 8, 10] forms a clean chain of length 5, | |
# since 2 + 4 + 6 + 8 = 20, which is divisible by 10, and the sequence has 5 numbers. | |
# The first clean chain formed out of the sequence of primes is simply [2], with length 1. | |
# The second is [2, 3, 5] with length 3. | |
# The third is [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, | |
# 53, 59, 61, 67, 71], with length 20 |
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
(1..100).map {|i| (fb = [["Fizz"][i%3],["Buzz"][i%5]].compact.join).empty? ? i : fb} |
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 lang="en"> | |
<head> | |
<!-- | |
normalize.css removes cross-browser differences in defaults, e.g., | |
differences in how form elements appear between Firefox and IE | |
See: http://necolas.github.com/normalize.css/ | |
--> | |
<link rel="stylesheet" href="normalize.css"> |
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 RPNCalculator | |
def initialize | |
@special_cases = [->(op, arr) {arr.include?('0') && op == '*' && '0'}, | |
->(op, arr) {arr.first == ('0') && op == '/' && '0'}, | |
->(op, arr) {arr.include?('1') && op == '*' && (arr-['1']).first}, | |
->(op, arr) {arr.include?('0') && op =~ /[+-]/ && (arr-['0']).first}] | |
end | |
def evaluate(*inputs) |
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 CalculatesRoute | |
def self.calculate(points) | |
remaining_points = points | |
route = [] | |
route << remaining_points.slice!(0) | |
until remaining_points == [] do | |
next_point = shortest_distance(route.last, remaining_points) | |
route << remaining_points.slice!(remaining_points.index(next_point)) |
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_relative 'geocoder' | |
require 'shoulda-matchers' | |
require 'geocoder' | |
require 'debugger' | |
class ActivityCluster | |
MAX_ROUTE_LENGTH = 4 | |
MAX_DISTANCE = 20 |
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
function justify(str, width) { | |
var whitespace = ' '; | |
while (str.length < width) { | |
var oldLength = str.length; | |
var spacing = new RegExp("(\\w)" + whitespace + "(\\w)"); | |
str = str.replace(spacing, '$1 ' + whitespace + '$2'); | |
if (oldLength === str.length) { | |
whitespace += ' '; | |
} | |
} |
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
characters = [ 'o', 'h', 'e', 'd', 'n', 'r', 'y', 'g', 'a', 'b', 'e' ] | |
positions = [ 1, 0, 4, 2, 6, 9, 8, 3, 7, 10, 5] | |
def rearrange(characters, positions) | |
positions.length.times do |i| | |
positions[i] = characters[positions[i]] | |
end | |
positions.each_with_index {|e, i| characters[i] = e} | |
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
def find_index(ary, index = 0) | |
midpt = ary.length / 2 | |
if midpt <= 1 | |
return ary.first < ary.last ? index : index + 1 | |
end | |
left, right = ary[0...midpt], ary[midpt..-1] | |
if left.last > left.first && ary.last < ary.first | |
index += midpt | |
find_index(right, index) | |
else |
OlderNewer