Skip to content

Instantly share code, notes, and snippets.

function arrayOfLight(x){
var output = [];
for (i = 0; i < x +1; i++){
output.push(i);
}
return output;
}
SELECT isbn FROM editions
where publisher_id = 59
@joshuastr
joshuastr / barracks.rb
Created May 4, 2016 17:00
Warcraft Barracks 3
class Barracks
attr_reader :gold, :food
def initialize
@gold = 1000
@food = 80
@footman_training_gold = 135
@footman_training_food = 2
@peasant_training_gold = 90
Regarding the self convention, within both a class method, and the class itself, 'self' refers to the given class, however when called
within an instance method, self refers to a specific instance of that class.
@joshuastr
joshuastr / animals_inheritance.rb
Created May 2, 2016 22:37
Animals Inheritance
#require './animals_module'
module CanFly
def fly
puts "I'm a #{self.class.name}, and I can fly"
end
end
class Animal
### SETUP
require 'rspec'
### LOGIC (fix me)
class HelloWorld
def hello
@hello
end
@joshuastr
joshuastr / 1_hello_world.rb
Created May 2, 2016 13:15
Debugging with rspec
### SETUP
require 'rspec'
### LOGIC (fix me)
class HelloWorld
def hello
@hello
end
@joshuastr
joshuastr / pop_bottles.rb
Created April 30, 2016 20:02
Pop Bottles
# You've just been hired at Lighthouse Markets, a reputable (and thoroughly fictional) grocery store chain.
# One of the primary features of Lighthouse Markets is their recycling program on pop bottles. Here is how the program works:
# For every two empty bottles, you can get one free (full) bottle of pop
# For every four bottle caps, you can get one free (full) bottle of pop
# Each bottle of pop costs $2 to purchase
# Given these parameters, write a program so that you can figure out how many total bottles of pop can be redeemed given a customer investment.
p 'Welcome to Lighthouse Pop Bottle Recycling Program, Bottles are $2 each, how many would you like to purchase?'
init_investment = gets.chomp.to_i
@joshuastr
joshuastr / math_game
Created April 29, 2016 22:43
Two Player Game
# Create a 2-player guessing game where players take turns to answer simple addition problems.
#The math questions are automatically generated.
#It should do this by picking two numbers between 1 and 20.
# Example prompt: "Player 1: What does 5 plus 3 equal?"
# Both players start with 3 lives. They lose a life if they mis-answer a question.
#If a player gets a question wrong, the game should output the new scores for both players, so players know where they stand.
# The game doesn’t end until one of the players loses all their lives.
#At this point, the game should announce who won and what the other player’s score is.
# As before, you can use gets.chomp to get input from users and puts for output.
@joshuastr
joshuastr / math_game_classes
Created April 29, 2016 22:40
OO Math Game
# Player Class
# You will have a Player class, where you will put all of your Player-specific logic and properties.
# Your program will still have to keep track of whose turn it is, and check players' scores and lives.
# Methods
# Your Player class should have instance methods for the following tasks:
# gain a point
# lose a life