Skip to content

Instantly share code, notes, and snippets.

def prime(number)
remainders = []
(2..number-1).each do |i|
remainders << (number % i).to_i
end
puts remainders.none? {|i| i == 0}
end
number = gets.chomp.to_i
prime number
@Jaltman429
Jaltman429 / gist:5754369
Created June 11, 2013 03:47
hashketball
# Hashketball Nests
#
# Great news! You're going to an NBA game! The only catch is that you've been
# volunteered to keep stats at the game.
#
# Using Nested Hashes, define a game, with two teams, their players, and the players stats:
#
# The game has two teams.
#
# A team has:
@Jaltman429
Jaltman429 / gist:5752646
Created June 10, 2013 21:44
tempbot.rb
# Temperature bot is American but takes Celsius temperatures.
#
def temperature_bot(temp)
case temp
when temp = 18,21,22
"I like this temperature"
else
"This is uncomfortable for me"
end
end
puts "Hello World".reverse
puts "Hello World".reverse.upcase
puts "Hello World".reverse.upcase.split
puts "Hello World".reverse.upcase.split.join(" ")
puts "Hello World".reverse.upcase.split.join(" ").reverse
puts "Hello World".reverse.upcase.split.join(" ").reverse.capitalize
puts "Hello World".reverse.upcase.split.join(" ").reverse.capitalize.concat('!')
# Construct an array with your favorite foods. It should have at least 5 elements.
# Write a puts which returns your most favorite food out of the array.
favorite_foods = ['pizza', 'bagel', 'sandwich', 'chicken', 'apple']
favorite_foods.each_with_index do |food, index|
puts (index + 1).to_s + ". " + food.capitalize
end
puts "Which is your favorite food? Please pick a number."
# Create Hashes for the following use-cases.
# A movie collection that organizes by genres
# Recipes with ingredients
# User profiles where each user has a list of favorite colors along with 3
# personal essays, essay_1, essay_2, essay_3
# Just be creative, create a bunch of fake data just for the practice of how you would
# store this data in a structured hash. Feel free to create a single file, hashes.rb with
# a bunch of these and send them to me for review. There are really no wrong answers -
@Jaltman429
Jaltman429 / gist:5750855
Created June 10, 2013 17:57
Jukebox.rb (as a class)
# jukebox.rb
class Jukebox
@@jukeboxes = []
def initialize (name)
@@on = true
@name = name
@user_tracks = []
@user_tracks << @name
@Jaltman429
Jaltman429 / gist:5745408
Created June 9, 2013 21:51
fizzbuzz.rb
# assignment.rb
# FizzBuzz - The Programmer's Stairway to Heaven
# Define the fizzbuzz method to do the following: 10pts
# Use the modulo % method (divisible by)
# 2 % 2 #=> true
# 1 % 2 #=> false
# If a number is divisible by 3, puts "Fizz".
# If a number is divisible by 5, puts "Buzz".
# If a number is divisible by 3 and 5, puts "FizzBuzz"
# assignment.rb
#
# write an expression that returns true by using ==
# write an expression that returns false using ==
# write an expression that returns true using !=
# write an expression that returns false using !=
puts 4 == 2 * 2
puts 'jack' == 'JACK'
puts 'jack' != 'blob'
@Jaltman429
Jaltman429 / gist:5701846
Last active December 18, 2015 01:09
Alien PB&J
DELIVERABLE: Create a numbered list that contains instructions for making a peanut butter and jelly sandwich.
FORMAT: Link to Public Gist
AUDIENCE:
Tourist Alien
CONSIDERATIONS:
The alien is positioned in front of a table with a plate, a knife, a jar of jelly, a jar of peanut butter, and a loaf of bread.
The alien can read and recognize english and english grammar, but does not necessarily understand what specific nouns refer to in the real world.