Skip to content

Instantly share code, notes, and snippets.

View durrellchamorro's full-sized avatar

Durrell Chamorro durrellchamorro

  • Fleetio
  • 18:43 (UTC -05:00)
View GitHub Profile
@durrellchamorro
durrellchamorro / sieve.rb
Last active November 21, 2015 03:01
Sieve of Eratosthenes
class Sieve
def initialize(limit)
@number_list = (2..limit).to_a
end
def primes
prime_numbers = []
until @number_list.empty?
prime_numbers << @number_list.first
@number_list -= multiples_of @number_list.first
class Series
attr_reader :digits
def initialize(string_of_digits)
@digits = string_of_digits.chars.map(&:to_i)
end
def slices(slice_size)
fail ArgumentError, "Slice size cannot exceed caller's digit size." if slice_size > digits.size
result = []
@durrellchamorro
durrellchamorro / reverse.rb
Created November 6, 2015 17:12
Three Approaches To Reversing A String
require 'benchmark'
class String
def swap!(a,b)
self[a], self[b] = self[b], self[a]
self
end
end
string1 = "Pneumonoultramicroscopicsilicovolcanoconiosis"
@durrellchamorro
durrellchamorro / queen_attack.rb
Last active November 8, 2015 08:18
Queen Attack Solution
class Queens
attr_reader :white, :black
def initialize(white: [0, 3], black: [7, 3])
@white, @black = white, black
fail ArgumentError, "Queens cannot occupy the same position." if white == black
end
def to_s
mark_board.map { |row| row.join(" ") }.join("\n")