Skip to content

Instantly share code, notes, and snippets.

@mwsage
mwsage / gist:7030768
Created October 17, 2013 19:25
1 on 1 with sherif - built a ball passing game and has some self notes
# in this universe, player will throw a frisbee which will track how far it flies and report progress along the way
class Player
attr_reader :name
attr_accessor :already_had_the_ball
@@player_count = 0
def initialize(name)
@name = name
@@player_count += 1
@mwsage
mwsage / gist:7002615
Created October 16, 2013 04:20
drawer object work with brick -- brickout
class Drawer
attr_reader :contents
def initialize
@contents = []
@open = true
end
def open
@mwsage
mwsage / gist:6945907
Created October 12, 2013 04:42
sudoku
class Sudoku
def initialize(board_string)
@sudoku_board = board_string.split(//).each_slice(9).to_a
p @num_zeros = board_string.split('').count('0')
end
def get_row(row_index, column_index)
@sudoku_board[row_index]
end
@mwsage
mwsage / gist:6928806
Last active December 25, 2015 05:59
thursday racer productivity
require_relative 'racer_utils'
class RubyRacer
attr_accessor :players, :length, :lane
def initialize(players, length = 30)
@players = players
@length = length
@die = Die.new
@mwsage
mwsage / gist:6896635
Created October 9, 2013 05:29
destructive message using regex tools
def destroy_message(string)
stop_here = string =~ /:/ #returns the index of ":"
if stop_here
string[0..stop_here] #returns string from 0 to 9 (which is index of ":")
else
string
end
end
@mwsage
mwsage / gist:6893633
Created October 8, 2013 23:30
enumerable methods
# TODO: Print the elements at indices 1, 3, 5, 7, etc. on separate lines.
# You should make use of Enumerable#each_with_index
def print_odd_indexed_integers(array)
array.each_with_index {|num, index| puts num if index % 2 != 0}
end
# TODO: Return the odd numbers from a list of integers.
# You should make use of Enumerable#select
def odd_integers(array)
array.select {|num| num.odd?}
@mwsage
mwsage / gist:6892761
Created October 8, 2013 22:17
pig latin
def pig_latin(word)
word.downcase!
word_arr = word.split('')
until word_arr[0] == "a" || word_arr[0] == "e" || word_arr[0] == "i" || word_arr[0] == "o" || word_arr[0] == "u" || word_arr[0] == "y"
f = word_arr.shift
word_arr.push(f)
def old_numerals(number)
(number / 1000).times do print "M" end
five_hundred = number % 1000
#puts five_hundred
(five_hundred / 500).times do print "D" end
one_hundred = five_hundred % 500
#puts one_hundred
@mwsage
mwsage / gist:6877072
Last active December 24, 2015 22:59
dictionary sort
puts "enter some words"
words = gets.chomp.split.sort!
puts "Congratulations! Your dictionary has #{words.length} words"
words.each do |x|
puts x
end
@mwsage
mwsage / gist:6876880
Created October 7, 2013 23:34
deaf grandma with ben
def deaf_grandma(state = true, greeting = true, steps = 0)
if steps == 2
puts "Bye dear"
state = false
end
puts "Hello, little boy." if greeting == true
if state
user_input = gets.chomp
if user_input == "I love ya, Grandma, but I've got to go."
puts "Bye, dear."