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
# Write a method that counts down to zero using recursion. | |
def count_down(num) | |
if num <= 0 | |
puts num | |
else | |
puts num | |
count_down(num - 1) | |
end | |
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
# Constants | |
VALID_CHOICES = %w(rock paper scissors lizard spock) | |
VALID_ABRV = %w(r p sc l sp) | |
# Variables | |
choice = '' | |
player_choice = '' | |
player_score = 0 | |
computer_score = 0 | |
winner = '' |
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
# Given the munsters hash below | |
munsters = { | |
"Herman" => { "age" => 32, "gender" => "male" }, | |
"Lily" => { "age" => 30, "gender" => "female" }, | |
"Grandpa" => { "age" => 402, "gender" => "male" }, | |
"Eddie" => { "age" => 10, "gender" => "male" }, | |
"Marilyn" => { "age" => 23, "gender" => "female"} | |
} |
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
# Given the munsters hash below | |
munsters = { | |
"Herman" => { "age" => 32, "gender" => "male" }, | |
"Lily" => { "age" => 30, "gender" => "female" }, | |
"Grandpa" => { "age" => 402, "gender" => "male" }, | |
"Eddie" => { "age" => 10, "gender" => "male" }, | |
"Marilyn" => { "age" => 23, "gender" => "female"} | |
} |
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
require 'pry' | |
INITIAL_MARKER = " " | |
PLAYER_MARKER = "X" | |
COMPUTER_MARKER = "O" | |
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows | |
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns | |
[[1, 5, 9], [3, 5, 7]] # diagonals | |
# Variables |
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
require 'pry' | |
# Constants | |
INITIAL_MARKER = " " | |
PLAYER_MARKER = "X" | |
COMPUTER_MARKER = "O" | |
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows | |
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns | |
[[1, 5, 9], [3, 5, 7]] # diagonals |
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
require 'pry' | |
# Constants | |
INITIAL_MARKER = " " | |
PLAYER_MARKER = "X" | |
COMPUTER_MARKER = "O" | |
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows | |
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns | |
[[1, 5, 9], [3, 5, 7]] # diagonals |
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
# 1. We are working with a database and we need to create a comma separated list of facebook friend's IDs | |
users.select {|u| u.is_friend?} | |
.map {|u| u.facebook_id} | |
.compact | |
.join(',') | |
# Pseudocode | |
# We combine our methods by chaining them together for clarity and readibility. | |
# First we create a method that checks if the given user is our friend and call it "is_friend?". | |
# We use the select method to itterate over the users database and return an array containing |
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
# Tic Tac Toe is a 2 player board game played on a 3x3 grid. Players take turns | |
# making a square. The first player to mark 3 squares in a row wins. | |
# Nouns: board, player, square, grid | |
# Verbs: play, mark | |
# Board | |
# Square | |
# Player | |
# - mark |
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
# Tic Tac Toe is a 2 player board game played on a 3x3 grid. Players take turns | |
# making a square. The first player to mark 3 squares in a row wins. | |
# Nouns: board, player, square, grid | |
# Verbs: play, mark | |
# Board | |
# Square | |
# Player | |
# - mark |
OlderNewer