Last active
April 25, 2019 10:12
-
-
Save KevinSia/a0d6d60ef1dad081fb234cf8ec8d534f 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
# generates a tic tac toe array with the right ratio of 'x' and 'o' | |
def generate_realistic_tic_tac_toe | |
# hardcode 4 'X's and 4 'O's, then pick one on random from ['X', 'O'] | |
one_d = (%w(X X X X O O O O) << %w(X O).sample).shuffle | |
return one_d.each_slice(3).to_a | |
end | |
# turns the array of players into array of hashes | |
def convert_roster_format(roster) | |
header = roster.shift | |
roster.map { |player| Hash[header.zip(player)] } | |
end | |
# LONGER SOLUTION | |
# def convert_roster_format(roster) | |
# header = roster.shift | |
# result = [] | |
# roster.each do |player_details| | |
# hash = {} | |
# header.each_with_index do |title, index| | |
# hash[title] = player_details[index] | |
# end | |
# result << hash | |
# end | |
# result | |
# end | |
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] ], | |
[7, "Sally Talls", "Power Forward", [18, 29, 26, 31, 19] ], | |
[22, "MK DiBoux", "Small Forward", [11, 0, 23, 17, 0] ]] | |
p convert_roster_format(roster) | |
# p generate_realistic_tic_tac_toe.flatten.map(&:downcase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment