[Question]
  [
# 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 with `0, 1, 2, 3` or `1, 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` and `ron` should return `gryffindor`;
* the inputs `luna`, `cho` and `penelope` should return `ravenclaw`;
* the inputs `draco`, `crab` and `goyle` should return `slytherin`;
* the inputs `cedric`, `ernie` and `hannah` should return `hufflepuff`;
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](https://babynames.net/all/english) 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](https://codegolf.stackexchange.com/a/199683/75323), [ovs Python answer](https://codegolf.stackexchange.com/a/199683/92069), [Kevin Cruijssen Whitespace answer](https://codegolf.stackexchange.com/a/199688/75323), [Jonathan Allan Jelly answer](https://codegolf.stackexchange.com/a/199725/75323), [Nick Kennedy Jelly answer](https://codegolf.stackexchange.com/a/199695/75323), [Kaddath PHP answer](https://codegolf.stackexchange.com/a/199710/75323), [Noodle9 C answer](https://codegolf.stackexchange.com/a/199729/75323), [640KB x86-16 answer](https://codegolf.stackexchange.com/a/199734/75323), [Guillermo Phillips PHP answer](https://codegolf.stackexchange.com/a/199741/75323), [Jonathan Alan Python 2 answer](https://codegolf.stackexchange.com/a/199746/75323), [Bob Jarvis - Reinstate Monica Clojure answer](https://codegolf.stackexchange.com/a/199910/75323), [Mitchell Spector Bash answer](https://codegolf.stackexchange.com/a/199948/75323).
# 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](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
  
[Answer]
# [Python 2](https://docs.python.org/2/), 30 bytes
Input is lower case name, output is `1` for Gryffindor, `0` for Ravenclaw, `2` for Slytherin and `3` for Hufflepuff.
```
lambda n:hash(n)%94%69%45%17%4
```
[Try it online!](https://tio.run/##HY6xDsIwDER3vsJLlFbqAiqgVmJmh5XFTV0SKXUiU4Z@fcCZ3tPdDZf3zSc@leX2KhHXaUbg0ePHN9yaoTeXwfRnc7yavixJgHElCAzWo8huu7@QrCExqUtiRfwyKp1PikxMMeW6mAVdDZ3gpHynPdbG0SzBqZFwqJFHZvRqj/vTjgeALIG3eqKDpVG25Qc "Python 2 – Try It Online")
`RGS` is in Ravenclaw.
---
# [Python 2](https://docs.python.org/2/), 34 bytes
Takes names in lower case and outputs upper case house initials.
```
lambda n:'HSHHSRRG'[hash(n)%189%8]
```
[Try it online!](https://tio.run/##HY2xDoMwDET3fkUWFJBY2okidS4zjG0HE0wdKTiRSwe@Pq0zvae7ky4dO0W@5PX2zAG2eQHDvR2mYZjG8W4fBB@quanO3bXqXnmNYhg2NJ6NJRA5bPsXlM1HRnWJrAhfBqWjqEjIGGIqi0XAldAJzMp3PEJpHC7inRoK@xIRMAPZ/mRMEs97eW/NWiub/AM "Python 2 – Try It Online")
---
# [Python 2](https://docs.python.org/2/), 34 bytes
Input with first letter in upper case, output is the house indices.
```
lambda n:~hash(n)%74%64%27%16%11%4
```
[Try it online!](https://tio.run/##Hc6xCoNADAbgvU@R5VDBRREFoZMtdSi0dO4S9ewdaE6iLbj01a/NTd/PnxCy7JtxlPvx@PQTzt2AQPXX4GpiSlRVqLJQeaWyUmWZKvzoGAhnDZYgapF5j9J/0DxbR1ryw5FwfROKjXHCXZOe3BI2Tox9KBvGTry4fQqTRg9se0lnJhuqFonQhMOvVbh91qg@ACxsaQu/pDDGYuJ/ "Python 2 – Try It Online")
`Rgs` gets assigned to Ravenclaw, `Ovs` to Gryffindor.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 35 bytes
Expects the names in title case. Returns \$0\$ for Gryffindor, \$1\$ for Hufflepuff, \$2\$ for Slytherin or \$3\$ for Ravenclaw.
```
s=>(([a]=Buffer(s))[3]*9|a*553)%9&3
```
[Try it online!](https://tio.run/##jZFNS8NAEIbv/oplQEkq2kPooYcIfpEePEh6rD2MyaxZWWfDpKkE/O8xqGDdJTWXOT3z8sy8r7jHphBT7y7YldTrtG/Sqyja4Da9abUmiZo43iTb2fIDZ4tFEp8uz5K@cNw4S5fWvUQ6ghWKdKCUipX6mvO5gkw6rQ2XTuDE50nejGOCiXzuGL7Jc3hi@Jd/aBlBeT457okLi@8Bflu5n/hJ@CMxWVcP9gc24/idYOH856xtt6tIDIcygs@B@zieuc4SeK85kk6lmAL@pq@Goi3VwwybQmasRnkfvxc2gc1hvL9wLYytLWGqT56tw6p@z@0/AQ "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 40 bytes
Returns the house initial in upper case.
```
s=>"SSHGRHGR"[parseInt(s,28)*51%78%10&7]
```
[Try it online!](https://tio.run/##jZFNS8RADIbv/oohsNL1a11Bdi8riEoreJD2qB5im7EjY6ak7Up/fS0quM5QLYScnrw8SV5xi3UupmqO2RXU601fby4gy5I4HQoeKpSabrmJ6qOz9fzgfDlbrWfL0/3VU587rp2lE@teIh1BgiIdKKXmSn32xUJBLJ3WhgsnsOfzJG/GMcFEPnUMX@QhPDL8y9@1jKA8nxS3xLnF9wC/Kt13/CT8npisqwb7HZtx/Fowd/5xMts1JYnhUEbwOXAfx2PXWQLvNH@kUyEmh9/pSau1pWro4aeQGctR3sdvhE1gsxvvD1wKY2sLmOqTxln4qp91@w8 "JavaScript (Node.js) – Try It Online")
### How?
The base formula that maps our 12 wizard students to the relevant houses is:
```
"SSHGRHGRS?"[parseInt(s, 28) * 51 % 78 % 10]
```
We first parse the input as Base-28. Valid input strings in this base must consist of an optional leading unary operator (`+` or `-`), followed by a sequence of characters matching `[0-9A-Ra-r]+`. If the whole string is invalid, it is parsed as \$NaN\$. Otherwise, the parsing stops just before the first invalid character.
*Example:*
```
parseInt("harry", 28) == parseInt("harr", 28) // -> 381807
```
There are, obviously, countless ways of building the hash formula and the corresponding lookup table \$t\$.
Among all brute-forced formulas, this one was chosen because:
* \$t[8]=t[0]\$ and we don't care about the value of \$t[9]\$, which means that we can apply a final modulo \$8\$ to get 8 entries.
* This modulo \$8\$ can be turned into a bitwise AND with \$7\$, which also guarantees that the index will be forced into \$[0..7]\$ even if the input string is parsed as \$NaN\$ or a negative value.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Updated 8-byter so that the bonus is fulfilled for ***both*** `'rgs'` ***and*** `'RGS'` :)
```
“EwS’,4ḥ
```
A monadic Link accepting a list of characters which yields:
```
4: Gryffindor
2: Ravenclaw
1: Slytherin
3: Hufflepuff
```
**[Try it online!](https://tio.run/##y0rNyan8//9RwxzX8uBHDTN1TB7uWPr//3/1ovw8dQA "Jelly – Try It Online")**
Or see a **[test-suite](https://tio.run/##JYwxDsIwDEWv0i1LR66A2OlYdTCJ1QRMUrmgKlvFwhmQWNk4ADsnIRcJdSpZel/f//8jEsWc0/zcTk2aH/Xm93nl7z3d3svl3CoLzFHVlbLIZxc8iubgBWCMGxfZ1VWr6OpBTG2DYECPFIYSB31CJiwz3I@C/a5Za4ZBl4JmOAj7EGltkZkgrimNhp0WF9m78rbgPdgSxItFYjSq@wM "Jelly – Try It Online")** showing the 3 given names belonging to each house, that an extra name exists in the linked name-list for each house and that both `'rgs'` and `'RGS'` are in `2`, Ravenclaw.
Places `'Jonathan Allan'` in Ravenclaw.
### How?
```
“¢Ʋ⁹’,4ḥ - Link: list of characters
“EwS’    - base 250 number = 4405084
      4  - 4
     ,   - pair
       ḥ - hash using:
             4405084 as a salt, and
             implicit range(4) = [1,2,3,4] as the domain
```
---
# 11-byter:
```
OP%⁽MJ%23%4
```
A monadic Link accepting a list of characters which yields:
```
3: Gryffindor
2: Ravenclaw
1: Slytherin
0: Hufflepuff
```
(Bonus fulfilled for `'rgs'`)
**[Try it online!](https://tio.run/##y0rNyan8/98/QPVR415fL1UjY1WT////qxelF6sDAA "Jelly – Try It Online")**
Or see a **[test-suite](https://tio.run/##LcwxDsIwDAXQq3SpsnQCToGEYK86mMRqAq5TuTBkhIXLcAUmbtKLhLpBsvStr2dfkCjlfDzV8@Nz2Nebbb3L39f8fC@Tc2s8iCTTVMajDCEy6i6RNcBeUSiZrqlaQ3cGLa2PGiMyUhyxuFs5kH4q2AnYlVmBs2YfExXrYAAJf2fRSbDao3BYgQdm8IW6MC2Pux8 "Jelly – Try It Online")** showing the 3 given names belonging to each house, that an extra name exists in the linked name-list for each house and that `'rgs'` is in `2`, Ravenclaw.
Places `'Jonathan Allan'` in Slytherin.
### How?
```
OP%⁽MJ%23%4 - Link: list of characters  e.g. 'rgs'
O           - ordinals                       [114,103,115]
 P          - product      114 * 103 * 115 = 1350330
   ⁽MJ      - 20325                          20325
  %         - modulo       1350330 % 20325 = 8880
       23   - 23                             23
      %     - modulo             8880 % 23 = 2
          4 - 4                              4
         %  - modulo                 2 % 4 = 2
```
Here is a Python script which will print viable `i j {G} {R} {S} {H}` results for code like `OP%i%j%4` for which each of `i` and `j` are small enough to write within three bytes. The first result happens to place `'rgs'` in Ravenclaw.
```
from functools import reduce
a,b,c,d = (['harry', 'hermione', 'ron'], ['luna', 'cho', 'penelope'], ['draco', 'crab', 'goyle'], ['cedric', 'ernie', 'hannah'])
pa,pb,pc,pd = ([reduce(lambda x,y:x*y, map(ord,n)) for n in v] for v in (a,b,c,d))
for j in range(5, 32251):
    for i in range(j, 32251):
        i+=1
        A=set(v%i%j%4 for v in pa)
        B=set(v%i%j%4 for v in pb)
        if A&B: continue
        C=set(v%i%j%4 for v in pc)
        if A&C or B&C: continue
        D=set(v%i%j%4 for v in pd)
        if A&D or B&D or C&D: continue
        print(i, j, A, B, C, D)
        break
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~30~~ 31 bytes
```
->x{"HSSRGRHHGRR"[x.sum%91%11]}
```
[Try it online!](https://tio.run/##Dc0xCoNAEAXQq3wEu0SwTJE0JuwWFmEtF4vRjCjorEyQrGjObvIu8HRp1qO7Hudb3BJbVc44a41ziY/Ze5nSS57mef090o@3pLrCsk5DEIYLgnIRQtEHPFl4DDPjrtQGFEoNTFhHRsEvHVo8VAaGJRHq4UxVZxPN2x73GT6eOh/rf/ID "Ruby – Try It Online")
Returns initial of house. RGS is on Ravenclaw
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~14~~ 12 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
•Sâ;»•4вs1öè
```
Outputs `0123` instead of `GRSH`.
-2 bytes thanks to *@Grimmy* (unfortunately it no longer got the internet bonus for outputting Ravenclaw for `RGS`).
[Try it online.](https://tio.run/##DcsxCsJAEAXQ/t9GtLNzlSxoIeYEs3EgC3FGJigEFDxLKmtRGzu3F8/gRdZ0r3naUoicT59H/l36MvXT92vA5HtrR@mZrvk8TvfsyayDZ9tFFcZGBauDEFytWLNwo3vG3KhSOKOAQruG4XhrsYInEaqxMIlDLUos@RgFMw1/)
**Explanation:**
```
•Sâ;»•        # Push compressed integer 478937616
      4в      # Convert it to base-4 as list: [1,3,0,2,0,3,0,0,0,0,2,0,1,0,0]
        s1ö   # Take the input, and convert it from base-1 to a base-10 integer
              # which will essentially sum the indices of the characters in the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzǝʒαβγδεζηθвимнт\nΓΔΘιΣΩ≠∊∍∞₁₂₃₄₅₆ !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~Ƶ€Λ‚ƒ„…†‡ˆ‰Š‹ŒĆŽƶĀ‘’“”–—˜™š›œćžŸā¡¢£¤¥¦§¨©ª«¬λ®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
           è  # And use that to (modular) index into the earlier created list
              # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (sections *How to compress large integers?* and *How to compress integer lists?*)](https://codegolf.stackexchange.com/questions/96361/tips-for-golfing-in-05ab1e) to understand why `•Sâ;»•` is `478937616` and `•Sâ;»•4в` is `[1,3,0,2,0,3,0,0,0,0,2,0,1,0,0]`.
[Answer]
# [Python 2](https://docs.python.org/2/), 24 bytes
```
lambda n:hash(n)/64779%4
```
```
3: Gryffindor
0: Ravenclaw
2: Slytherin
1: Hufflepuff
```
Bonus fulfilled for `'rgs'` while `'Jonathan Allan'` is placed in Slytherin.
**[Try it online!](https://tio.run/##Pc9NCsJADAXgvafIRtqCIIgoCp5EXcSZ1AxOk5LqoqevzfizemHyBeb145NVNlN7ukwZu1tEkCPjwLU06912vz8st1OrBqyvgSAJ1AuAumI0G6sVVEzWJRXy2VQ8MDzIMo1Vsyo2vwT9PbB69CSUtS8XGDW35fQ@/Hg0DAUGw5vnXcf81dihpb8MFC0F35BJKoRRBPmDYxrmD822Oc4coLckTzi3tWBHDXgrn7xUaXed3g "Python 2 – Try It Online")**
[Answer]
# x86-16 machine code, IBM PC DOS, ~~37~~ ~~32~~ 30 bytes
**Binary:**
```
00000000: 92be 8200 ad8a e0ac b3be f7f3 92d4 08bb  ................
00000010: 1601 d7cd 29c3 4853 5252 4753 5252       ....).HSRRGSRR
```
Build `HAT.COM` from above using `xxd -r`.
**Unassembled listing:**
```
92          XCHG AX, DX             ; DX = 0 
BE 0082     MOV  SI, 82H            ; SI to input string (char*s)
AD          LODSW                   ; AL = s[0], SI = SI + 2 
8A E0       MOV  AH, AL             ; AH = s[0] 
AC          LODSB                   ; AL = s[2] 
B3 BE       MOV  BL, 190            ; divisor = 190 
F7 F3       DIV  BX                 ; DX = AX % 190 
92          XCHG AX, DX             ; AX = DX 
D4 08       AAM  8                  ; AL = AL % 8 
BB 011D     MOV  BX, OFFSET S       ; BX = output string table 
D7          XLAT                    ; AL = [BX][AL]
CD 29       INT  29H                ; DOS fast console output  
C3          RET                     ; return to DOS 
S           DB "HSRRGSRR"           ; house char table
```
A standalone PC DOS executable. Input via command line, output to console is the house initial `{"G","R","S","H"}`.
All credit goes to @Noodle9, as this is really just a port of [that answer](https://codegolf.stackexchange.com/a/199729/84624). I promise to try harder next time.
**I/O:**
[![enter image description here](https://i.stack.imgur.com/JnOiw.png)](https://i.stack.imgur.com/JnOiw.png)
[![enter image description here](https://i.stack.imgur.com/AWPn3.png)](https://i.stack.imgur.com/AWPn3.png)
[Answer]
# [Python 2](https://docs.python.org/2/), 25 bytes
```
lambda n:hash(n)%814329%4
```
[Try it online!](https://tio.run/##HY6xDoMwDET3foUXBEgspQwtUmf2du1iQqgjBTty6cDXp3Wm93R3w6VjJ@E@r/dXjrjNCwKPhB9quK2u5@HS36ohr6LAuHkIDDWh6lF3f/G6BWFvrsKG@GU0OhJD8uyjpLJYFF0JneJsfMsRS@P8osGZeeVQIkJmJLPH9KzHE0DSwHs50cHaGNv8Aw "Python 2 – Try It Online")
Firstly, forgive me for mostly ripping off ovs's answer but this is my first ever golf "putt", so I'm taking it for posting practice!
2: Gryffindor  
3: Ravenclaw  
1: Slytherin  
0: Hufflepuff
RGS -> Slytherin and Belly Buster -> Slytherin!
[Answer]
# [PHP](https://php.net/), ~~36~~ ~~33~~ ~~31~~ 29 bytes
```
<?=467921>>crc32($argn)%20&3;
```
[Try it online!](https://tio.run/##DcyxDgFBEIDhfp5CgVBI2BMiOMXhrlBceIKxJnaTNbOZc8W9vLXd3/xfdDGlw@m43mx3ZlWWVm1hZmPUN88nZjkt9ik1qDpAQ/rxwgR3Ybj1jFA5gZaYgkSCs6IVqBSfUMsQCCp6qbfQIDM6uCj7vNYPqHsfQrZk1LpcPnY/id8sd2lx/QM "PHP – Try It Online")
I'm in danger of turning into a one trick pony.
2=Gryffindor, 1=Ravenclaw, 0=Slytherin, 3=Hufflepuff
I'm in Ravenclaw along with @RGS!
[Answer]
# Python 3.8, 18 bytes
Sharing because it's an amusing solution!
If invoked with the following environment variable `PYTHONHASHSEED=895984` ([apparently this does not have to be counted](https://codegolf.meta.stackexchange.com/questions/14337/command-line-flags-on-front-ends/14339#14339) towards byte length),
```
lambda s:hash(s)%4
```
[Try it online!](https://tio.run/##FY/RS8MwEMb/lXMg6WD64oROKVNwrE8q1hepRdI0aQLZJSSttoz97fXyct93v@OO71oe9fL@9Vm@vZbPVVkdDi9Fvrvf5Vvw86Ad3t3mcCNgpYuaHcOslMHOBbZh5aiUld6SUPfBfyUKy//IV5Y2ZTDImkdPa5qHMBMndjIOJdngkKodkZMI7ah6idI6n6Zd4CIhEXhL0rvZJixkF4wgIwOaBDRH5Dqd62PKcKzYBuicQT7EMfmnn/2eUqjie7H81HYc4oOml7O4vt4utaeQQ6bYebpA72SEwcFZ1yqb1s3liq1BuQATGATfrJZ/ "Bash – Try It Online")
given lowercase input,
* 0 => Gryffindor
* 1 => Hufflepuff
* 2 => Ravenclaw
* 3 => Slytherin
`RGS` (and `rgs`) goes to Ravenclaw, `chinatsu` goes to Gryffindor.
In the range `[0, 895984]` there are 3 good seeds, `139840`, `330811`, and `895984`. Only the latter places `RGS` in Ravenclaw.
[Answer]
## [W](https://github.com/A-ee/w) `d`, ~~19~~ 18 bytes
Port of G B's answer. (RGS is also on Ravenclaw.)
BTW, my name can't be entered in the W interpreter, so I do not belong in any house.
* I forgot that the operator overloading exists, so -1 byte due to the order-free indexing.
```
r#↔X┌3ÇMQyΘf○ºÞΘ☺¬
```
Uncompressed:
```
CJ91m11m"HSSRGR HGRR"[
```
## Explanation
```
C                      % Convert the input to a list of characters
 J                     % Reduce the list by addition
  91m                  % Modulus by 91
     11m"HSSRGR HGRR"[ % Cyclic indexing into the string
```
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~50~~ \$\cdots\$ ~~47~~ 42 bytes
Added a byte to fix a bug kindly pointed out by [RGS](https://codegolf.stackexchange.com/users/75323/rgs).  
Saved 2 bytes thanks to [S.S. Anne](https://codegolf.stackexchange.com/users/89298/s-s-anne)!!!  
Saved 5 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!!!  
```
#define f(s)"HSRRGSRR"[(*s<<8|s[2])%190%8]
```
[Try it online!](https://tio.run/##hZJBi8IwEIXv/oqQpZAsFlxPiuLFXerBg9SjeogxXQN1IlM9yLq/vbZm6tEJBL4J7828wNjUlgZ@6/rj4AoPThSq0nKxzvOsuXKjPqvpdHSvNsOdTr7Gg2S0qz1cxMl4UFr89UR7zti8FUomlUjTmUjsFmRfLgziTfYLtSTUevJW7/DkAziydBXjygNEQwuMdnkFE8VPYtTzY4jiFrgU2ZpSNMBoVw5cGc70z1fFuL7RWMoTkUuPZk/xW2LUWbiVFCgi190d0FvqH5lx/CB4mhCR2wYDYI7d@jy5c6C7XBHEYNL7rx8 "C (clang) – Try It Online")
Inputs a capitalised name string and returns `G`, `H`, `S`, or `R`.  
[RGS](https://codegolf.stackexchange.com/users/75323/rgs) is in Ravenclaw!!! 
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 295 bytes
```
[S S S N
_Push_0][N
S S T   T   N
_Create_Label_LOOP][S N
S _Dupe][S N
S _Dupe][T  N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve_input][S N
S _Dupe_input][S S S T  S T S N
_Push_10][T S S T   _Subtract][N
T   S T S N
_If_0_Jump_to_Label_DONE][T S S S _Add][N
S N
T   T   N
_Jump_to_Label_LOOP][N
S S T   S N
_Create_Label_DONE][S N
N
_Discard][S S S T   S T T   S T T   N
_Push_91][T S T T   _Modulo][S S S T    S T T   N
_Push_11][T S T T   _Modulo][S N
S _Dupe][N
T   S S S N
_If_0_Jump_to_Label_HUFFELPUFF][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S T N
_If_0_Jump_to_Label_SLYTHERIN][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S T N
_If_0_Jump_to_Label_SLYTHERIN][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S N
_If_0_Jump_to_Label_RAVENCLAW][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S S N
_If_0_Jump_to_Label_GRYFFINDOR][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S N
_If_0_Jump_to_Label_RAVENCLAW][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S N
_If_0_Jump_to_Label_RAVENCLAW][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S S S N
_If_0_Jump_to_Label_HUFFELPUFF][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Dupe][N
T   S S N
_If_0_Jump_to_Label_GRYFFINDOR][N
S S N
_Create_Label_RAVENCLAW][S S S T    N
_Push_1][T  N
S T _Print_as_integer][N
N
N
_Exit_Program][N
S S S N
_Create_Label_GRYFFINDOR][T N
S T _Print_as_integer][N
N
N
_Exit_Program][N
S S T   N
_Create_Label_SLYTHERIN][S S S T    S N
_Push_2][T  N
S T _Print_as_integer][N
N
N
_Exit_Program][N
S S S S N
_Create_Label_HUFFELPUFF][S S S T   T   N
_Push_3][T  N
S T _Print_as_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
Port of [*@GB*'s Ruby answer](https://codegolf.stackexchange.com/a/199683/52210).
Since Whitespace inputs one character at a time, the input should contain a trailing newline (`\n`) so it knows when to stop reading characters and the input is done.
[Try it online](https://tio.run/##hY9RCoAwDEO/m1PkNv7rCUQG@icoePyuXacMFcYGSx5J6a51O9Oxz0tSJQmQIqA9oEDMiBujdswHLMo4LOsNl4iQ39KrNjTuRgxgJdIFb89e4FP4GYEH@idRVm90LNGSmo@C6jhMyA) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer sum = 0
Start LOOP:
  Integer c = STDIN as character
  If(c == '\n'):
    Jump to Label DONE
  sum = sum + c
  Go to next iteration of LOOP
Label DONE:
  sum = sum modulo-91
  sum = sum modulo-11
  If(sum == 0): Jump to Label HUFFELPUFF
  If(sum-1 == 0): Jump to Label SLYTHERIN
  If(sum-2 == 0): Jump to Label SLYTHERIN
  If(sum-3 == 0): Jump to Label RAVENCLAW
  If(sum-4 == 0): Jump to Label GRYFFINDOR
  If(sum-5 == 0): Jump to Label RAVENCLAW
  If(sum-6 == 0): Jump to Label RAVENCLAW
  If(sum-7 == 0): Jump to Label HUFFELPUFF
  If(sum-8 == 0): Jump to Label GRYFFINDOR
  Label RAVENCLAW:
    Integer n = 1
    Print n as integer to STDOUT
    Exit program
  Label GRYFFINDOR:
    Print top (sum-4 or sum-8) as integer to STDOUT
    Exit program
  Label SLYTHERIN:
    Integer n = 2
    Print n as integer to STDOUT
    Exit program
  Label HUFFELPUFF:
    Integer n = 3
    Print n as integer to STDOUT
```
[Answer]
# [Zsh](https://www.zsh.org/), 66 bytes
```
case $1 in ?ra*|g*)<<<S;;[lp]*|cho)<<<R;;h?r*|r*)<<<G;;*)<<<H;esac
```
[Try it online!](https://tio.run/##bY8xb8IwEIV3/4qTm4okUgc6YlqGtiJDhxZGhCqTnGtLxo4uUJQCvz21Q7fkBlv@3nt3vt9GdyrN0q6UDUIyBeNgQTK/fOfZfD5fC7Gx9Ta/lNrH90oIvaD8Qr26FKK/C4GNLLuMhTppYxEIZQXWOBRQeVCewMk9whdofwxzwpDknH5myfkpmq7XaGOsJuMOCib3j9NmAjzpM02I2Ap24Xd9eDPdzjhToUGUZ/YKoe7A@hNSXIKxyt/mOux4IYlaDg/PwJfUKmVc5YkzXiDtTXCMSCvvRuj70ckbXskfdKWVp0BftB/CD3RofY1D5ZVk@R9Y2/agMSwcu5DcDenStxZHzFiRKW@8OCplsQ5nXEk6J/WI8EbO4JD/AQ "Zsh – Try It Online")
No hash functions available, so we make do with pattern matching in
a single case statement:
```
case $1 in
    ?ra*|g*)    <<< S ;;
    [lp]*|cho) <<< R ;;
    h?r*|r*)   <<< G ;;
    *)         <<< H     # last branch doesn't need ;;
esac
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 36 bytes
```
\B(u|h|p|ra|oy|nn|edr|rni)
$.&$*
3`1
```
[Try it online!](https://tio.run/##DcxBCsJADAXQ/T9HlepCEG/gKO1CRFy7aKzBGRiTEu1iIHcf@w7wjH9JqK7abqiPYzt79MmNXIuLOL/MTdIGzW7dbHEY9rX2ZFbQs32SCuOugssshBAVNxbOOjFORqMiGD3RacmMsFRpRE8iFHFeUsaVU4a9v38 "Retina 0.8.2 – Try It Online") Link includes test suite. Outputs the house index. `Neil` and `rgs` both map to index `0`. Explanation:
```
\B(u|h|p|ra|oy|nn|edr|rni)
$.&$*
```
Replace each of the scoring letters with `1`s. The `\B` means that the first letter never counts as a scoring letter, allowing it to be upper or lower case.
```
3`1
```
Count the number of scoring letters, up to 3.
[Answer]
# [PHP](https://php.net/), 43 bytes
```
<?='RSHGGGHSHRSGRRSGHHRS'[crc32($argn)%20];
```
[Try it online!](https://tio.run/##jVFNTwIxEL33VwwbTCUBYvDGZwzq9uCB7B6Bw9AtdOPaNt2CEuNfd22rEhMTwmE70@6b9@blGWmaZjyb0CxnaZqynGV5mvmP@YYuueW3g@s22p3qXA1u1qNmNiVkPDPSEMGlhmSl7qoKONaiHq5UMiJthAksKUNrj7QLlAn7UmolQp9pFcrTXmGoc6lDWQglKm0i4t4ij49zi5tQU32s4p@5KGzJIyMqhTJ0D1aVgq5HhGy1FcilXxWwhvah804AwobnjR2iq34SN/8gJ0/@FoftrobeFGj/LE2A0b9M38Jpfsmsh/3OgnhzFsHoUrkavCXYaCdbrRYMF5H3337PWBTo5CU6P9CTltI@NVM6rLpQ@FwcvKJy4DRsBCCw/XZbCePPk3wTM/3Uxvk866b3@AU "PHP – Try It Online")
I wanted to do something else than a port.. better but maybe I can do better, when I have time. And this time with bonus points! I'm Griffindor without my capital ;) (Hacks not to be Hufflepuff)
Takes input with Capital letter and returns house initial letter (works with any string input actually, but the result will change)
EDIT: changed a not meaningful G to a S for equal representation between G and S
EDIT 2: saved 10 bytes with a longer string, and ran for the double extra points!! Houses are equally reprensented for meaningless values.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 16 bytes
```
OḄ%19ị“®5ƭ{~’ḃ4¤
```
[Try it online!](https://tio.run/##y0rNyan8/9//4Y4WVUPLh7u7HzXMObTO9Nja6rpHDTMf7mg2ObTk/9E9h9uzHjWtAcop6NopPGqYG/n/v5JHYlFRpZKOkkdqUW5mfl4qkBmUnwckfUrzEoGUc0Y@kAxIzUvNyS8AyboUJSaDhJyLEpOAlHt@ZQ5I2Dk1pSgzGWRQYl5eYgaQ4VqUlwmSKUovVgIA "Jelly – Try It Online")
A monadic link taking a string or list of strings and returning a 1-indexed number corresponding to Gryffindor, Ravenclaw, Slytherin, Hufflepuff. 
"rgs" gets sorted into Ravenclaw.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 28 bytes
```
->n{296887>>n.sum%20%11*2&3}
```
[Try it online!](https://tio.run/##JU09C4JQFN39FfLAhjBJgz4GXSx0aAgdxeFa13yg98k1BbF@u@FzOudwvrgvxrn0511Ak3c5ns@nICCn6xvL21uuu/U2h98MfiZiYB6FbRoiRm6kItQiUSRsQ9x7Aq3DSml8IGGtWlzMK8NTLSRkKLQbqbFe@yG@WD7XXSCCasndmKRu8rtbIIlSfYID1mYiB2Qz/YjcAKeBdvrKb2uWmcx/xvwH "Ruby – Try It Online")
Returns `2310` instead of `GRSH`. RGS is on `1=S`, I am on `2=G`.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~23~~ 24 bytesSBCS
```
'GSGHSSRRH'⊃⍨9|15|19|⍋⊥⍒
```
[Try it online!](https://tio.run/##JY3BasJAEIbvPkVE6UohUFEPuRV6MJ4KWV9gs1mzKetuGPEQyE3wEFnRQh@h4K2XPoGPMi8SZ/Hy//98M8MvahMXjTCu7PH8s/rE4@WtZ0u@TDnPspRhd0B/S9rpop0mLfoTdr/ov/sNHaI/P3@6w/1vhscrTTz7IF2nK95v7rdoHs3Q/zMtABoWMa1gWzmrKIKzpGZvBZnUjrRWVhlXh20BQgYkQeRkpWtMwFIVUEkKCmwVgBbWCs0GcRwPQh@Dckc43@e5UUDpy@nQEw3fJ68v49GYPQA "APL (Dyalog Unicode) – Try It Online")
Some number digging magic using three functions unique to APL:
* Grade up `⍋X`: Indices to reorder the array X into ascending order
* Mixed base `X⊥Y`: Convert array Y from base X to integer
* Grade down `⍒X`: Indices to reorder the array X into descending order
~~Interestingly, modulo 15 doesn't guarantee successful indexing into a length-10 list, yet both `rgs` and `bubbler` fit into the list nicely.~~ I missed the input range, so I added `9|` in the modulo chain to fix it at the cost of 1 byte. `rgs` goes to Slytherin; I go to Hufflepuff.
[Answer]
# Clojure - 186 bytes
Since everyone else seems to have settled on somewhat similar algorithms I boldly went where no one wanted to go before (that I noticed)!
Takes the string, converts it to individual characters, sums up the character values. Has precomputed special cases for the desired assignments. For all other names takes the character sum, mod 4, to get a number in [0..3]. 0 = Gryffindor, 1 = Ravenclaw, 2 = Slytherin, 3 = Hufflepuff.
**Golfed version**
`(defn s[m](let[n(apply + (map int (into [] (clojure.string/upper-case m))))p {390 0,599 0,239 0,1973 0,304 1,218 1,600 1,361 2,280 2,384 2,426 3,430 3,371 3,236 1}](or (p n) (mod n 4))))`
**Ungolfed version**
Adds precomputed values for other versions of the character's names (e.g. accepts "Harry", "Harry Potter", and "Potter" for The Boy Who Lived, and so on), and also returns the full house name instead of a number:
```
(defn sorting-hat [name]
  (let [ n          (apply + (map int (into [] (clojure.string/upper-case name))))
         houses     [ "Gryffindor" "Ravenclaw" "Slytherin" "Hufflepuff" ]
         name-map   { 390 0, 900 0, 478 0, 599 0, 1149 0,  518 0, 239 0, 809 0, 1018 0, 538 0, 1973 0,
                      304 1, 943 1, 218 1, 603 1,  600 1, 1378 1,
                      361 2, 849 2, 456 2, 280 2,  415 2,  982 2, 384 2, 959 2, 
                      426 3, 991 3, 430 3, 906 3,  371 3, 1057 3, 236 1 }
         house      (name-map n)                                                              ; house derived from special cases
         house2     (mod n 4)]
    (houses (or house house2))))
```
Test harness:
```
(doseq [ person  ["Harry"  "Hermione" "Ron"
                  "Luna"   "Cho"      "Penelope"
                  "Draco"  "Crab"     "Goyle"
                  "Cedric" "Hannah"   "Ernie"
                  "RGS"                            ; poster's codegolf nickname
                  "Bob Jarvis - Reinstate Monica"  ; my codegolf nickname
                  "Ackerley" "Ealasaid" "Icarus" "Mabel" "Qing" "Ulbrecht" "Yardley"] ]  ; other names
  (println person " -> "(s person)))
```
Test results (using golfed version):
```
Harry  ->  0
Hermione  ->  0
Ron  ->  0
Luna  ->  1
Cho  ->  1
Penelope  ->  1
Draco  ->  2
Crab  ->  2
Goyle  ->  2
Cedric  ->  3
Hannah  ->  3
Ernie  ->  3
RGS  ->  1
Bob Jarvis - Reinstate Monica  ->  0
Ackerley  ->  0
Ealasaid  ->  0
Icarus  ->  3
Mabel  ->  1
Qing  ->  3
Ulbrecht  ->  1
Yardley  ->  2
```
Note that OP is assigned to Ravenclaw. I'm in Gryffindor.
[Try It Online! (golfed version)](https://tio.run/##jZJPbxMxEMXv@RRPvuCKBHbX2zRRJSQIVQOiUgnigFZ7cLzTZqnXNraDFCE@e5il5USEmMNvxtY8P/8z1n/dRzoeZUd3DqkZWmkpN07qEOwBzyEHHdC7DMnwaFpI8yh6kXLs3f3LfQgUZ0YnwnDGEfBDLQsU0/PlklmpkeXyQnFSRY1yWpUL5rwomGpeoppWi4KpFjWzruZQ01oVTHVRMis1R/mzlT5CBrgz3pTv4FCPdpOJ7Hyib2jA@0jeAY1Y6xgPAhBrikPvHQmIjXdigr9CfNg7LcZitfPiae6WHFkf6KTgbdRm7BSrqLePCnHtD/Z094q62Bv2X2vn9O6301V0/enuzfUngX/EJYJPmeKzBOM7uvf2Dq43D04PdGq9N36L9zp@7xNm2FDvUtaZcONZNJ76EsPh/1Z6bR4oWuJbFVfa6qT7jst3Rsd94uJGb8ly/shfgtNnu41kdpnLLzp2o65FO/r5vKOI0SWxjQz8h7J1f95OYPYKQqanMb/v8fgL)
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 78 bytes (& bonus imaginary Internet points!)
**sortinghat:**
```
o()(printf %d "'${s:$1}")
s=$1
h=HSSGGRSHRHSRGGHHR
echo ${h:(`o`-`o -1`)%13:1}
```
[Try it online!](https://tio.run/##BcE7DoAgDADQnVMQgxEGh8aNxJnOcAHwl7qIARdDPHt9b0mVmLM2@i7n9Ryy32Q3qFatgq8zos4KBM0YgnM@oMfgnUP0Yl8pS9XI6pjjGLMcIZoeJgsfM1Mq5eUf "Bash – Try It Online")
Input is passed as an argument in all lower-case, and output (G, R, S, or H) is on stdout.
---
**Test program:**
```
for x in %GRYFFINDOR-TEST harry hermione ron %RAVENCLAW-TEST luna cho penelope rgs %SLYTHERIN-TEST draco crab goyle %HUFFLEPUFF-TEST cedric ernie hannah %OTHER-SAMPLE-NAMES minerva newton myrtle salazar
  do
    if test "${x:0:1}" = '%'
      then
        echo "${x:1}"
      else
        printf "%12s " "$x"
        ./sortinghat "$x"
    fi
  done
```
**Output of test program:**
```
GRYFFINDOR-TEST
      harry  G
   hermione  G
        ron  G
RAVENCLAW-TEST
       luna  R
        cho  R
   penelope  R
        rgs  R
SLYTHERIN-TEST
      draco  S
       crab  S
      goyle  S
HUFFLEPUFF-TEST
     cedric  H
      ernie  H
     hannah  H
OTHER-SAMPLE-NAMES
    minerva  G
     newton  H
     myrtle  R
    salazar  S
```
The extra sample names are all in OP's list of names, and I think they're even sorted into the right houses (according to the HP books)! (I get sorted into Gryffindor if you put my name in all lower-case like the others.)
[Answer]
# Clojure - 124 bytes
## Solution
`(defn f[n](if-let[k({:harry 3 :hermione 3 :cho 0 :crab 1 :ernie 2}(keyword(clojure.string/lower-case n)))]k(mod(count n)4)))`
`Gryffindor 3
Rawenclaw 0
Slytherin 1
Hufflepuff 2`
## Explanation
The algorithm takes the modulo 4 length of the name and assigns a house based on that. Exceptions are made for the special cases for the few names that would not get to the predetermined house in this way (Harry, Hermione, Cho, Crab, Ernie).
## Test
```
(deftest a-test
  (testing "known-cases"
    (is (= 3 (f "Harry")))
    (is (= 3 (f "Hermione")))
    (is (= 3 (f "Ron")))
    (is (= 0 (f "Luna")))
    (is (= 0 (f "Cho")))
    (is (= 0 (f "Penelope")))
    (is (= 1 (f "Draco")))
    (is (= 1 (f "Crab")))
    (is (= 1 (f "Goyle")))
    (is (= 2 (f "Cedric")))
    (is (= 2 (f "Hannah")))
    (is (= 2 (f "Ernie")))
    )   
  (testing "other-names"
    (is (= 0 (f "Ackerley")))
    (is (= 1 (f "Acton")))
    (is (= 2 (f "Africa")))
    (is (= 3 (f "Addison")))
    (is (= 3 (f "Attilio")))
    (is (= 3 (f "RGS")))
    )   
  )
```
]