<repo_name>yenertuz/app_academy_ruby<file_sep>/29_hash_map_lru_cache/lib/p02_hashing.rb
class Fixnum
  # Fixnum#hash already implemented for you
end

class Array


  def hash
	return 0.hash if self.length == 0
	sub_result = self.reduce { |sum, num|  (sum << 5) + num  }
	to_hash = self.length ^ sub_result
	sub_result.hash
  end
end

class String
  def hash
	return 0.hash if self.length == 0
	sub_result = self.chars.reduce(0) { |sum, num| (sum << 5) + num.bytes[0] }
	to_hash = self.length ^ sub_result
	sub_result.hash
  end
end

class Hash
  # This returns 0 because rspec will break if it returns nil
  # Make sure to implement an actual Hash#hash method
  def hash
	return 0.hash if self.length == 0
	arr = self.to_a.sort.flatten
	arr.map! { |x| x.is_a?(Symbol) ? x.to_s.hash : x.hash }
	arr.hash
  end
end
<file_sep>/13_diy_adts/map.rb
class Map

	def initialize
		@map = []
	end

	def set(key, value)
		a = nil
		@map.each_with_index {|(k, v), i|  a = i if k == key  }
		if a == nil
			@map << [key, value]
		else
			@map[i][1] = value
		end
	end

	def get(key)
		@map.each { |(k, v)| return v if k == key   }
		nil
	end

	def delete(key)
		@map.delete_if { |(k, v)| k == key }
	end

	def show
		puts "{"
		@map.each { |(k, v)|  print k.to_s + " => " + v.to_s; puts   }
	end

end<file_sep>/21_chess/chess.rb
require "./tile.rb"
require "./move.rb"
require "./player.rb"
require "io/console"

class String
	def black;          "\e[30m#{self}\e[0m" end
	def red;            "\e[31m#{self}\e[0m" end
	def green;          "\e[32m#{self}\e[0m" end
	def brown;          "\e[33m#{self}\e[0m" end
	def blue;           "\e[34m#{self}\e[0m" end
	def magenta;        "\e[35m#{self}\e[0m" end
	def cyan;           "\e[36m#{self}\e[0m" end
	def gray;           "\e[37m#{self}\e[0m" end
	def yellow;         "\e[33m#{self}\e[0m" end
	def pink;           "\e[35m#{self}\e[0m" end
	
	def bg_black;       "\e[40m#{self}\e[0m" end
	def bg_red;         "\e[41m#{self}\e[0m" end
	def bg_green;       "\e[42m#{self}\e[0m" end
	def bg_brown;       "\e[43m#{self}\e[0m" end
	def bg_blue;        "\e[44m#{self}\e[0m" end
	def bg_magenta;     "\e[45m#{self}\e[0m" end
	def bg_cyan;        "\e[46m#{self}\e[0m" end
	def bg_gray;        "\e[47m#{self}\e[0m" end 
	def bg_white;       "\e[47;1m#{self}\e[0m" end
	
	def bold;           "\e[1m#{self}\e[22m" end
	def italic;         "\e[3m#{self}\e[23m" end
	def underline;      "\e[4m#{self}\e[24m" end
	def blink;          "\e[5m#{self}\e[25m" end
	def reverse_color;  "\e[7m#{self}\e[27m" end
	def no_colors
		self.gsub /\e\[\d+m/, ""
	  end
end

class Chess

	KEYMAP = {
  " " => :space,
  "h" => :left,
  "j" => :down,
  "k" => :up,
  "l" => :right,
  "w" => :up,
  "a" => :left,
  "s" => :down,
  "d" => :right,
  "\t" => :tab,
  "\r" => :return,
  "\n" => :newline,
  "\e" => :escape,
  "\e[A" => :up,
  "\e[B" => :down,
  "\e[C" => :right,
  "\e[D" => :left,
  "\177" => :backspace,
  "\004" => :delete,
  "\u0003" => :ctrl_c,
}

	def self.start_game
		system "clear"
		@player1 = Player.from_input
		@player2 = Player.from_input
		@turn = @player1
		@selection = false
		@cursor = [0, 0]
		@board = Array.new(8) do |row|
			Array.new(8) do |column|
				type = ""
				case column
				when 0, 7
					type = :rook
				when 1, 6
					type = :knight
				when 2, 5
					type = :bishop
				when 3
					type = :king
				when 4
					type = :queen
				end

				poz = [row, column]
				case row
				when 0
					Tile.new(poz, type, @player1)
				when 1
					Tile.new(poz, :pawn, @player1)
				when 6
					Tile.new(poz, :pawn, @player2)
				when 7
					Tile.new(poz, type, @player2)
				else
					Tile.new(poz, :nil)
				end
			end
		end
		@is_over = false
		@board[@cursor[0]][@cursor[1]].place_cursor
		@check = false
		play
	end

	def self.read_char
		STDIN.echo = false # stops the console from printing return values
	
		STDIN.raw! # in raw mode data is given as is to the program--the system
					 # doesn't preprocess special characters such as control-c
	
		input = STDIN.getc.chr # STDIN.getc reads a one-character string as a
								 # numeric keycode. chr returns a string of the
								 # character represented by the keycode.
								 # (e.g. 65.chr => "A")
	
		if input == "\e" then
		  input << STDIN.read_nonblock(3) rescue nil # read_nonblock(maxlen) reads
													   # at most maxlen bytes from a
													   # data stream; it's nonblocking,
													   # meaning the method executes
													   # asynchronously; it raises an
													   # error if no data is available,
													   # hence the need for rescue
	
		  input << STDIN.read_nonblock(2) rescue nil
		end
	
		STDIN.echo = true # the console prints return values again
		STDIN.cooked! # the opposite of raw mode :)
	
		return input
	  end

	def self.print_board(board)
		system "clear"
		board.each do |row|
			row.each do |tile|
				print tile.output + "  "
			end
			puts; puts
		end
	end

	def self.play
		while @is_over == false
			print_board(@board)
			print "\nCHECK!" if @check == true
			move = KEYMAP[read_char]
			temp = @turn
			process_move(move)
		end
	end

	def self.valid_move?(move)
		new_cursor = [@cursor[0], @cursor[1]]
		case move
		when :left
			new_cursor[1] -= 1
		when :right
			new_cursor[1] += 1
		when :up
			new_cursor[0] -= 1
		when :down
			new_cursor[0] += 1
		end
		new_cursor.all? { |x| (0..7).include?(x)  }
	end

	def self.update_cursor(move)
		new_cursor = [@cursor[0], @cursor[1]]
		case move
		when :left
			new_cursor[1] -= 1
		when :right
			new_cursor[1] += 1
		when :up
			new_cursor[0] -= 1
		when :down
			new_cursor[0] += 1
		end
		@board[@cursor[0]][@cursor[1]].remove_cursor
		@cursor = new_cursor
		@board[@cursor[0]][@cursor[1]].place_cursor
	end

	def self.process_selection 
		if @selection == false && @board[@cursor[0]][@cursor[1]].player == @turn
			@selection = [@cursor[0], @cursor[1]]
			@board[@selection[0]][@selection[1]].place_select
		elsif @selection != false && @cursor == @selection
			remove_selection
			@board[@cursor[0]][@cursor[1]].place_cursor
		elsif @selection != false && moves(@selection).include?(@cursor)
			@board[@selection[0]][@selection[1]].remove_select
			@board[@selection[0]][@selection[1]].place_cursor
			@board[@cursor[0]][@cursor[1]] = @board[@selection[0]][@selection[1]]
			@board[@selection[0]][@selection[1]] = Tile.new(0, :nil)
			@selection = false
			@check = is_check(@turn)
			@turn == @player1 ? @turn = @player2 : @turn = @player1
		end
	end

	def self.remove_selection
		if @selection
			@board[@selection[0]][@selection[1]].remove_select
			@selection = false
		end
	end

	def self.process_move(move)
		case move
		when :up, :down, :left, :right
			update_cursor(move) if valid_move?(move)
		when :return, :newline, :space
			process_selection
		when :escape
			remove_selection
		when :ctrl_c
			Process.exit(0)
		end
	end

	def self.is_check(turn)
		r = []
		@board.each_with_index do |row, idx|
			row.each_with_index do |tile, idx2|
				if tile.type == :king && tile.player != turn
					r = [idx, idx2]
				end
			end
		end
		@board.each_with_index do |x, x_i|
			x.each_with_index do |y, y_i|
				return true if y.player == turn &&  moves([x_i, y_i]).include?(r) 
			end
		end
		false
	end


	# MOVES

	def self.moves_rook(start)
		r = []
		temp = [start[0], start[1] + 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[1] += 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0], start[1] - 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[1] -= 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0] + 1, start[1]]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] += 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0] - 1, start[1]]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] -= 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		r
	end

	def self.moves_bishop(start)
		r = []
		temp = [start[0] + 1, start[1] + 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] += 1
			temp[1] += 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0] + 1, start[1] - 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] += 1
			temp[1] -= 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0] - 1, start[1] + 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] -= 1
			temp[1] += 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		temp = [start[0] - 1, start[1] - 1]
		while (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].type == :nil
			r << temp.dup
			temp[0] -= 1
			temp[1] -= 1
		end
		r << temp.dup if (temp.all? { |x|  (0..7).include?(x)  })  && @board[temp[0]][temp[1]].player != @turn
		r
	end

	def self.moves_king(start)
		a = start[0]
		b = start[1]
		r = [
			[a, b + 1],
			[a, b - 1],
			[a + 1, b],
			[a + 1, b + 1],
			[a + 1, b - 1],
			[a - 1, b],
			[a - 1, b + 1],
			[a - 1, b - 1]
	]
		r.select! { |x|  (0..7).include?(x[0]) && (0..7).include?(x[1])   }
		r.reject { |x| @board[x[0]][x[1]].player == @turn   }
	end

	def self.moves_knight(start)
		a = start[0]
		b = start[1]
		r = [
			[a - 1, b + 2],
			[a + 1, b + 2],
			[a + 2, b + 1],
			[a + 2, b - 1],
			[a + 1, b - 2],
			[a - 1, b - 2],
			[a - 2, b - 1],
			[a - 2, b + 1]
	]
		r.select! { |x|  (0..7).include?(x[0]) && (0..7).include?(x[1])   }
		r.reject {|x|  @board[x[0]][x[1]].player == @turn        }
	end

	def self.moves_pawn(start)
		r = []
		a = start[0]
		b = start[1]
		@turn == @player1 ? to_add = 1 : to_add = -1
		return [] if (0..7).include?(a) == false
		r << [a + to_add, b] if @board[a + to_add][b].type == :nil
		r << [a + to_add, b + 1] if (0..7).include?(b + 1) && @board[a + to_add][b + 1].player != @turn
		r << [a + to_add, b - 1] if (0..7).include?(b - 1) && @board[a + to_add][b - 1].player != @turn
		r
	end

	def self.moves(start)
		type = @board[start[0]][start[1]].type
		case type
		when :rook 
			moves_rook(start)
		when :bishop
			moves_bishop(start)
		when :king 
			moves_king(start)
		when :pawn
			moves_pawn(start)
		when :queen
			moves_rook(start) + moves_bishop(start)
		when :knight
			moves_knight(start) 
		end
	end





	# END MOVES




end

Chess.start_game<file_sep>/04_sudoku/sudoku.rb
class Sudoku

	def initialize(sudoku_path)
		@board = File.read(sudoku_path)
		@board = @board.split("\n")
		@lines = (0...9).map { |x|  (0...9).map {|y| [x, y]  }  }
		@columns = (0...9).map { |x|  (0...9).map {|y| [y, x]  }  }
		all_poz = []
		(0..9).each { |x| (0...9).each { |y| all_poz << [x, y] } }
		@squares = []
		@squares = self.get_squares(all_poz)
	end

	def win?
		!(@board.join.include?("0"))
	end

	def get_squares(all_poz)
		row_counter = 0
		column_counter = 0
		temp_array = []
		while row_counter < 3
			column_counter = 0
			while column_counter < 3
				row_min = row_counter * 3
				row_max = row_min + 3
				column_min = column_counter * 3
				column_max = column_min + 3
				temp_array = all_poz.select { |(row, column)| row_min <= row && row < row_max && column_min <= column && column < column_max }
				@squares << temp_array
				column_counter += 1
			end
			row_counter += 1
		end
		@squares
	end

	def print_board
		puts "    " + (0...9).map {|x| "[" + x.to_s + "]" } .join(" ")
		puts
		@board.each_with_index do |x, i|
			print "[" + i.to_s  + "] "
			puts x.chars.map {|x| " " + x + " " }.join(" ")
			puts
		end
	end

	def check_poz_array(poz_array, board_array)
		focus_array = poz_array.map { |(row, column)|  board_array[row][column] }
		(1...9).all? {|x| focus_array.count(x.to_s) <= 1  }
	end

	def check_if_valid(new_board)
		return false if @lines.any? {|x| self.check_poz_array(x, new_board) == false  }
		return false if @columns.any? {|x| self.check_poz_array(x, new_board) == false } 
		return false if @squares.any? {|x| self.check_poz_array(x, new_board) == false }
		true 
	end

	def ask_for_input
		print "Enter a row, columnd and number like \"1 5 3\" (without the quoation marks, separated by spaces): "
		input = gets.chomp
		input = input.split
		(0...3).each { |x| input[x] = input[x].to_i }
		input[2] = input[2].to_s
		input
	end

	def next_move
		system("clear")
		self.print_board
		input = self.ask_for_input
		new_board = @board.join(" ").split
		new_board[input[0]][input[1]] = input[2]
		if self.check_if_valid(new_board) && input[2] != 0
			@board = new_board
		else
			puts
			puts "Invalid move!"
			sleep(1)
		end
	end


	def play
		while self.win? == false
			self.next_move
		end
		system("clear")
		self.print_board
		puts "You win! :-)"
		puts
	end

end<file_sep>/15_poly_tree_node/lib/00_tree_node.rb
class PolyTreeNode

	attr_reader :parent, :children, :value

	def initialize(value)
		@parent = nil
		@children = []
		@value = value
	end

	def parent=(new_parent)
		self.parent.children.delete(self) if @parent
		@parent = new_parent
		if new_parent != nil
			new_parent.children << self if new_parent.children.include?(self) == false
		end
	end


	def add_child(child_node)
		raise "Child node is not a Poly Tree Node object!" if child_node.is_a?(PolyTreeNode) == false
		child_node.parent = self
		@children << child_node if @children.include?(child_node) == false
	end

	def remove_child(child_node)
		raise "Child node is not a Poly Tree Node object!" if child_node.is_a?(PolyTreeNode) == false
		raise "Child node is not a child of this node" if @children.include?(child_node) == false
		child_node.parent = nil
		@children.delete(child_node)
	end

	def dfs(target_value)
		return self if @value == target_value
		@children.each do |x|
			if x != self
				result = x.dfs(target_value)
				return result if result
			end
		end
		return nil
	end

	def bfs(target_value)
		queue = []
		queue.push(self)
		while queue.length != 0
			current = queue.pop
			return current if current.value == target_value
			current.children.each { |x| queue.unshift(x)  }
		end
		nil
	end



end<file_sep>/29_hash_map_lru_cache/lib/p04_linked_list.rb
class Node
  attr_reader :key
  attr_accessor :val, :next, :prev

  def initialize(key = nil, val = nil)
    @key = key
    @val = val
    @next = nil
	@prev = nil
  end

  def to_s
    "#{@key}: #{@val}"
  end

  def remove
    # optional but useful, connects previous link to next link
	# and removes self from list.
	@prev.next = @next
	@next.prev = @prev
  end
end

class LinkedList
	include Enumerable

	attr_reader :length

  def initialize
	@head = Node.new
	@tail = @head
	@head.next = @tail
	@tail.prev = @head
	@length = 0
  end

  def [](i)
    each_with_index { |link, j| return link if i == j }
    nil
  end

  def first
	@head
  end

  def last
	@tail
  end

  def empty?
	@head.next == @tail && @head.key == nil
  end

  def get(key)
	self.each {|node| return node.val if node.key == key   }
	return nil
  end

  def include?(key)
	self.each {|node|  return true if node.key == key  }
	false
  end

  def append(key, val)
	new_node = Node.new(key, val)
	if @head.key == nil
		@head = new_node
		@tail = @head
		@head.next = @tail
		@tail.prev = @head
		@length = 1
	else
		@tail.next = new_node
		@tail.next.prev = @tail
		@tail = @tail.next
		@length += 1
	end
	new_node
  end

  def update(key, val)
	self.each { |node| node.val = val if node.key == key  }
  end

  def remove(key)
	if @length == 1 && @head.key == key
		@head = Node.new
		@tail = @head
		@head.next = @tail
		@tail.prev = @head
		@length = 0
	else
		self.each do |node|
			next if node.key != key
			if node == @head
				@head = @head.next
				@head.prev = nil
			elsif node == @tail 
				@tail = @tail.prev
				@tail.next = nil 
			else
				node.prev.next = node.next
				node.next.prev = node.prev
			end
		end
		@length -= 1
	end
  end

  def each
	pointer = @head
	while pointer != nil
		yield pointer
		break if pointer == pointer.next
		pointer = pointer.next
	end
  end

  #uncomment when you have `each` working and `Enumerable` included
  def to_s
    inject([]) { |acc, link| acc << "[#{link.key}, #{link.val}]" }.join(", ")
  end
end
<file_sep>/25_poker/deck.rb
require_relative "./card.rb"

class Deck


	def initialize
		@deck = Card.all_cards
		@deck.shuffle!
		@deck.shuffle!
	end


	def draw
		return @deck.pop
	end

	def start_over
		@deck = Card.all_cards 
		@deck.shuffle!
		@deck.shuffle!
	end

end<file_sep>/08_recursion_exercises/recursion.rb
def range(start, end_)
	return Array.new(start) if end_ <= start
	return Array.new(end_) + range(end_ - 1)
end

def exp1(b, n)
	return 1 if n <= 0
	return b * exp1(b, n - 1)
end

def exp2(b, n)
	return 1 if n <= 0
	return b if n == 1
	return exp2(b, n / 2) ** 2 if n.even?
	return b * exp2(b, ( (n - 1) / 2 ) ** 2)
end

def deep_dup(input)
	return Array.new(1, input) if input.is_a?(Array) == false
	return deep_dup(input[0]) if input.length <= 1
	return deep_dup(input[0]) + deep_dup(input[1..-1])
end

def r_fib(n)
	return nil if n < 1
	return 1 if n == 1
	return n * r_fib(n - 1)
end

def i_fib(n)
	return nil if n < 1
	(1..n).reduce(:*)
end

def b_search(array, target)
	l = n.length
	return nil if l == 0
	m = l / 2
	return m if array[m] == target
	if target < array[m]
		return b_search(array[0...m], target)
	else
		return m + b_search(array[(m + 1)..-1])
	end
end

def merge_helper(arr1, arr2)
	r = []
	while arr1.length > 0 && arr2.length > 0
		if arr1[0] > arr2[0]
			r.push(arr2.shift)
		else
			r.push(arr1.shift)
		end
	end
	r.push(arr1.shift) if arr1.length > 0
	r.push(arr2.shift) if arr2.legnth > 0
	r 
end

def merge_sort(array)
	return array if array.length <= 1
	l = array.length
	m = l / 2
	merge_helper(merge_sort(array[0..m], merge_sort(array[(m + 1)..-1])))
end

def array_subsets(array)
	return [[]] if array.length == 0
	return array_subsets(array[1..-1]) + array_subsets(array[1..-1]).map {|x| x << array[0] }
end

def greedy_make_change(total, changes=[25, 10, 5, 1])
	changes.sort!
	r = []
	while total > 0
		while total < changes[-1]
			changes.pop
		end
		r << changes[-1]
		total -= changes[-1]
	end
	r
end<file_sep>/13_diy_adts/stack.rb
class Stack

	def initialize
		@stack = []
	end

	def push(el)
		@stack.push(el)
	end

	def pop(el)
		@stack.pop 
	end

	def peek()
		@stack[-1]
	end

end<file_sep>/21_chess/tile.rb
require "./player.rb"

class Tile

	attr_reader :char, :output, :type, :player

	CHAR_MAP = {
		king: "♚",
		queen: "♛",
		rook: "♜",
		bishop: "♝",
		knight: "♞",
		pawn: "♟",
		nil: "*"
	}

	def initialize(poz, type=:nil, player=nil)
		@row = poz[0]
		@column = poz[1]
		@type = type
		@char = CHAR_MAP[@type]
		@output = @char
		@player = player
		self.get_char
	end

	def get_char
		@char = CHAR_MAP[@type]
		return if @player == nil
		if @player.number == 1
			@char = @char.red
		elsif @player.number == 2
			@char = @char.blue
		end
		@output = @char
	end

	def place_cursor
		@output = @char.reverse_color if @output == @char
	end

	def place_select
		@output = @char.no_colors.yellow
	end

	def remove_select
		@output = @char
	end

	def remove_cursor
		@output = @char if @output == @char.reverse_color
	end

