Last active
January 14, 2016 09:08
-
-
Save yclim95/3cd0c1321279300d3e05 to your computer and use it in GitHub Desktop.
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
#Tic_Tac_Toe revisited | |
def create_tick_tack_toe_table | |
tick_tack_toe_table=Array.new(3) {Array.new(3) } | |
choice=['X','0'] | |
(0..2).each { |x| | |
(0..2).each {|y| | |
tick_tack_toe_table[x][y]=choice.sample | |
} | |
} | |
return tick_tack_toe_table | |
end | |
def print_table(game) | |
game.each{|x| | |
puts x.inspect | |
} | |
puts | |
end | |
def print_row_column(time) | |
counter=1 | |
while time>0 | |
game_start=create_tick_tack_toe_table | |
puts "Tick Tack Toe ##{counter}" | |
print_table(game_start) | |
time-=1 | |
counter+=1 | |
end | |
end | |
print_row_column(10) | |
#Convert nested ARRAY to hash | |
roster=[["Number","Name","Position","Points per Game"], | |
[12,"Joe Schmo","Center",[14,32,7,0,23]], | |
[9,"Ms. Buckets","Point Guard",[19,0,11,22,0]], | |
[31,"Harvey Kay","Shooting Guard",[0,30,16,0,25]], | |
[18,"Sally Talls","Power Foward",[18,29,26,31,19]], | |
[22,"MK DiBoux","Small Foward",[11,0,23,17,0]]] | |
def convert_roster_format(roster) | |
header = roster.shift | |
result = [] | |
roster.each do |row| | |
x = Hash.new | |
counter = 0 | |
row.each do |attribute| | |
x[header[counter]] = attribute | |
counter = counter + 1 | |
end | |
result << x | |
end | |
return result | |
end | |
hashed_roster = convert_roster_format(roster) | |
puts hashed_roster[0]["Name"] == "Joe Schmo" #return TRUE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment