Skip to content

Instantly share code, notes, and snippets.

@carolineartz
carolineartz / Challenge1_1_BONUS_array_mode.rb
Last active January 3, 2016 02:19 — forked from dbc-challenges/phase0_template_gist.rb
Write a method mode which takes an Array of numbers as its input and returns an Array of the most frequent values. If there's only one most-frequent value, it returns a single-element Array.
def mode(array)
array_of_modes = []
#NOTE:
#Hash.new(0) differs from defining an empty hash by {} in that:
# 1. Hash.new(0) defines an empty hash with a default value of 0 for new keys with undefined values.
# 2. {} defines an empty hash that will default to nil for new keys with undefined values.
#Here, executing the block on nil will result in NoMethodError as + is undefined for nil, so must Hash.new(0)
##############CREATE OUR FREQUENCIES HASH#########
@carolineartz
carolineartz / Chellenge1_2_Regex.rb
Last active January 3, 2016 07:29 — forked from dbc-challenges/phase0_template_gist.rb
Ruby's String class has over 100 public methods that give Ruby programmers a remarkable power to process, manipulate, and transform textual data. About a dozen of those String methods use Regular Expressions in order to allow for high-powered string matching. (Try searching for "regular expression" on the ruby docs String page.)
#######################################PSEUDOCODE###################################
# INPUT: a string
# OUPUT & PSEUDOCODE
# Contains SSN => OUTPUT: Return boolean true/false
# Test string for chars in SSN format
# Return SSN => OUTPUT: Return SSN extracted from input, as string
# Call Contains SSN method-test if a SSN in string
# If contains SSN, extract and return.
@carolineartz
carolineartz / Challenge1_2_numbers_commas.rb
Last active January 3, 2016 07:29 — forked from dbc-challenges/phase0_week2_challenge_template.rb
Write a method separate_comma which takes an integer as its input and returns a comma-separated integer as a string
#######################################PSEUDOCODE###################################
# INPUT: a positive integer number formatted without commas
# OUPUT: the input number formatted with commas as a string
# [refactored solution]
# Convert the input number to string
# Reverse the string
# put a comma after each complete group of 3 characters
# reverse and return the string
@carolineartz
carolineartz / Challenge1_2_Fibonacci.rb
Last active January 3, 2016 08:39 — forked from dbc-challenges/phase0_week2_challenge_template.rb
Check, if a number i is part of the Fibonacci sequence.
#######################################PSEUDOCODE###################################
# INPUT: a positive integer
# OUPUT: boolean true/false if it is a fibonacci number
# generate fib numbers less than or equal to input
# test whether input one of the generated fib numbers
# return boolean true if is fib number
# return boolean false if not a fib number
@carolineartz
carolineartz / Challenge1_2_Refactoring_Cipher.rb
Last active January 3, 2016 19:59 — forked from dbc-challenges/phase0_week2_refactoring_challenge.rb
The N.S.A. just broke Kim Jong Un's cipher that he's been using to give instructions to his military commanders! We wrote the following program to decipher the messages. As the N.S.A.'s best programmer on staff, your job is to refactor the code.
########################IDENTIFY WHAT EACH LINE OF CODE IS DOING####################
def north_korean_cipher(coded_message)
input = coded_message.downcase.split("") #any uppercase chars to lowercase;
#splits the string at each char and
#returns an array of chars.
decoded_sentence = [] #creates empty array to push our deciphered message chars into
cipher = {"e" => "a", #deciphers the alphabetical chars into NK key => EN value
"f" => "b",
"g" => "c",
@carolineartz
carolineartz / challenge1_3_die_class1_numeric.rb
Last active January 3, 2016 20:19 — forked from dbc-challenges/phase0_week2_challenge_template.rb
Implement a basic Die class which can be initialized with some number of sides. We can then roll the die, returning a random number. It should work like this: die = Die.new(6) die.sides # returns 6 die.roll # returns a random number between 1 and 6 If we pass Die.new a number less than 1, we should raise an ArgumentError. This is done using the …
#######################################PSEUDOCODE###################################
# INPUT, OUTPUT & PSEUDOCODE:
# Initialize => INPUT: number of sides = integer > 0
# OUTPUT: new Die object
# # set instance variable sides to value of passed argument
# Die#sides => INPUT: none
# OUTPUT: number of sides
# getter/accessor method for sides
# Die#roll => INPUT: none
@carolineartz
carolineartz / challenge1_3_die_class2_arbitrary_symbols.rb
Last active January 3, 2016 20:39 — forked from dbc-challenges/phase0_template_gist.rb
Working off your previous Die class from Die Class 1, implement a new Die class which takes an array of strings as its input. When Die#roll is called, it randomly returns one of these strings. If Die.new is passed an empty array, raise an ArgumentError. It should work like this: `die = Die.new(['A', 'B', 'C', 'D', 'E', 'F’])` `die.sides # still …
#######################################PSEUDOCODE###################################
# INPUT, OUTPUT & PSEUDOCODE:
# Initialize => INPUT: array of strings (labels)
# OUTPUT: new Die object
# a. raises argument error if passed an empty array
# b. Creates instance variabel for labels
# Die#sides => INPUT: none
# OUTPUT: number of sides
# a. calculate and return size of labels array
@carolineartz
carolineartz / challenge1_3_guessing_game.rb
Last active January 3, 2016 20:39 — forked from dbc-challenges/phase0_template_gist.rb
Exercise: Build a simple guessing gameCreate a GuessingGame class which is initialized with an integer called answer.Define an instance method GuessingGame#guess which takes an integer called guess as its input. guess should return the symbol :high if the guess is larger than the answer, :correct if the guess is equal to the answer, and :low if …
####################################### PSEUDOCODE #####################################
# INPUT: initialize a game passing the correct integer answer to instantiate;
# pass a guess value to #guess
# OUPUT: #guess outputs symbol representing
# if the most recent guess is too high, too low, or correct
# #solved? outputs true if the most recent guess is correct and flase otherwise.
# STEPS: #initialize -> set answer to instance variable, answer
#guess -> return corresponding symbol for too high, too low, correct
@carolineartz
carolineartz / challenge1_3_class_warfare.rb
Last active January 3, 2016 20:39 — forked from dbc-challenges/phase0_template_gist.rb
Exercise: Class Warfare, Validate a Credit Card NumberGiven a credit card number we should be able to validate whether it is valid based on the Luhn algorithm. While the word algorithm sounds scary you can just think of them as a series of steps you use to solve a specific problem. An example algorithm:Heat water until boilingAdd pastaIf pasta c…
####################################### PSEUDOCODE #####################################
# INPUT: Initialize object with input 16-digit integer parameter
# OUPUT: #initialize outputs invalid ArgumentError for input integers not 16 digits
# #CreditCard#check_card outputs boolean true/false for
# valid/invalid digits as credit card number
# STEPS: #initialize raise ArgumentError if input parameter is not 16 digits
# set input to instance variable for card number
#card_number isolate digits to double and multiply them by 2
#!/usr/bin/env ruby
require 'open-uri'
require 'net/http'
require 'iconv'
require 'optparse'
require 'fileutils'
require 'cgi'
$options = {}