end<file_sep>/04_sudoku/play.rb
require "./sudoku.rb"

print "enter the path of sudoku file to solve: "
path = gets.chomp
Sudoku.new(path).play<file_sep>/21_chess/cursor.rb
require "io/console"

class String
	def black;          "\e[30m#{self}\e[0m" end
	def red;            "\e[31m#{self}\e[0m" end
	def green;          "\e[32m#{self}\e[0m" end
	def brown;          "\e[33m#{self}\e[0m" end
	def blue;           "\e[34m#{self}\e[0m" end
	def magenta;        "\e[35m#{self}\e[0m" end
	def cyan;           "\e[36m#{self}\e[0m" end
	def gray;           "\e[37m#{self}\e[0m" end
	def yellow;         "\e[33m#{self}\e[0m" end
	def pink;           "\e[35m#{self}\e[0m" end
	
	def bg_black;       "\e[40m#{self}\e[0m" end
	def bg_red;         "\e[41m#{self}\e[0m" end
	def bg_green;       "\e[42m#{self}\e[0m" end
	def bg_brown;       "\e[43m#{self}\e[0m" end
	def bg_blue;        "\e[44m#{self}\e[0m" end
	def bg_magenta;     "\e[45m#{self}\e[0m" end
	def bg_cyan;        "\e[46m#{self}\e[0m" end
	def bg_gray;        "\e[47m#{self}\e[0m" end 
	def bg_white;       "\e[47;1m#{self}\e[0m" end
	
	def bold;           "\e[1m#{self}\e[22m" end
	def italic;         "\e[3m#{self}\e[23m" end
	def underline;      "\e[4m#{self}\e[24m" end
	def blink;          "\e[5m#{self}\e[25m" end
	def reverse_color;  "\e[7m#{self}\e[27m" end
	def no_colors
		self.gsub /\e\[\d+m/, ""
	  end
end

KEYMAP = {
  " " => :space,
  "h" => :left,
  "j" => :down,
  "k" => :up,
  "l" => :right,
  "w" => :up,
  "a" => :left,
  "s" => :down,
  "d" => :right,
  "\t" => :tab,
  "\r" => :return,
  "\n" => :newline,
  "\e" => :escape,
  "\e[A" => :up,
  "\e[B" => :down,
  "\e[C" => :right,
  "\e[D" => :left,
  "\177" => :backspace,
  "\004" => :delete,
  "\u0003" => :ctrl_c,
}

  def read_char
    STDIN.echo = false # stops the console from printing return values

    STDIN.raw! # in raw mode data is given as is to the program--the system
                 # doesn't preprocess special characters such as control-c

    input = STDIN.getc.chr # STDIN.getc reads a one-character string as a
                             # numeric keycode. chr returns a string of the
                             # character represented by the keycode.
                             # (e.g. 65.chr => "A")

    if input == "\e" then
      input << STDIN.read_nonblock(3) rescue nil # read_nonblock(maxlen) reads
                                                   # at most maxlen bytes from a
                                                   # data stream; it's nonblocking,
                                                   # meaning the method executes
                                                   # asynchronously; it raises an
                                                   # error if no data is available,
                                                   # hence the need for rescue

      input << STDIN.read_nonblock(2) rescue nil
    end

    STDIN.echo = true # the console prints return values again
    STDIN.cooked! # the opposite of raw mode :)

    return input
  end<file_sep>/12_minesweeper/board.rb
class Board

	def initialize
		@board = Array.new(9) { Array.new(9) { Tile.new }  }
	end

end<file_sep>/29_hash_map_lru_cache/lib/p05_hash_map.rb
require_relative 'p04_linked_list'

class HashMap
  attr_accessor :count

  include Enumerable

  def initialize(num_buckets = 8)
	@store = Array.new(num_buckets) { LinkedList.new }
	@max = num_buckets
    @count = 0
  end

  def include?(key)
	bucket(key).include?(key)
  end

  def set(key, val)
	resize! if @count == @max
	if self.include?(key) == false
		bucket(key).append(key, val)
		@count += 1
		return true
	else
		bucket(key).update(key, val)
	end
	false
  end

  def get(key)
	bucket(key).get(key)
  end

  def delete(key)
	if self.include?(key) == true
		bucket(key).remove(key)
		@count -= 1
		return true
	end
	false
  end

  def each
	@store.each do |bucket2|
		bucket2.each do |node|
			yield [node.key, node.val] if node.key != nil
		end
	end
  end

  # uncomment when you have Enumerable included
  def to_s
    pairs = inject([]) do |strs, (k, v)|
      strs << "#{k.to_s} => #{v.to_s}"
    end
    "{\n" + pairs.join(",\n") + "\n}"
  end

  alias_method :[], :get
  alias_method :[]=, :set

  private

  def num_buckets
    @store.length
  end

  def resize!
	@max *= 2
	new_store = Array.new(@max) { LinkedList.new  }
	self.each do |(key, val)|
		new_store[key.hash % @max].append(key, val)
	end
	@store = new_store
  end

  def bucket(key)
	# optional but useful; return the bucket corresponding to `key`
	@store[key.hash % @max]
  end
end
<file_sep>/03_memory_puzzle/game.rb
class Game

	def initialize
		@cards = Array.new(5) { ("A".."Z").to_a.sample(1) }
		@cards += @cards 
		@cards.shuffle!
		@remaining = 10
		@index = nil
		@index2 = nil
	end

	def first_pick
		system("clear")
		self.line_cards
		puts "Pick a card by entering a number between 0 and " + (@remaining - 1).to_s + " :"
		@index = gets.chomp
		while ("0".."9").include?(@index) == false || @index.to_i >= @remaining
			puts "\nInvalid input! Try again: "
			@index = gets.chomp
		end
		@index = @index.to_i
	end

	def second_pick
		system("clear")
		self.line_cards
		puts "Pick another card by entering a number between 0 and " + (@remaining - 1).to_s + " :"
		@index2 = gets.chomp
		while ("0".."9").include?(@index2) == false || @index2.to_i >= @remaining || @index2 == @index
			puts "\nInvalid input! Try again: "
			@index2 = gets.chomp
		end
		@index2 = @index2.to_i
	end


	def line_cards
		indices = [@index, @index2].reject { |x| x == nil }
		to_display = @cards.map.with_index { |x, i| indices.include?(i) ? x : "*" }
		puts to_display.join(" ")
		puts (0...@remaining).to_a.map {|x| x.to_s }.join(" ")
	end

	def process
		system("clear")
		self.line_cards
		sleep(1)
		if @cards[@index] == @cards[@index2]
			to_del = @cards[@index]
			@cards.delete(to_del)
			@remaining -= 2
		end
		@index = nil
		@index2 = nil
	end

	def next_turn
		self.first_pick
		self.second_pick
		self.process
	end

	def play
		puts "\nStarting Game!"
		while @remaining > 0
			self.next_turn
		end
		puts "\nGame Over!"
	end





end<file_sep>/20_class_inheritance/test.rb
require "./manager.rb"

david = Employee.new("David", 10000, "TA", "Darren")
shawna = Employee.new("Shawna", 12000, "TA", "Darren")
darren = Manager.new("Darren", 78000, "TA Manager", "Ned", [david, shawna])
ned = Manager.new("Ned", 1000000, "Founder", nil, [darren])

p ned.bonus(5)
p darren.bonus(4)
p david.bonus(3)<file_sep>/22_rspec_homework/spec/dessert_spec.rb
require 'rspec'
require 'dessert'

=begin
Instructions: implement all of the pending specs (the `it` statements without blocks)! Be sure to look over the solutions when you're done.
=end

describe Dessert do
  let(:chef) { double("chef", :bake => 21, :titleize => "Yener") }
  subject { Dessert.new("type", 40, chef)  }

  describe "#initialize" do
	it "sets a type" do
		expect(subject.type).to eq("type")
	end

	it "sets a quantity" do
		expect(subject.quantity).to eq(40)
	end

	it "starts ingredients as an empty array" do 
		expect(subject.ingredients).to eq([])
	end

	it "raises an argument error when given a non-integer quantity" do
		expect {Dessert.new("type2", "ss", "yener")}.to raise_error(ArgumentError)
	end
  end

  describe "#add_ingredient" do
	it "adds an ingredient to the ingredients array" do 
		subject.add_ingredient("ingredient1")
		expect(subject.ingredients).to include("ingredient1") end
  end

  describe "#mix!" do
	it "shuffles the ingredient array" do
		(0..20).each { |n|   subject.add_ingredient(n)               }
		subject.mix!
		expect(subject.ingredients).to_not eq((0..20).to_a)
	end
  end

  describe "#eat" do
	it "subtracts an amount from the quantity" do 
		subject.eat(20)
		expect(subject.quantity).to eq(20)
	end

	it "raises an error if the amount is greater than the quantity" do 
		expect { subject.eat(200) }.to raise_error
	end
  end

  describe "#serve" do
	it "contains the titleized version of the chef's name" do 
		expect(subject.serve).to include("Yener") end 
  end

  describe "#make_more" do
	it "calls bake on the dessert's chef with the dessert passed in" do 
		expect(subject.make_more).to eq(21) 
	end
  end
end
<file_sep>/21_chess/player.rb
class Player

	@@counter = 1

	attr_reader :number, :name

	def initialize(name)
		@name = name
		@number = @@counter
		@@counter += 1
	end

	def self.from_input
		print "Enter name for Player #{@@counter}: "
		name = gets.chomp.split[0]
		puts
		return self.new(name)
	end

end<file_sep>/01_ghost/game.rb
class Game

	def initialize(p1, p2)
		@fragment = ""
		@players = [p1, p2].shuffle
		@dictionary = Hash.new(0)
		File.read("dictionary.txt").split("\n").each { |x| @dictionary[x] = 1 }
		@losses = Hash.new(0)
	end


	def round_over?
		if @fragment.length > 2 && @dictionary[@fragment] == 1
			return true
		end
		false
	end

	def check_guess(guess)
		return false if guess.length != 1
		return false if ("a"..."z").include?(guess.downcase) == 0
		return false if @dictionary.keys.none? { |key| key.index(@fragment + guess) == 0 }
		true
	end

	def next_turn
		current_player = @players[0]
		current_player.announce_turn
		puts "current fragment is: " + @fragment
		guess = current_player.get_guess
		while self.check_guess(guess) == false
			current_player.invalid_guess
			guess = current_player.get_guess
		end
		@fragment += guess
		@players.rotate!
		puts
		current_player.lose_round if self.round_over?
	end


	def play_round
		@fragment = ""
		puts "starting round"
		puts ""
		while self.round_over? == false
			self.next_turn
		end
		puts
		puts "end of round"
	end


	def play
		while @players.none? {|player| player.lost? }
			self.play_round
		end
		puts "game over!"
		@players.select {|player| player.lost? }[0].lose_game
	end

end<file_sep>/13_diy_adts/queue.rb
class Queue

	def initialize
		@queue = []
	end

	def enqueue(el)
		@queue.unshift(el)
	end

	def dequeue
		@queue.pop
	end

	def peek
		@queue[-1]
	end

end<file_sep>/16_knights_travails/path_finder.rb
require "./tree_node.rb"

class KnightPathFinder

	def initialize(start_poz)
		@start_node = PolyTreeNode(start_poz)
		@visited_positions = [start_poz]

		self.build_move_tree
	end

	def self.valid_moves_helper(pos, x_add, y_add)
		ret = pos.dup
		ret[0] += x_add
		ret[1] += y_add 
		ret
	end

	def self.valid_moves(pos)
		r = []
		r << self.class.valid_moves_helper(pos, 1, 2)
		r << self.class.valid_moves_helper(pos, -1, 2)
		r << self.class.valid_moves_helper(pos, 1, -2)
		r << self.class.valid_moves_helper(pos, -1, -2)
		r << self.class.valid_moves_helper(pos, 2, 1)
		r << self.class.valid_moves_helper(pos, -2, 1)
		r << self.class.valid_moves_helper(pos, 2, -1)
		r << self.class.valid_moves_helper(pos, -2, -1)
		r.select {|x|  0 <= x[0] && x[0] < 8 && 0 <= x[1] && x[1] < 8   }
	end

	def new_move_positions(pos_node)
		new_moves = self.class.valid_moves(pos_node)
		new_moves.each 
	end


	def build_move_tree
		;
	end

end<file_sep>/29_hash_map_lru_cache/lib/p03_hash_set.rb
class HashSet
  attr_reader :count

  def initialize(num_buckets = 8)
    @store = Array.new(num_buckets) { Array.new }
	@count = 0
	@max = num_buckets
  end

  def insert(key)
	resize! if @count == @max
	if self[key].include?(key) == false
		self[key].push(key)
		@count += 1
		return true
	end
	false
  end

  def include?(key)
	self[key].include?(key)
  end

  def remove(key)
	if self[key].include?(key)
		self[key].delete(key)
		@count -= 1
		return true
	end
	false
  end

  private

  def [](num)
	# optional but useful; return the bucket corresponding to `num`
	@store[num.hash % @max]
  end

  def num_buckets
    @store.length
  end

  def resize!
	@max *= 2
	new_store = Array.new(@max) { Array.new }
	@store.each do |bucket|
		bucket.each do |element|
			new_store[element.hash % @max].push(element)
		end
	end
	@store = new_store
  end
end
<file_sep>/21_chess/move.rb
def Move

	def initialize(start_tile, end_tile)
		@start = start_tile
		@end_ = end_tile
	end

end<file_sep>/20_class_inheritance/manager.rb
require "./employee.rb"

class Manager < Employee

	def initialize(name, title, salary, boss, team=[])
		super(name, title, salary, boss)
		@team = team
	end

	def bonus(multiplier)
		@team.reduce(0) { |sum, num| sum + num.bonus(multiplier) + (num.is_a?(Manager)  ? num.salary * multiplier : 0 )  }
	end

end<file_sep>/17_simon/lib/simon.rb
require "colorize"

class Simon
  COLORS = %w(red blue green yellow)

  attr_accessor :sequence_length, :game_over, :seq

  def initialize
	@sequence_length = 1
	@game_over = false
	@seq = []
  end

  def play
	self.take_turn while @game_over == false
	self.game_over_message
	self.reset_game
  end

  def take_turn
	self.show_sequence
	self.require_sequence
	if @game_over == false
		self.round_success_message
		@sequence_length += 1
	end
  end

  def show_sequence
	self.add_random_color
  end

  def require_sequence
	seq = gets.chomp.split
	@game_over == 1 if seq != @seq
  end

  def add_random_color
	@seq += COLORS.sample(1)
  end

  def round_success_message

  end

  def game_over_message
	puts "GAME OVER :( ".red
  end

  def reset_game
	@sequence_length = 1
	@seq = []
	@game_over = false
  end
end

Simon.new.play<file_sep>/24_tdd/lib/tdd.rb
class Array 


	def my_uniq
		r = [] 
		self.each { |x| r << x if r.include?(x) == false}
		r
	end

	def two_sum
		r = []
		self.each_with_index do |x1, i1|
			self.each_with_index do |x2, i2|
				if x1 != 0 && x1 + x2 == 0
					r << [i1, i2].sort
				end
			end
		end
		r.uniq
	end
end


def my_transpose(array)
	raise ArgumentError.new("Argument not an array") if array.is_a?(Array) == false
	r = Array.new(array.length) { Array.new(array.length)   }
	(0...array.length).each do |i1|
		(0...array.length).each do |i2|
			r[i1][i2] = array[i2][i1]
		end
	end
	r
end

def stock_picker(stocks)
	raise ArgumentError.new("Argument not an array") if stocks.is_a?(Array) == false
	t = []
	profit = -1
	(0...stocks.length).each do |i1|
		((i1 + 1)...stocks.length).each do |i2|
			new_profit = stocks[i2][1] - stocks[i1][0]
			if new_profit > profit
				t = [i1, i2]
				profit = new_profit
			end
		end
	end
	t
end

class Toh

attr_reader :stacks

	def initialize
		@stacks = [
			[5, 3],
			[4, 1],
			[2]
		]
	end

	def move(start, end_)
		if (@stacks[start][-1] < @stacks[end_][-1])
			@stacks[end_].push(@stacks[start].pop)
			return true
		end
		return false
	end

	def end?
		return true if @stacks.count { |x|  x.empty?   } == 2
		false 
	end
end<file_sep>/25_poker/player.rb
class Player

	def initialize(name, money)
		@name = name
		@money = money
		@hand = []
		@pot = 1000
	end

end<file_sep>/09_word_chains/word_chains.rb
class WordChainer

	def initialize(first_word, second_word)
		@first_word = first_word
		@second_word = second_word
		raise "First word and second word cannot be of different length" if first_word.length != second_word.length
		raise "First word and second word are the same ..." if first_word == second_word
		@dictionary = Hash.new(0)
		File.read("dictionary.txt").split("\n").each { |x| @dictionary[x] = 1 }
		raise "First word does not exist!" if @dictionary[@first_word] != 1
		raise "Second word does not exist!" if @dictionary[@second_word] != 1
		l = first_word.length
		@dictionary = @dictionary.keys.select { |x| x.length == l }
		@is_solved = 0
		self.try
	end

	def try
		@stack = [[@first_word.dup, []]]
		while @stack.length > 0 && @dictionary.length > 0 && @is_solved == 0
			self.next_word
		end
		if @is_solved == 1
			puts @solution
		else
			puts "Cannot find a word chain between #{@first_word} and #{@second_word}"
		end
	end


	def char_diffs(word1, word2)
		word1_chars = word1.chars 
		word2_chars = word2.chars
		matches = 0
		(0...word1_chars.length).each { |i| matches += 1 if word1_chars[i] == word2_chars[i] }
		return word2_chars.length - matches
	end

	def is_match?(p1, p2)
		return false if p1.length != p2.length
		return false if self.char_diffs(p1, p2) != 1
		true
	end


	def get_matches(word)
		r = []
		@dictionary.each_with_index {|x, i| (r << x ; @dictionary.delete(x))  if self.is_match?(word, x)   }
		r 
	end

	def next_word
		current = @stack[0]
		current_word = current[0]
		current_history = current[1]
		matches = self.get_matches(current_word)
		if matches.length != 0
			if matches.include?(@second_word)
				@is_solved = 1
				@solution = current_history + [current_word] + [@second_word]
				return 
			end
			@stack += matches.map { |x| [x, current_history + [current_word]]   }
		end
		@stack.delete_at(0)
	end

end

if __FILE__ == $PROGRAM_NAME
	WordChainer.new(ARGV[0].to_s, ARGV[1])
end<file_sep>/01_ghost/play.rb
require "./game.rb"
require "./player.rb"

print "Enter name for player1: "
p1_name = gets.chomp
puts
print "Enter name for player2: "
p2_name = gets.chomp
puts

puts "Starting game"
puts 
game = Game.new(Player.new(p1_name), Player.new(p2_name))
game.play<file_sep>/18_mancala/mancala.rb
require "colorize"
require "./board.rb"

class Mancala

	def initialize
		system("clear")
		print "Enter player1 name (single word): "
		@player1_name = gets.chomp.split[0]
		print "Enter player2 name (single word): "
		@player2_name = gets.chomp.split[0]
		@board = [0, 4, 4, 4, 4, 0, 4, 4, 4, 4]
		@turn = 1
		@winner = 0
		self.play
	end

	def self.get_board_string(board, tur=0, turn=-1)
		str = "%2s %2s %2s %2s" % [board[0], board[1], board[2], board[3]]
		str = str.light_blue if tur == turn
		str = str.yellow if tur == 0
		str
	end

	def is_over?
		if p1_board.all?(0) || p2_board.all?(0)
			if @board[0] > @board[5]
				@winner = @player1_name
			elsif @board[5] > @board[0]
				@winner = @player2_name
			else
				@winner = ""
			end
			return true
		end
		false
	end

	def play
		while self.is_over? == false
			self.next_turn
		end
		puts
		if @winner == ""
			puts "TIE!"
		else
			puts "#{@winner} WINS!"
		end
	end


	def get_input
		puts
		print "Enter a number 0, 1, 2 or 3: "
		input = gets.chomp
		if ("0".."3").include?(input) == false
			puts "Invalid input! Try again"
			return get_input
		end
		input.to_i
	end

	def get_next_current(current)
		return current - 1 if (1..5).include?(current)
		return 6 if current == 0
		return current + 1 if (5..8).include?(current)
		return 5 if current == 9
	end

	def process_input(input)
		current = input
		stones = @board[current]
		@board[current] = 0
		self.render
		@turn == 1 ? special = 0 : special = 5
		@turn == 1 ? counter = 5 : counter = 0
		while stones > 0
			current = get_next_current(current)
			if current != counter
				@board[current] += 1
				stones -= 1
			end
		end
		if @board[current] != 1 && [0, 5].include?(current) == false
			return process_input(current)
		elsif current != special
			@turn = (@turn % 2) + 1
		end
	end

	def next_turn
		self.render
		input = get_input
		input += 1
		input += 5 if @turn == 2
		self.process_input(input)
	end

	def render
		system("clear")
		puts "%4s%s" % ["", self.class.get_board_string([0, 1, 2, 3])]
		puts
		puts "%4s%s" % ["", self.class.get_board_string(p1_board, 1, @turn)]
		puts "%2s%13s%3s" % ["P1", "", "P2"]
		puts "%2s%13s%3s" % [@board[0].to_s, "", @board[5].to_s]
		puts "%4s%s" % ["", self.class.get_board_string(p2_board, 2, @turn)]
	end

	private

	def p1_board
		@board[1..4]
	end

	def p2_board
		@board[6..-1]
	end

end


if __FILE__ == $PROGRAM_NAME
	Mancala.new
end<file_sep>/24_tdd/spec/tdd_spec.rb
require "rspec"
require "tdd"

describe Array do

	describe ".my_uniq" do 

		subject { [1, 1, 2, 2, 3]  }

		it "removes dupes" do 
			expect(subject.my_uniq).to eq([1, 2, 3])
		end
	end

	describe ".two_sum" do
		it "finds all pairs of positions where elements at those positions sum to zero" do 
			expect([-1, 0, 2, -2, 1].two_sum).to eq([[0, 4], [2, 3]])
		end
	end

	describe "my_transpose()" do 
		subject {  [[0, 1, 2], [3, 4, 5], [6, 7, 8]]          }

		it "converts between the row oriented and column oriented representations of an array" do 
			expect(my_transpose(subject)).to eq([[0, 3, 6], [1, 4, 7], [2, 5, 8]])
		end

		it "raises error when argumetn is not an array" do 
			expect{ my_transpose("test")}.to raise_error(ArgumentError, "Argument not an array")
		end
	end

	describe "stock picker" do
		subject {  [[1, 2], [3, 4], [5, 6]]    }

		it "returns an array (of 2 elements) with the number (not index, but index + 1) of day to buy and sell" do
			expect(stock_picker(subject)).to eq([0, 2])
		end
	end

end

describe Toh do

	subject {  Toh.new  }

	describe "#move" do

		it "moves when valid" do 
			expect(subject.move(1, 2)).to eq(true)
		end

		it "does not move when invalid" do 
			expect(subject.move(0, 2)).to eq(false)
		end

	end

	describe "#end?" do

		it "return false when game is not over" do 
			expect(subject.end?).to eq(false)
		end

	end
end<file_sep>/README.md
# App Academy - Ruby

Gif of the Chess project

![Gif of Chess](chess_demo.gif?raw=true "Chess")

Image of the Mine Sweeper project

![Screen Shot of Mine Sweeper](screen_show.png?raw=true "Mine Sweeper")
<file_sep>/06_recursion_homework/recursion.rb
def sum_to(n)
	return 1 if n == 1
	return n + sum_to(n - 1)
end

def add_numbers(nums_array)
	return nums_array[0] if nums_array.length == 1
	return nil if nums_array.length == 0
	return nums_array[0] + add_numbers(nums_array[1..-1])
end

def factorial(n)
	return nil if n < 0
	return 1 if n == 0
	return n * factorial(n - 1)
end

def gamma(n)
	factorial(n - 1)
end

def ice_cream_shop(flavors, favorite)
	return false if flavors.length == 0
	return flavors[0] == favorite if flavors.length == 1
	return flavors[0] == favorite || ice_cream_shop(flavors[1..-1], favorite)
end

def reverse(str)
	return str if str.length <= 1
	return str[-1] + reverse(str[0...-1])
end<file_sep>/12_minesweeper/game.rb
require "./tile.rb"
require "colorize"

class Minesweeper

	def initialize
		@board = Array.new(10) { Array.new(10) { Tile.new } }
		@is_loss = 0
	end

	def render
		system("clear")
		puts "  0 1 2 3 4 5 6 7 8 9".yellow
		(0..9).each do |i|
			puts
			print i.to_s.yellow + " "
			@board[i].each { |tile|  print tile.render; print " "  }
			puts
		end
		puts
	end

	def game_over?
		return true if @is_loss == 1
		return false if @board.any? do |row|
			row.any? do |tile|
				tile.is_unrevealed_bomb?
			end
		end
		true
	end

	def is_valid_input?(input)
		return false if "rf".include?(input[0]) == false
		return false if (0..9).include?(input[1]) == false 
		return false if (0..9).include?(input[2]) == false
		return true
	end

	def get_input
		print "Enter an action (r for reveal or f for flag lowercase) and two digits (ex: r05 or f36): "
		input = gets.chomp
		while self.is_valid_input?(input) == 0
			print "Invalid input! Try again: "
			input = gets.chomp
		end
		input
	end

	def get_neighbors(coors)
		r = []
		[-1, 0, 1].each do |add_to_x|
			[-1, 0, 1].each do |add_to_y|
				new_x = coors[0] + add_to_x
				new_y = coors[1] + add_to_y
				if new_x.to_s.length == 1 && new_y.to_s.length == 1
					r << [new_x, new_y]
				end
			end
		end
		r
	end

	def count_neighbors(coor_arr)
		coor_arr.reduce(0) { |sum, num|  sum + @board[num[0]][num[1]].is_mine  }
	end

	def reveal_recursively(coors)
		neighbors = self.get_neighbors(coors)
		neighbor_count = self.count_neighbors(neighbors)
		@board[coors[0]][coors[1]].reveal(neighbor_count)
		if neighbor_count == 0
			neighbors.each do |target|
				self.reveal_recursively(target) if @board[target[0]][target[1]].render == "*"
			end
		end
	end

	def process_input(input)
		x_coor = input[1].to_i 
		y_coor = input[2].to_i
		action = input[0]
		if action == "r"
			coors = [x_coor, y_coor]
			target = @board[x_coor][y_coor]
			break if target.is_revealed == 1
			if target.is_mine == 1
				target.reveal
				@is_loss = 1
			else
				self.reveal_recursively(coors)
			end
		elsif action == "f"
			@board[x_coor][y_coor].flag
		end
	end

	def next_turn
		self.render
		input = self.get_input
		self.process_input(input)
	end

	def play
		while self.game_over? == false
			self.next_turn
		end
		self.render
		puts "You win, this time ..." if @is_loss != 1
		#self.announce_result
	end
end

Minesweeper.new.play<file_sep>/27_lru_cache/lru_cache.rb
class LRUCache

	def initialize(num=0)
		@cache = Array.new(num)
		@num = num
	end

	def add(element)
		@cache.delete(element)
		@cache.push(element)
		if @cache.length > @num
			@cache.shift
		end
	end

	def show
		p @cache
	end

	def count
		@cache.length
	end

end

<file_sep>/05_stack_trace/stack_trace.rb
MAX_STACK_SIZE = 200
tracer = proc do |event|
  if event == 'call' && caller_locations.length > MAX_STACK_SIZE
    fail "Probable Stack Overflow"
  end
end
set_trace_func(tracer)<file_sep>/25_poker/card.rb
require "./libft.rb"


class Card

RANKS = [ :A, :K, :Q, :J, 10, 9, 8, 7, 6, 5, 4, 3, 2   ]

SUITS = [ :heart, :diamond, :club, :spade  ]

attr_reader :suit, :rank

	def initialize(suit, rank)
		raise ArgumentError.new("#{suit} is not a valid suit") if SUITS.include?(suit) == false
		raise ArgumentError.new("#{rank} is not a valid rank") if RANKS.include?(rank) == false
		@suit = suit
		@rank = rank
	end

	def self.all_cards
		r = []
		RANKS.each do |rank|
			SUITS.each do |suit|
				r << self.class.new(suit, rank)
			end
		end
		r
	end

	def same_suit?(other_card)
		self.suit == other_card.suit
	end

	def same_rank?(other_card)
		self.rank == other_card.rank
	end

	def >(other_card)
		RANKS.index(self.rank) < RANKS.index(other_card.rank)
	end

	def <(other_card)
		RANKS.index(self.rank) < RANKS.index(other_card.rank)
	end


end<file_sep>/12_minesweeper/tile.rb
class Tile

	attr_reader :is_mine, :is_revealed

	def initialize
		rand(0..5) == 0 ? @is_mine = 1 : @is_mine = 0
		@is_mine = @is_mine.to_i
		@is_revealed = 0
		@is_flagged = 0
		@render_character = "*"
	end

	def is_unrevealed_bomb?
		return true if @is_mine == 1 && @is_flagged == 0
		false
	end

	def render
		@render_character
	end

	def flag
		if @is_flagged == 0 && @is_revealed == 0
			@is_flagged = 1
			@render_character = "F".light_blue
		elsif @is_flagged == 1 && @is_revealed == 0
			@is_flagged = 0
			@render_character = "*"
		end
		return @render_Character
	end

	def reveal(neighbor_bomb_count=0)
		if @is_revealed == 0
			if @is_mine == 1
				@render_character = "B".red
			else
				@render_character = neighbor_bomb_count.to_s
				@render_character = "_" if neighbor_bomb_count == 0
			end
			@is_revealed = 1
		end
		@render_character
	end
end<file_sep>/01_ghost/player.rb
class Player

	def initialize(name)
		@name = name
		@losses = 0
	end


	def announce_turn
		puts "current player: " + @name
	end

	def get_guess
		print "enter a letter: "
		gets.chomp
	end

	def invalid_guess
		puts
		puts "invalid guess! try again"
		puts
	end

	def lose_round
		puts @name + " lost this round :( "
		@losses += 1
	end

	def lost?
		@losses >= 5
	end

	def lose_game
		puts @name + " lost the game :( "
	end

end<file_sep>/00_enumerables/enumerables.rb
class Array
	def my_each
		i = 0
		while i < self.length
			yield self[i]
			i += 1
		end
	end

	def my_select(&prc)
		r = []
		self.my_each { |n| r << n if prc.(n) }
		r
	end

	def my_reject(&prc)
		r = []
		self.my_each { |n| r << n unless prc.(n) }
		r 
	end

	def my_any?(&prc)
		self.my_each { |n| return true if prc.(n)  }
		false 
	end

	def my_flatten
		self.map { |x| x.is_a?(Array) ? x.flatten : x }
	end

	def my_zip(*arg)
		r = Array.new([])
		self.each_with_index { |x, i| r[i] << self[i] }
		args.each_with_index { |x, i| r[i] << x[i] }
		r
	end

	def my_rotate(p1 = 1)
		r = self.dup
		p1.times { r.push(r.shift) }
		r 
	end

	def my_join(p1 = "")
		self.reduce() { |sum, num| sum.to_s + p1 + num.to_s }
	end

	def my_reverse
		(0...l).map { |i|  }
	end

end
<file_sep>/20_class_inheritance/employee.rb
class Employee

	attr_reader :name, :title, :boss, :salary

	def initialize(name, salary, title, boss)
		@name = name
		@title = title 
		@boss = boss 
		@salary = salary
	end

	def bonus(multiplier)
		@salary * multiplier
	end

end<file_sep>/12_minesweeper/README.md
# App_Academy_Ruby


Image of the Mine Sweeper project

![Screen Shot of Mine Sweeper](../screen_show.png?raw=true "Mine Sweeper")
<file_sep>/29_hash_map_lru_cache/lib/p01_int_set.rb
class MaxIntSet
  def initialize(max)
	@store = Array.new(max) {false}
	@max = max
  end

  def insert(num)
	#raise ArgumentError.new("Can only accept integers") if num.is_a? FixNum == false
	raise ArgumentError.new("Out of bounds") if num < 0
	raise ArgumentError.new("Out of bounds") if num >= @max
	if @store[num] == false
		@store[num] = true
		return true
	else
		return false
	end
  end

  def remove(num)
	#raise ArgumentError.new("Can only accept integers") if num.is_a? FixNum == false
	raise ArgumentError.new("Out of bounds") if num < 0
	raise ArgumentError.new("Out of bounds") if num >= @max
	@store[num] = false
  end

  def include?(num)
	#raise ArgumentError.new("Can only accept integers") if num.is_a? FixNum == false
	raise ArgumentError.new("Can only accept non-negative numbers") if num < 0
	raise ArgumentError.new("Invalid argument: #{num} is greater than #{@max}") if num >= @max
	return @store[num]
  end

  private

  def is_valid?(num)
	return true if 0 <= num && num < max
	false
  end

  def validate!(num)
  end
end


class IntSet
  def initialize(num_buckets = 20)
	@store = Array.new(num_buckets) { Array.new }
	@size = num_buckets
  end

  def insert(num)
	if self[num].include?(num) == false
		self[num].push num
		return true
	end
	false
  end

  def remove(num)
	if self[num].include?(num) == true
		self[num].delete num
		return true
	end
	false
  end

  def include?(num)
	return self[num].include?(num)
  end

  private

  def [](num)
	# optional but useful; return the bucket corresponding to `num`
	@store[num % @size]
  end

  def num_buckets
    @size
  end
end

class ResizingIntSet
  attr_reader :count, :max, :store

  def initialize(num_buckets = 20)
    @store = Array.new(num_buckets) { Array.new }
	@count = 0
	@max = num_buckets
  end

  def insert(num)
	resize! if @count == @max
	if self[num].include?(num) == false
		self[num].push(num)
		@count += 1
		return true
	end
	false
  end

  def remove(num)
	if self[num].include?(num) == true
		self[num].delete(num)
		@count -= 1
		return true
	end
	false
  end

  def include?(num)
	self[num].include?(num)
  end

  private

  def [](num)
	# optional but useful; return the bucket corresponding to `num`
	@store[num % @max]
  end

  def num_buckets
    @max
  end

  def resize!
	@max *= 2
	new_store = Array.new(@max) {Array.new}
	@store.each do |bucket|
		bucket.each do |number|
			new_store[number % @max].push(number)
		end
	end
	@store = new_store
  end
end
