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 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 |
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 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 = [] |
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 'benchmark' | |
class String | |
def swap!(a,b) | |
self[a], self[b] = self[b], self[a] | |
self | |
end | |
end | |
string1 = "Pneumonoultramicroscopicsilicovolcanoconiosis" |
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 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") |
NewerOlder