Skip to content

Instantly share code, notes, and snippets.

View samtalks's full-sized avatar

Sam Yang samtalks

View GitHub Profile
def reverse_each_word(sentence)
arr = []
sentence.split.map do |word|
reversed = ""
i = 0
while i < word.length
reversed << word[word.length-(i+1)]
i += 1
# sam's algorithm for solving these.
# first, lay out three panels: screen shot of data below, bash window, & subl for visualization
# second, drill down carefully solving for entire set of a kind for results
# third, apply the 'filter' or the conditional to narrow results
game = {
:home => { :team_name => "Charlotte Hornets",
:colors => ["Turquoise", "Purple"],
:players => [
def create_groups(source, students, groups)
arr, src = [], source.shuffle
(students*groups/41+1).times {arr += src}
arr.slice!(((students*groups)-arr.size)..-1)
arr.each_slice(students).to_a
end
def get_students
pigeons = []
pigeon_list = {}
pigeon_data.each {|props, vals| pigeon_data[props].
each {|prop, bird_set| pigeons += bird_set}}
pigeons.uniq!
pigeons.each do |pigeon|
pigeon_list[pigeon] = {:color => [], :gender => "", :lives => ""}
pigeons = []
pigeon_list = {}
pigeon_data.each {|properties, properties_hash| pigeon_data[properties].
each {|property, birds| pigeons += birds}}
pigeons.uniq!
pigeons.each do |pigeon|
pigeon_list[pigeon] = {:color => [], :gender => "", :lives => ""}
pigeon_data.each do |properties,properties_hash|
@samtalks
samtalks / school.rb
Last active December 25, 2015 01:29
class School
attr_accessor :roster
def initialize(school)
@roster = {}
end
def add_student(name, grade)
@roster[grade] ||= []
@roster[grade] << name
ArgumentError: wrong number of arguments (2 for 1)