Skip to content

Instantly share code, notes, and snippets.

class MovieFlight
def self.length(flight_length, movie_length)
movie_length.each_with_index do |movie, index|
remaining_time = (flight_length - movie)
movie_length.each_with_index do |m, i|
if remaining_time - m == 0 && index != i
return true
end
end
require "colorize"
require "pry"
POSSIBLE_SOLUTIONS = [
["r", "e", "d"],
["b", "l", "u", "e"],
["o","r", "a", "n", "g", "e"]
]
class Dragon
def initialize(name, color = "rainbow")
@name = name.capitalize
@asleep = false
@in_belly = 10 # is full
@in_intenstine = 0 # doesn't need to poo
@hydrated = 10 # this is level of drunken-ness (yes, our dragon drinks whiskey)
@color = color
if @color == "rainbow" # adding abilities based on color
class Planets
attr_accessor :name, :pop_by, :diameter, :distance_from_sun, :planets, :good_for_humans
def initialize(planet_hash, good_for_humans = true)
@name = planet_hash[:name]
@pop_by = planet_hash[:pop_by]
@diameter = planet_hash[:diameter]
@distance_from_sun = planet_hash[:distance_from_sun]
@good_for_humans = planet_hash[:good_for_humans]
end
# define class
class Planet
attr_accessor :name, :pop_by, :avg_temp, :color, :rate_solar_rotation, :distance_from_sun, :planets, :add_planet, :print_planets
def initialize(name, pop_by, avg_temp, color)
@name = name.capitalize
@pop_by = pop_by
@avg_temp = avg_temp
@color = color
end
# any input that's not within my calculator's parameters calculates to "nonsense"
answer = "nonsense"
puts "Please enter an operation (such as add, -, *, divide, exponent, %): "
user_op = gets.chomp.downcase
puts "Please enter a number: "
num_one = gets.chomp
puts "Please enter a number: "
# building and sorting an array
puts "We're going to play a game!"
puts "You're going to list off words."
puts "When you're done, hit the enter button on a blank line."
puts "I'll tell you which words you listed, in alphabetical order."
words = []
answer = 0
# 99 bottles of beer on the wall
count = 99
(99).times do
if count > 1
puts "#{count} bottles of beer on the wall,"
puts "#{count} bottles of beer."
puts "Take one down, pass it around,"
puts "#{count-1} bottles of beer on the wall!"
puts ""
@hougland
hougland / 6_2.rb
Last active January 15, 2016 19:23
# 6.2 part 1
puts "WHAT DO YOU WANT? I AM YOUR BOSS!!!"
print "> "
answer = gets.chomp.upcase
puts "WHAT DO YOU MEAN \"#{answer}\"?!? YOU'RE FIRED!!"
# 6.2 part 2
puts "What's your first name?"
puts ">"
first_name = gets.chomp
puts "What's your middle name?"
puts ">"
middle_name = gets.chomp