This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
directory = '/Users/kevinbuchanan/Music' | |
Dir.chdir directory | |
playlist = {} | |
while true | |
puts 'Enter a song name to add to the playlist: (Press enter when done)' | |
song = gets.chomp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This program dispalys LCD-style numbers in terminal. | |
# Digits to be displayed are passed as an argument from the command line. | |
# Size can be controled with the command-line option -s followed by a positive integer. | |
# example: $ ruby lcd_numbers.rb -s 5 1234 | |
class LCDNumber | |
def initialize (digits, size = 2, h_char = '-', v_char = '|' ) | |
@digits = digits.split(//) | |
@size = size | |
@h_char = h_char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Randomly assigns secret santas. Will not match up two people with the same last name. | |
class SecretSanta | |
attr_accessor :names | |
def initialize(names_array) | |
@names = names_array.map { |name| name.split(' ') } | |
raise "Odd number of names!" if @names.size.odd? | |
@assignments = {} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Asteroid | |
attr_accessor :x, :y, :z, :connections | |
LIMIT = 150 | |
def initialize(x, y, z, vx, vy, vz) | |
@x, @y, @z = x, y, z | |
@vx, @vy, @vz = vx, vy, vz | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vehicle | |
attr_reader :wheels, :color, :gas_mileage | |
attr_accessor :status, :speed | |
def initialize(args) | |
@wheels = args[:wheels] | |
@color = args[:color] | |
@status = :stopped | |
@speed = 0 | |
@gas_mileage = [true, false].sample | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node | |
attr_accessor :value, :left, :right | |
def initialize(value, left = nil, right = nil) | |
@value, @left, @right = value, left, right | |
end | |
def delete(node) | |
if @left.value == node.value | |
@left = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------------------------------------------ | |
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here. | |
//------------------------------------------------------------------------------------------------------------------ | |
var Zoo = { | |
init : function(animals){ | |
this.animals = animals | |
}, | |
bipeds : function(){ | |
return this.animals.filter(function(element){ | |
return (element.legs == 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALUES = { 1000000000000 => 'trillion ', 1000000000 => 'billion ', 1000000 => 'million ', 1000 => 'thousand ', 1 => '' } | |
TENS = ['', '', 'twenty ', 'thirty ', 'forty ', 'fifty ', 'sixty ', 'seventy ', 'eighty ', 'ninety '] | |
ONES = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine '] | |
TEENS = ['ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen '] | |
def to_word(number) | |
power = 1000**(Math.log10(number).floor / 3) | |
to_write = number / power | |
number_as_word = get_hundreds(to_write) + get_tens(to_write) + get_ones(to_write) + VALUES[power] | |
number_as_word << to_word(number % power) unless number % power == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Frame | |
attr_reader :rolls | |
def initialize(rolls) | |
@rolls = rolls.first == 10 ? [rolls.first] : rolls | |
end | |
def roll_score | |
@rolls.inject(:+) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Frame(rolls) { | |
if (rolls[0] == 10) { | |
this.rolls = [rolls[0]] | |
} | |
else { | |
this.rolls = rolls | |
} | |
} | |
Frame.prototype.rollScore = function() { |
OlderNewer