Context
At Hogwarts School of Witchcraft and Wizardry, students are sorted into 4 houses, Gryffindor
, Ravenclaw
, Slytherin
and Hufflepuff
. This sorting is done by a magical hat, called the Sorting Hat.
Task
Your task is to code a sorting hat. In other words, you should create some deterministic rule that, given the name of a person, outputs one of the four available houses. (See the output section for a restriction on the rule)
Input
Input will be a string (representing the student name) in the ascii range [32, 126]
, the printable characters.
This is not necessarily an English name. The input may be "@_??" and your code should still assign a house.
Output
For a fixed string (any string of printable ASCII characters), your code should always output the same house, thus your code should be deterministic. The output has to uniquely identify the houses, in any of the following ways:
- returning the full house name, e.g.
"Gryffindor"
(capitalization doesn't matter) - returning the house initial, e.g.
"G"
(capitalization doesn't matter) - returning the house index, e.g.
0
(you may use any house ordering as long as the indexing is done with0, 1, 2, 3
or1, 2, 3, 4
and as long as you specify it in your answer.)
What is more, there are 12 cases that should be as follows:
- the inputs
harry
,hermione
andron
should returngryffindor
; - the inputs
luna
,cho
andpenelope
should returnravenclaw
; - the inputs
draco
,crab
andgoyle
should returnslytherin
; - the inputs
cedric
,ernie
andhannah
should returnhufflepuff
;
You can either get these 12 inputs as stated, or the 12 inputs where the first letter is upper case (e.g. Harry
).
You should also prove that there are other English names in this list that get mapped into each house.
Be sure to include the house that your code assigns to your own codegolf.SE nickname, plus the house rgs
or RGS
gets assigned to. Bonus imaginary internet points if I get assigned to Ravenclaw
!!!
As of now, these answers qualify for the bonus imaginary internet points: G B Ruby answer, ovs Python answer, Kevin Cruijssen Whitespace answer, Jonathan Allan Jelly answer, Nick Kennedy Jelly answer, Kaddath PHP answer, Noodle9 C answer, 640KB x86-16 answer, Guillermo Phillips PHP answer, Jonathan Alan Python 2 answer, Bob Jarvis - Reinstate Monica Clojure answer, Mitchell Spector Bash answer.
Test cases
"Harry" -> "Gryffindor"
"Hermione" -> "Gryffindor"
"Ron" -> "Gryffindor"
"Luna" -> "Ravenclaw"
"Cho" -> "Ravenclaw"
"Penelope" -> "Ravenclaw"
"Draco" -> "Slytherin"
"Crab" -> "Slytherin"
"Goyle" -> "Slytherin"
"Cedric" -> "Hufflepuff"
"Hannah" -> "Hufflepuff"
"Ernie" -> "Hufflepuff"
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
random
tag? \$\endgroup\$vincent
. Alsogoyle
should begregory
. \$\endgroup\$