Skip to content

Instantly share code, notes, and snippets.

View todlazarov's full-sized avatar

Tod Lazarov todlazarov

  • Toronto, ON, Canada
View GitHub Profile
# 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
# 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 = ''
# 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"}
}
# 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"}
}
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
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
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
# 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
# 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
# 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