Skip to content

Instantly share code, notes, and snippets.

View samtalks's full-sized avatar

Sam Yang samtalks

View GitHub Profile
@samtalks
samtalks / gist:6707289
Created September 25, 2013 22:50
HW given on 9/25
FizzBuzz part 1
def fizzbuzz(until_num)
i = 1
while i <= until_num do
if i % 3 == 0 && i % 5 == 0
puts "FizzBuzz"
elsif i % 3 == 0
puts "Fizz"
elsif i % 5 == 0
puts "Buzz"
songs = [
"The Magnetic Fields - 69 Love Songs - Parades Go By",
"The Magnetic Fields - Get Lost - Smoke and Mirrors",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
"The Magnetic Fields - Get Lost - You, Me, and the Moon",
"The Magnetic Fields - 69 Love Songs - The Book of Love",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - The King of Carrot Flowers"
]
@samtalks
samtalks / speakers.rb
Created September 27, 2013 01:18
HW on 9/26. Speakers and Room assignments
# You're hosting a conference and need to print badges for the speakers. Each badge should say: "Hello, my name is _____."
# Write a method that will create and return this message, given a person's name.
def badge(name)
puts "Hello, my name is #{name}."
end
# Now the list of speakers is finalized, and you can send the list of badges to the printer. Remember that you'll need to give this list to the printer, so it should be accessible outside of the method.
speaker_list = %w(John Mike Liz Harry Betty)
@samtalks
samtalks / different_ways.rb
Created September 27, 2013 03:41
9/26 HW: Different ways to...
# Let's go back to the exercise where we determined what is and isn't a vowel. With ruby, there's always more than one way to do something and get the same result.
# Assuming vowels a,e,i,o,u:
# Write a method that returns whether a given letter is a vowel, using if and elsif
def is_vow(letter)
if letter == "a"
true
elsif letter == "e"
true
elsif letter == "i"
true
@samtalks
samtalks / normalized_phone.rb
Created September 27, 2013 14:22
Morning lab 9/27
# Download this file:
# https://gist.github.com/scottcreynolds/ac1b5c8d96de0c91bf7c/download
# Run it from your terminal with:
# ruby ruby_phone_format.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
# Download Gist: https://gist.github.com/scottcreynolds/e6534b284373efe0ba6e/download
# Build a Jukebox
# create a file jukebox.rb
# When that program is run, it should introduce itself
# to the user and accept input from the user using the gets command.
# The jukebox should respond to 4 commands, help, play, list and exit.
# The help command should output instructions for the user
# on how to use the jukebox.
# The list command should output a list of songs that the
# Apple picker
# Create a method, apple_picker, that will pick all the apples out of an array. Implement it with collect and then implement it with select. Write a sentence about how select differs from collect.
def apple_picker(fruits)
answer = []
# You need to program the "Take a Number" feature for a deli. At the start, the deli is empty and is represented by an empty array.
# Build a method that a new customer will use when entering our deli. The method, take_a_number, should accept the current line of people, along with the new person's name, and return their position in line (and no 0 index, these are normal people, if they are 7th in line, tell them that, not 6).
def take_a_number(place, person)
place << person
place.length.to_s
end
# Build a method now_serving. This method should call out (via puts) the next person in line and remove them from the line.
# Movie collection by genre
movies = {
:animation => ["Incredibles", "Little Mermaid", "Cars"]
:comedy => ["Zoolander", "Groundhog Day"],
:drama => ["Little Women", "JFK", "Black Stallion"]
}
# Recipes with ingredients
# Holiday suppliers
# You have a bunch of decorations for various holidays organized by season.
holiday_supplies = {
:winter => {
:christmas => ["Lights", "Wreath"],
:new_years => ["Party Hats"]
},
:summer => {
:forth_of_july => ["Fireworks", "BBQ"]