Skip to content

Instantly share code, notes, and snippets.

@all4miller
Last active February 23, 2017 10:31
Show Gist options
  • Save all4miller/9fc338fe268459ca51b26dd84ccb3e29 to your computer and use it in GitHub Desktop.
Save all4miller/9fc338fe268459ca51b26dd84ccb3e29 to your computer and use it in GitHub Desktop.
Wizard
class School
SCHOOL_DATA = [
{
name: 'Beauxbatons Academy of Magic',
location: 'Pyrenees, France',
courses: {
muggle_studies: 5,
wand_practice: 41,
defence_against_the_dark_arts: 25,
herbology: 15,
quidditch: 100
}
},
{
name: 'Castelobruxo',
location: 'Amazon rainforest, Brazil',
courses: {
advanced_broom_making: 32,
wand_practice: 54,
defence_against_the_dark_arts: 10,
scrying: 80,
beast_studies: 100
}
},
{
name: 'Durmstrang Institute',
location: 'Scandinavia',
courses: {
potions: 35,
wand_practice: 10,
dark_arts: 90,
dueling: 63,
advanced_animagus: 8
}
},
{
name: 'Hogwarts School of Witchcraft and Wizardry',
location: 'Highlands, Scotland',
courses: {
wand_practice: 22,
magical_creatures_studies: 70,
potions: 90,
defence_against_the_dark_arts: 90,
herbology: 38
}
},
{
name: 'Ilvermorny School of Witchcraft and Wizardry',
location: 'Mount Greylock, United States of America',
courses: {
magical_creatures: 53,
wand_practice: 22,
dark_arts: 41,
magical_banking: 89,
quidditch: 40
}
}
]
def self.best_suited_for(student_ratings = {})
return '' unless student_ratings.count { |_, rating| rating > 0 } >= 5
SCHOOL_DATA.max_by do |school|
school[:courses].map do |course, score|
score * student_ratings[course].to_i
end.reduce(:+)
end
end
end
ratings = {
muggle_studies: 1,
wand_practice: 9,
defence_against_the_dark_arts: 0,
herbology: 3,
quidditch: 6,
advanced_broom_making: 0,
scrying: 8,
potions: 0,
dueling: 0,
advanced_animagus: 0,
magical_creatures_studies: 0,
magical_creatures: 0,
magical_banking: 0
}
School.best_suited_for(ratings) # must equal 'Castelobruxo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment