Skip to content

Instantly share code, notes, and snippets.

@kmandreza
kmandreza / gist:6747571
Last active March 11, 2016 23:15
Let's Play 2
Exercise 1 Deaf Grandma
We're going to model something a little silly: an interaction between you and your imaginary deaf grandma. She exhibits the following inexplicable behavior:
1.She can only hear you if you shout at her.
2.If you say something but don't shout, she'll shout right back: "HUH?! SPEAK UP, SONNY!"
3.If you do shout you're also out of luck, because she'll misunderstand you and shout back "NO, NOT SINCE 1983!"
4.She won't let you leave the room unless you say, politely, "I love ya, Grandma, but I've got to go." She may be deaf, but she can smell rude a mile away.
How should these behaviors map to code?
@kmandreza
kmandreza / gist:6747393
Last active December 24, 2015 04:59
Sudoku
PART 1
By the end of the next two challenges you'll have a fully-functioning Sudoku solver that you can run from the command line.
Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids that compose the grid (also called "boxes") contains all of the digits from 1 to 9.
The person who created the puzzle provides a partial solution so that some squares already have numbers. Typically, there are enough initial numbers to guarantee a unique solution.
Unsolved Solved Sudoku
@kmandreza
kmandreza / gist:6654798
Created September 21, 2013 22:26
LET'S PLAY
# Exercise 1
Define three local variables: home_address, home_city, and home_state. Define and assign them the values of your own personal home address, city, and state, respectively.
# Exercise 2
Explain the difference between the following lines of code in plain English. "Plain English" means use language Edward, your non-programming second cousin from Ames, IA, would understand.
If any of the lines are invalid, explain why.
first_name = "Khara"
@kmandreza
kmandreza / flashcard.rb
Last active December 12, 2015 08:49
flashcard and sherif's notes
class Flashcard #data structure
attr_accessor :term, :definition
def initialize(term,definition)
@term=term
@definition=definition
end
end
@kmandreza
kmandreza / gist:4743420
Last active December 12, 2015 08:19
Ruby Todos 1.0: Core Features
require_relative 'view'
require_relative 'FileReadWrite'
class Parser
TODO_FILE = 'Todolist.txt'
def initialize(user_input)
@filerw = FileReadWrite.new(TODO_FILE)
@list = get_list
@viewer = Viewer.new
@kmandreza
kmandreza / todo.rb
Last active December 12, 2015 08:19
To Do
class FileReadWrite
def initialize(filename)
@filename = filename
end
def read_file
File.open(@filename).readlines
end
@kmandreza
kmandreza / Flashcards
Created February 7, 2013 22:02
Ruby Flashcards 1: Single Deck Let's build a simple flashcard game in Ruby with a command-line interface. Here is an example of one possible implementation: $ ruby flashcards.rb Welcome to Ruby Flash Cards. To play, just enter the correct term for each definition. Ready? Go! Definition A file format in which values are delimited by commas. Guess…
class Flashcard #data structure
attr_accessor :term, :definition
def initialize(term,definition)
@term=term
@definition=definition
end
end
@kmandreza
kmandreza / jsonyaml.rb
Last active December 12, 2015 06:09
json yaml
require 'csv'
require 'date'
require 'yaml'
require 'json'
FILENAME = "people.csv"
NEW_FILE = "new_people.csv"
YAML_FILE = "people.yaml"
JSON_FILE = "people.json"
@kmandreza
kmandreza / serialization.rb
Created February 7, 2013 00:12
CSV In, CSV Out
require 'csv'
require 'date'
FILENAME = "people.csv"
NEW_FILE = "new_people.csv"
class Person
attr_reader :id, :first_name, :last_name, :email, :phone, :created_at
# id,first_name,last_name,email,phone,created_at
class InputError < StandardError
end
class RPNCalculator
DIGITS = /\A-?\d+\Z/
ACCEPTABLE_INPUT = /\d+|[+*-\/]/
def evaluate(list)
list_array = list.split
stack = []
list_array.each do |element|