Skip to content

Instantly share code, notes, and snippets.

@carolineartz
carolineartz / A_Nested_Array_to_Model_a_Boggle_Board_solution.rb
Last active August 29, 2015 13:55
Solution for A Nested Array to Model a Boggle Board
# Solution for Challenge: A Nested Array to Model a Boggle Board. Started 2014-01-29T21:58:07+00:00
@boggle_board = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last]}.join("")
# OBJECTIVE 3: CREATE PEZ CLASS
# See objectives #1, #2, and #6 after #3
class PezDispenser
@@available_flavors = %w(cherry chocolate cola grape lemon orange peppermint raspberry strawberry raspberry-lemon strawberry-vanilla)
# Class variable describes current market available pez flavors (wikipedia; exclues sugarfree & sour)
def initialize(flavors)
unless flavors == flavors.select { |flavor| valid_flavor?(flavor) }
raise ArgumentError.new('Contains invalid flavors') # raises if input includes invalid flavor
end
@carolineartz
carolineartz / 0.2.1-boggle_class_from_methods.rb
Last active August 29, 2015 13:55 — forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@dice_grid = dice_grid
end
def create_word(*coords)
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join('')
end
@carolineartz
carolineartz / Database_Drill:_Intro_to_SQLite_solution.sql
Last active August 29, 2015 13:56
Solution for Database Drill: Intro to SQLite
-- Solution for Challenge: Database Drill: Intro to SQLite. Started 2014-02-06T18:06:49+00:00
$ sqlite3 dummy.db
-- Loading resources from /Users/carolineartz/.sqliterc
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE users (
@carolineartz
carolineartz / Database_Drill:_SQLzoo_for_SQL_queries_solution.md
Last active August 29, 2015 13:56
Solution for Database Drill: SQLzoo for SQL queries

##Scores Database Drill Scores

##Reflection I was stuck for quite a while on the final problem (#13) in the bonus JOIN section.

First, I had trouble distributing the scores correctly across the teams for each record--but I realized I should be using SUM and not COUNT.

Next, I could not figure out how to populate the records (rows/games) with a 0-0 tie. With an INNER JOIN (default JOIN behavior), only when the joined field appears in both tables will the result table be populated with data. However, there are different types of joins and we needed the one where all games are populated, regardless of whether they appear in the table describing goals (because games that result in a draw wouldn't show up in the goals table). Remembering this, I went for a LEFT JOIN--including all items from my "left" table (game) and those that match on the joined feild from the "right" table (goal).

@carolineartz
carolineartz / Database_Drill:_Student_Roster_solution.md
Last active August 29, 2015 13:56
Solution for Database Drill: Student Roster

Solution for Challenge: Database Drill: Student Roster. Started 2014-02-10T02:55:08+00:00 student roster

<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: https://socrates.devbootcamp.com/sql.html -->
<sql>
    <datatypes db="mysql">
        <group label="Numeric" color="rgb(238,238,170)">
@carolineartz
carolineartz / Database_Drill:_One_To_Many_Schema_solution.md
Last active August 29, 2015 13:56
Solution for Database Drill: One To Many Schema

Solution for Challenge: Database Drill: One To Many Schema. Started 2014-02-10T03:36:16+00:00 one to many schema

<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: https://socrates.devbootcamp.com/sql.html -->
<sql>
    <datatypes db="mysql">
        <group label="Numeric" color="rgb(238,238,170)">
@carolineartz
carolineartz / Database_Drill:_One_to_One_Schema_solution.md
Last active August 29, 2015 13:56
Solution for Database Drill: One to One Schema

Solution for Challenge: Database Drill: One to One Schema. Started 2014-02-10T03:40:14+00:00 one to one schema

<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: https://socrates.devbootcamp.com/sql.html -->
<sql>
    <datatypes db="mysql">
        <group label="Numeric" color="rgb(238,238,170)">
@carolineartz
carolineartz / Database_Drill:_Many_To_Many_Schema_solution.md
Last active August 29, 2015 13:56
Solution for Database Drill: Many To Many Schema

Solution for Challenge: Database Drill: Many To Many Schema. Started 2014-02-10T04:01:00+00:00 many to many schema

<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: https://socrates.devbootcamp.com/sql.html -->
<sql>
    <datatypes db="mysql">
        <group label="Numeric" color="rgb(238,238,170)">
require 'sqlite3'
$db = SQLite3::Database.open 'congress_poll_results.db'
def print_arizona_reps
puts 'AZ REPRESENTATIVES'
az_reps = $db.execute("SELECT name FROM congress_members WHERE location = 'AZ'")
az_reps.each { |rep| puts rep }
end