Skip to content

Instantly share code, notes, and snippets.

View mindplace's full-sized avatar
🎯
Focusing

Esther Leytush mindplace

🎯
Focusing
View GitHub Profile
@mindplace
mindplace / block_problems_spec.rb
Created January 14, 2016 14:27
RSpec for block problems
require "rspec"
require "block_problems"
describe "#doubler" do
let(:array) { [1, 2, 3] }
it "doubles the elements of the array" do
expect(doubler(array)).to eq([2, 4, 6])
end
@mindplace
mindplace / block_problems.rb
Created January 14, 2016 14:27
Block problems to work on block passing
# ### Bubble Sort
#
# http://en.wikipedia.org/wiki/bubble_sort
#
# Implement Bubble sort in a method, `Array#bubble_sort!`. Your method should
# modify the array so that it is in sorted order.
#
# > Bubble sort, sometimes incorrectly referred to as sinking sort, is a
# > simple sorting algorithm that works by repeatedly stepping through
# > the list to be sorted, comparing each pair of adjacent items and
@mindplace
mindplace / comp_class.rb
Created January 14, 2016 19:57
computer class for tic tac toe
class ComputerPlayer
def initialize(name, mark=0)
@name = name
@mark = mark
end
def name
@name
end
@mindplace
mindplace / human_class.rb
Created January 14, 2016 19:58
human player for tic tac toe
class HumanPlayer
def initialize(name, mark=0)
@name = name
@mark = mark
end
def name
@name
end
@mindplace
mindplace / board.rb
Created January 14, 2016 20:01
board class for tic tac toe
class Board
def initialize(grid=[[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]])
@grid = grid
end
def grid
@grid
end
def place_mark(position, symbol)
@mindplace
mindplace / mastermind.rb
Created January 18, 2016 20:55
Mastermind
class Code
attr_reader :pegs
def initialize
@pegs = random
end
def random
colors = ["R", "G", "B", "Y", "O", "P"]
[colors[rand(6)], colors[rand(6)], colors[rand(6)], colors[rand(6)]].join
end
@mindplace
mindplace / in_words.rb
Created January 20, 2016 05:35
TestFirstRuby - In Words problem
class Fixnum
def ones_place(integer)
portion = integer.to_s[-1].to_i
teen_test = integer.to_s[-2..-1].to_i
teenager = true if (teen_test > 10 && teen_test < 20)
return "" if portion == 0 || teenager
ones(portion)
end
def tens_place(integer)
@mindplace
mindplace / battleship.rb
Created January 23, 2016 18:52
Battleship
class HumanPlayer
attr_accessor :name
def get_play
gets.chomp.split(",").map{|item| item.to_i}
end
def prompt
puts "Where do you want to fire? (Input like this: 2,3)\n>\n"
end
def merge_sort(array)
total_length = array.length
size = 2
while size < total_length + 1
sorted_array = []
array.each_slice(size).to_a.each do |group|
slice1 = group[0...(group.length / 2)]
slice2 = group[(group.length / 2)..-1]
combined = []
def selection_sort(array)
array.each_index do |i|
break if i == array.length - 1
current = array[i]
smaller = array[i]
smaller_index = i
array.each_with_index do |item, j|
next if j <= i