This file contains hidden or 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
def delete_from_array(cells) | |
human_spaces = human_location(cells) | |
human_spaces.map!(&:to_i) | |
@comp_winning_combos.each do |sub_array| | |
intersect = sub_array & human_spaces | |
if intersect.any? | |
difference = sub_array - human_spaces | |
sub_array.clear |
This file contains hidden or 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
def smart_move(cells) | |
comp_spaces = comp_location(cells) | |
wins_left = delete_from_array(cells) | |
comp_spaces.map!(&:to_i) | |
options = [] | |
if comp_spaces.empty? | |
return [5] |
This file contains hidden or 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
def find_block_move(cells) | |
human_winning_combos = [[1,2,3], [4,5,6], [7,8,9], | |
[1,4,7], [2,5,8], [3,6,9], | |
[1,5,9], [3,5,7]] | |
human_spaces = human_location(cells) | |
human_spaces.map!(&:to_i) | |
to_block = [] |
This file contains hidden or 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
def moves_left(cells) | |
move = [] | |
cells.each do |k,v| | |
move << k if cells[k] != "X" && cells[k] != "O" | |
end | |
move | |
end |
This file contains hidden or 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
class RomanNumerals | |
attr_reader :numerals_hash | |
def initialize | |
@numerals_hash = {1 => "I", 5 => "V", | |
10 => "X", 50 => "L", 100 => "C", | |
500 => "D", 1000 => "M"} | |
end | |
def find_base(number) |
This file contains hidden or 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
class RomanNumerals | |
attr_reader :numerals_hash | |
def initialize | |
@numerals_hash = {1 => "I", 4 => "IV", 5 => "V", 9 => "IX", | |
10 => "X", 50 => "L", 100 => "C", | |
500 => "D", 1000 => "M"} | |
end | |
def convert(number) |
This file contains hidden or 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
class RomanNumerals | |
attr_reader :numerals_hash | |
def initialize | |
@numerals_hash = {1 => "I", 2 => "II", 3 => "III", 4 => "IV", | |
5 => "V", 6 => "VI", 7 => "VII", | |
8 => "VIII", 9 => "IX", 10 => "X", | |
40 => "XL", 50 => "L", 100 => "C", | |
500 => "D", 1000 => "M"} | |
end |
This file contains hidden or 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
class RomanNumerals | |
def convert(number) | |
roman = "" | |
bases = { 1000 => "M", 900 => "CM", 500 => "D", 100 => "C", | |
90 => "XC", 50 => "L", 40 => "XL", 10 => "X", | |
9 => "IX", 5 => "V", 4 => "IV" } | |
bases.each do |arabic, base| | |
while number >= arabic | |
roman += base |
This file contains hidden or 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
#code in txt file | |
FIRST_NAME,LAST_NAME,EMAIL | |
Albus,Dumbledore,<[email protected]> | |
Harry,Potter,<[email protected]> | |
Ron,Weasley,<[email protected]> | |
Hermione,Granger,<[email protected]> | |
Draco,Malfoy,<[email protected]> | |
#code in Secret Santa class |
This file contains hidden or 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
def same_last_name?(list) | |
last_name = list.group_by { |h| h["LAST_NAME"] }.values.select { |a| a.size > 1}.flatten | |
return false if last_name.empty? | |
list | |
end |