This file contains hidden or 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 BoggleBoard | |
def initialize(board) | |
@board = board | |
end | |
def create_word(*coords) | |
coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end |
This file contains hidden or 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
#population density is number of people per square mile as of 2012 | |
#this data is updated every year with estimates from a 10 year census | |
STATE_DATA = { "Alabama" => {population_density: 94.65, population: 4822023, region: 5, regional_spread: 3}, | |
"Alaska" => {population_density: 1.26, population: 731449, region: 10, regional_spread: 9}, | |
"Arizona" => {population_density: 57.05, population: 6553255, region: 8, regional_spread: 8}, | |
"Arkansas" => {population_density: 56.43, population: 2949131, region: 7, regional_spread: 5}, | |
"California" => {population_density: 244.2, population: 38041430, region: 9, regional_spread: 8}, | |
"Colorado" => {population_density: 49.33, population: 5187582, region: 8, regional_spread: 6}, | |
"Connecticut" => {population_density: 741.4, population: 3590347, region: 1, regional_spread: 2}, |
This file contains hidden or 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
# When you are finished with this challenge you should be able to: | |
# Explain what "require_relative" does and why you would use it | |
# Demonstrate how to iterate through a hash | |
# Easily recognize and refactor repetitive code | |
# Objectives | |
# 1) Run the code. Look at the output. Look at the input (it's in the other file). Explain what the program is doing. | |
# 2) Write a comment explaining the require_relative statement below | |
# 3) Comment each method and define it's responsibility |
This file contains hidden or 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
# Input: an integer >= 0 | |
# Output: True/False | |
1 2 3 4 5 6 7 8 | |
0 1 1 2 3 5 8 13<< 21 | |
9 | |
def fibonacci( n ) | |
return n if ( 0..1 ).include? n | |
( fibonacci( n - 1 ) + fibonacci( n - 2 ) ) |
This file contains hidden or 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
def total(array) | |
sum = 0 | |
#create variable sum | |
#iterate through the array and add each element to sum | |
#output sum | |
array.each do |arg| | |
sum += arg |
This file contains hidden or 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
def mode(array) | |
# sort the original array, `array` | |
# create array of at least 1 in length: return this | |
frequencies = Hash.new(0) | |
array.each do |arg| | |
# add to frequencies | |
# if key already exists, just add 1 to value | |
# if not, create key, and set value to 1 | |
end |