Skip to content

Instantly share code, notes, and snippets.

View lgranger's full-sized avatar

Ray Granger lgranger

View GitHub Profile
@lgranger
lgranger / LtP2pt5
Last active September 25, 2015 17:43
# Instructions: Write a program that tells you the following:
# Hours in a year. How many hours are in a year?
def hrs_per_yr
puts "Is this a leap year?"
leap = gets.chomp
x = 0
while x == 0 do
if leap == "Yes" || leap == "yes" || leap == "Y" || leap == "y"
puts "There are #{366 * 24} hours in a leap year"
def food_time
cooking_type = ["steamed", "fried", "sautéed", "grilled", "poached", "raw", "skewered", "roasted", "pan fried", "baked", "oven roasted", "simmered in sauce", "boiled", "sliced", "pickled", "brined", "sun-dried", "dehydrated", "chopped", "broiled"]
main_food = ["tofu", "seitan steaks", "TVP", "Field Roast", "beans", "lentils", "tempeh", "edamame", "chickpeas", "cutlets"]
veg = ["carrots", "kale", "okra", "tomatoes", "potatoes", "chard", "squash", "zucchini", "pumpkin", "pearl onions"]
puts "Do you want some food? yes or no?"
want_food = gets.chomp
x = 1
if want_food == "yes"
@lgranger
lgranger / LtP5pt6.rb
Last active September 29, 2015 05:39
# Full name greeting. Write a program that askes for a person's first name, then middle, and then last. Finally, it should greet the person using their full name
puts "Hello!\nWhat is your first name?"
first_name = gets.chomp
puts "Nice to meet you #{first_name}.\nWhat is your middle name?"
middle_name = gets.chomp
puts "#{middle_name}, huh? Interesting.\n What is your last name?"
last_name = gets.chomp
puts "Well I'm pleased to meet you #{first_name} #{middle_name} #{last_name}!"
# "99 Bottles of Beer on the Wall." Write a program that prints out the lyrics to that beloved classic.
bottles = 99
while bottles != 2 do
puts "#{bottles} bottles of beer on the wall! #{bottles} bottles of beer! Take one down! Pass it around! #{bottles - 1} bottles of beer on the wall!\n"
bottles -= 1
end
puts "#{bottles} bottles of beer on the wall! #{bottles} bottles of beer! Take one down! Pass it around! #{bottles - 1} bottle of beer on the wall!\n"
bottles -= 1
puts "#{bottles} bottle of beer on the wall! #{bottles} bottle of beer! Take it down! Pass it around! No more bottles of beer on the wall!"
# Angry boss. Write an angry boss program that rudely asks you what you want. Whatever you answer, the angry boss should yell it back to you and then fire you.
puts "Huh? You again? What do you want!?"
want = gets.chomp.upcase
puts "WHAT?!!?!! YOU WANT \"#{want}\"!!??!! YOU'RE FIRED!!"
#Table of contents. Here's something for you to do in order to play around more with center, ljust, and rjust: write a program that will display a table of contents so that it looks like this:
page_width = 50
puts ("\"The Book Of Mad Skilz\"".center(page_width))
# Building and sorting an array. Write the program we talked about at the beginning of this chapter, one that asks us to type as many words as we want (one word per line, continuing until we just press Enter on an empty line) and then repeats the words back to us in alphabetical order. Make sure to test your program thoroughly; for example, does hitting Enter on an empty line always exit your program? Even on the first line? And the second? Hint: There’s a lovely array method that will give you a sorted version of an array: sort. Use it!
puts "Type as many lines as you want and I'll alphabetize them for you:"
my_array = Array.new
new_word = "a"
while new_word != ""
new_word = gets.chomp
my_array.push(new_word)
end
# Functions for preforming calculations
def addition(first_num, second_num)
puts "#{first_num} + #{second_num} = "
puts first_num.to_i + second_num.to_i
end
def subtraction(first_num, second_num)
puts "#{first_num} - #{second_num} = "
puts first_num.to_i - second_num.to_i
class Planet
attr_reader :name, :color, :size, :number_of_moons, :rotation, :distance_from_the_sun
def initialize(title, hue, how_big)
@name = title
@color = hue
@size = how_big
@number_of_moons = rand(0..3)
@rotation = title.length/2
class Planet
attr_reader :name, :color, :size, :number_of_moons, :rotation, :distance_from_the_sun, :rain
def initialize(planet_hash)
@name = planet_hash[:name]
@color = planet_hash[:color]
@size = planet_hash[:size]
@number_of_moons = rand(0..3)
@rotation = @name.length/2
class SolarSystem
require "./PlanetClass"
attr_reader :name, :planets
def initialize(name)
@name = name
@planets = []
end