Hodorize a String

48

5

Hodor is a slow-minded but endearing character on the show Game of Thrones (he's in the books as well of course). The only word he ever says is 'hodor'.

Surprisingly, despite not having much of a vocabulary, Hodor always speaks in complete sentences with correct capitalization and punctuation, and does in fact convey meaning.

Hodor is capable of expressing all 128 ASCII characters, though it takes him an entire sentence to say each one. Each character has a single, exact representation as a sentence. An ASCII string is Hodorized by translating all the characters in the string to their Hodor sentence equivalents, then joining all the sentences. Since all characters map to exact sentences, all ASCII strings have a single, unique Hodorized representation.

Hodorizing Characters

Hodor divides his 128 expressible characters into 4 sets of 32 by using 4 different types of punctuation for the sentences that represent characters.

The sentence ends with...

  • . if the ASCII character code mod 4 is 0.
  • .[newline][newline] (for a new paragraph) if the code mod 4 is 1.
  • ? if the code mod 4 is 2.
  • ! if the code mod 4 is 3.

For example, the ASCII character code for b is 98, and 98 mod 4 is 2, so Hodor's sentence for b is sure to end in ?.

The content of the sentence is one of 32 distinct strings only containing the word 'hodor'. Each of the 32 characters of a particular punctuation type map to a different sentence content string. So with 32 sentence content strings and 4 punctuation types, all 128 ASCII character can be represented as distinct Hodor sentences.

To determine the sentence content for a character with ASCII code C, compute (floor(C / 4) + 16) mod 32; everything after the colon on that line in this list is the sentence content:

0:Hodor
1:HODOR
2:Hodor hodor
3:Hodor, hodor
4:Hodor hodor hodor
5:Hodor, hodor hodor
6:Hodor hodor hodor hodor
7:Hodor hodor, hodor hodor
8:Hodor hodor hodor hodor hodor
9:Hodor hodor, hodor hodor hodor
10:Hodor hodor hodor hodor hodor hodor
11:Hodor hodor hodor, hodor hodor hodor
12:Hodor hodor hodor hodor hodor hodor hodor
13:Hodor hodor hodor, hodor hodor hodor hodor
14:Hodor hodor hodor hodor hodor hodor hodor hodor
15:Hodor hodor hodor hodor, hodor hodor hodor hodor
16:Hodor hodor hodor hodor hodor hodor hodor hodor hodor
17:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor
18:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
19:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor
20:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
21:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor
22:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
23:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor
24:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
25:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor
26:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
27:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor
28:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
29:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor
30:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
31:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor

It can be seen that, apart from the HODOR special case, these strings are generated by joining more and more hodor's, and every other string has a comma halfway between all the words (with the "larger half" right of the comma for an odd number of words).

Joining sentence content with punctuation, we can form the Hodor sentences for all 128 characters (the number on the left is the character code):

0:Hodor hodor hodor hodor hodor hodor hodor hodor hodor.
1:Hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
2:Hodor hodor hodor hodor hodor hodor hodor hodor hodor?
3:Hodor hodor hodor hodor hodor hodor hodor hodor hodor!
4:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor.
5:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor.[newline][newline]
6:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor?
7:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor!
8:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
9:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
10:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
11:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
12:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor.
13:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor.[newline][newline]
14:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor?
15:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor!
16:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
17:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
18:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
19:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
20:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.
21:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.[newline][newline]
22:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor?
23:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor!
24:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
25:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
26:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
27:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
28:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.
29:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.[newline][newline]
30:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor?
31:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor!
32:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
33:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
34:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
35:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
36:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.
37:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
38:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor?
39:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor!
40:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
41:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
42:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
43:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
44:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.
45:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
46:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor?
47:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor!
48:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
49:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
50:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
51:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
52:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.
53:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
54:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor?
55:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!
56:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
57:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
58:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
59:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
60:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.
61:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
62:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor?
63:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!
64:Hodor.
65:Hodor.[newline][newline]
66:Hodor?
67:Hodor!
68:HODOR.
69:HODOR.[newline][newline]
70:HODOR?
71:HODOR!
72:Hodor hodor.
73:Hodor hodor.[newline][newline]
74:Hodor hodor?
75:Hodor hodor!
76:Hodor, hodor.
77:Hodor, hodor.[newline][newline]
78:Hodor, hodor?
79:Hodor, hodor!
80:Hodor hodor hodor.
81:Hodor hodor hodor.[newline][newline]
82:Hodor hodor hodor?
83:Hodor hodor hodor!
84:Hodor, hodor hodor.
85:Hodor, hodor hodor.[newline][newline]
86:Hodor, hodor hodor?
87:Hodor, hodor hodor!
88:Hodor hodor hodor hodor.
89:Hodor hodor hodor hodor.[newline][newline]
90:Hodor hodor hodor hodor?
91:Hodor hodor hodor hodor!
92:Hodor hodor, hodor hodor.
93:Hodor hodor, hodor hodor.[newline][newline]
94:Hodor hodor, hodor hodor?
95:Hodor hodor, hodor hodor!
96:Hodor hodor hodor hodor hodor.
97:Hodor hodor hodor hodor hodor.[newline][newline]
98:Hodor hodor hodor hodor hodor?
99:Hodor hodor hodor hodor hodor!
100:Hodor hodor, hodor hodor hodor.
101:Hodor hodor, hodor hodor hodor.[newline][newline]
102:Hodor hodor, hodor hodor hodor?
103:Hodor hodor, hodor hodor hodor!
104:Hodor hodor hodor hodor hodor hodor.
105:Hodor hodor hodor hodor hodor hodor.[newline][newline]
106:Hodor hodor hodor hodor hodor hodor?
107:Hodor hodor hodor hodor hodor hodor!
108:Hodor hodor hodor, hodor hodor hodor.
109:Hodor hodor hodor, hodor hodor hodor.[newline][newline]
110:Hodor hodor hodor, hodor hodor hodor?
111:Hodor hodor hodor, hodor hodor hodor!
112:Hodor hodor hodor hodor hodor hodor hodor.
113:Hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
114:Hodor hodor hodor hodor hodor hodor hodor?
115:Hodor hodor hodor hodor hodor hodor hodor!
116:Hodor hodor hodor, hodor hodor hodor hodor.
117:Hodor hodor hodor, hodor hodor hodor hodor.[newline][newline]
118:Hodor hodor hodor, hodor hodor hodor hodor?
119:Hodor hodor hodor, hodor hodor hodor hodor!
120:Hodor hodor hodor hodor hodor hodor hodor hodor.
121:Hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
122:Hodor hodor hodor hodor hodor hodor hodor hodor?
123:Hodor hodor hodor hodor hodor hodor hodor hodor!
124:Hodor hodor hodor hodor, hodor hodor hodor hodor.
125:Hodor hodor hodor hodor, hodor hodor hodor hodor.[newline][newline]
126:Hodor hodor hodor hodor, hodor hodor hodor hodor?
127:Hodor hodor hodor hodor, hodor hodor hodor hodor!

([newline]'s are to be replaced with actual newlines.)

Hodorizing Strings

Hodorizing a string really just involves concatenating all the character sentences of the string's characters together. There are only a couple caveats:

  • A space is inserted after every sentence except for the .[newline][newline] punctuated ones and the very last sentence.
  • If the last sentence is punctuated with .[newline][newline], the punctuation becomes ... so there is no trailing whitespace.

Examples

The string F0 is Hodorized as

HODOR? Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
  • F has ASCII code 70. 70 mod 4 is 2, so the first sentence ends in ?. (floor(70 / 4) + 16) mod 32 is 1 so the content is HODOR.
  • 0 has ASCII code 48. 48 mod 4 is 0, so the second sentence ends in .. (floor(48 / 4) + 16) mod 32 is 28 so the content is 15 hodor's strung together with no comma.
  • Notice that there is no trailing space.

The string CEE is Hodorized as

Hodor! HODOR.

HODOR...
  • Notice that there is no space before the last sentence.
  • Notice that the the last sentence punctuation was changed to ....

The string

Hodor's real name is Walder.
Did you know?

is Hodorized as

Hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor, hodor hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor, hodor hodor hodor? Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor.

Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor, hodor hodor! Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor. Hodor hodor, hodor hodor hodor. Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor? HODOR. Hodor hodor hodor hodor hodor hodor.

Hodor hodor, hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor? Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!

(assuming the newline is a single \n)

Challenge

Write a program or function that takes in an ASCII string and Hodorizes it, printing or returning the resulting string. Take input in any standard way (from text file, command line, stdin, function arg).

The solution with the fewest bytes wins. Tiebreaker is earlier post. (Handy byte counter.)

Calvin's Hobbies

Posted 2015-04-16T12:19:18.737

Reputation: 84 000

1This challenge makes me want to re-watch seasons 1-4 and discover what he's really saying. :D – mbomb007 – 2015-04-16T16:22:28.503

24

Great, we found the next version of Ook.

– ASCIIThenANSI – 2015-04-16T17:56:10.997

8Hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor, hodor hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor... – Adam Davis – 2015-04-16T20:40:21.863

1@AdamDavis Hodorception! – Martin Ender – 2015-04-16T21:11:51.730

1

I would answer this question with HODOR but I think I may crash SE.

– caird coinheringaahing – 2017-04-05T17:48:27.313

Answers

26

Hodor! Hodor hodor? Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor hodor. Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor!

That's just the language and size header!? Nevermind then, let's just encode the post in boring old ASCII. Sorry if you have trouble understanding the post, Hodor.


CJam, 85 bytes

Here's my attempt. Some parts of this code felt rather clunky when I wrote them, so there's likely potential to beat this!

qW%{'@^4md('.X1$N?_++a"?!."XLS?f++=\(_)2md","*1$)"hodor":Ha*H@+@(2/\tS*0:X'HtHeu?}%W%

Try it online.

Explanation

qW%             "Read and reverse the input.";
{               "Map each character c:";
  '@^4md          "Calculate (c^64)/4, which is the sentence content determiner,
                    and c%4, which is the sentence ending determiner.";
  (               "Calculate c%4-1 for later.";
  '.X1$N?_++      "Produce the sentence ending string for the case that c%4==1,
                   which is '.' followed by two copies of:
                    - '.' if this is the first processed (last actual) character
                    - or a newline otherwise.
  a"?!."XLS?f     "Produce a list of the sentence ending strings for the cases
                   that c%4 is 2, 3, or 0, which are:
                    - '?', '!', and '.' if this is the first processed character
                    - or these punctuation marks each followed by a space
                      otherwise.";
  ++=\            "Prepend the sentence ending string for the case that c%4==1
                   to the list for the other cases and select the element at the
                   index (c%4-1)%4 as the correct sentence ending string.";
  (               "Calculate (c^64)/4-1 for later.";
  _)2md           "Calculate the quotient and remainder of the sentence content
                   content determiner divided by 2.";
  ","*            "Produce a string of commas with a length of the remainder
                   calculated above (either 0 or 1).";
  1$)"hodor":Ha*  "Produce a list of copies of 'hodor' with a length of the
                   quotient calculated above plus one.";
  H@+@(2/\t       "Append the string of commas (either empty or one comma) to
                   the middle 'hodor'.";
  S*              "Join the sentence words into a string a space between each.";
  0:X             "Signal that later characters are not the first processed.";
  'Ht             "Capitalize the first letter of the sentence (always 'h').";
  Heu             "Produce the string 'HODOR'.";
  ?               "Select the correct sentence content, which is 'HODOR' if 
                   (c^64)/4-1 is zero or the full sentence produced before that
                   otherwise.";
}%
W%              "Reverse the reversed translation to obtain the forward one.";
                "Implicitly print the result.";

Runer112

Posted 2015-04-16T12:19:18.737

Reputation: 3 636

1Post the explanation in Hodor to make it more readable. – Magic Octopus Urn – 2017-05-25T19:55:58.257

101

Hodor, 602 582 bytes

HoDoRHoDoR HODOR! (Hodor ){r='';Hodor!? =Hodor .Hodor!? hodor? HODOR? hodor! hodor. h;HODOR{}(Hodor? =0;Hodor? <Hodor!? ;++Hodor? ){hodor =Hodor .hodor hHODOR rHodor... odhodor? hodor?!? hodor. (Hodor? );HODOR? =(0|hodor /4+16)%32;r+='H';HODOR =HHHOOODDDDOOORRR!!! hodor?!? rrHODOR HODOR!?! (0|HODOR? /2+2);HOdor!!!(HODOR? %2)HODOR [0|(HODOR? +1)/4]=',';r+=HODOR? ==1?'ODOR':HODOR .HODOR?! oHodor? HODOR? (' hodor').Hodor Hodor!? Hodor? hodor hodor? (2);r+=['. ',Hodor? ==Hodor!? -1?'....':'.\HODOR? \HODOR? ','? ','! '][hodor %4]}HODOR:: r.Hodor Hodor!? Hodor? hodor hodor? (0,-1)}

Here is an ungolfed version... you know... for readability:

HoDoRHoDoR HODOR! (Hodor ){
    r='';
    Hodor!? =Hodor .Hodor!? hodor? HODOR? hodor! hodor. h;
    HODOR{}(Hodor? =0;Hodor? <Hodor!? ;++Hodor? ){
        hodor =Hodor .hodor hHODOR rHodor... odhodor? hodor?!? hodor. (Hodor? );
        HODOR? =(0|hodor /4+16)%32;
        r+='H';
        HODOR =HHHOOODDDDOOORRR!!! hodor?!? rrHODOR HODOR!?! (0|HODOR? /2+2);
        HOdor!!!(HODOR? %2)HODOR [0|(HODOR? +1)/4]=',';
        r+=HODOR? ==1?'ODOR':HODOR .HODOR?! oHodor? HODOR? (' hodor').Hodor Hodor!? Hodor? hodor hodor? (2);
        r+=['. ',Hodor? ==Hodor!? -1?'....':'.\HODOR? \HODOR? ','? ','! '][hodor %4]
    }
    HODOR:: r.Hodor Hodor!? Hodor? hodor hodor? (0,-1)
}

Yep, there is a language called Hodor. (And it's rather new.) It's essentially just a string substitution for JavaScript. The corresponding JS looks like this:

function f(s){
  r='';
  l=s.length;
  for(i=0;i<l;++i){
    c=s.charCodeAt(i);
    n=(0|c/4+16)%32;
    r+='H';
    a=new Array(0|n/2+2);
    if(n%2)a[0|(n+1)/4]=',';
    r+=n==1?'ODOR':a.join(' hodor').slice(2);
    r+=['. ',i==l-1?'....':'.\n\n','? ','! '][c%4]
  }
  return r.slice(0,-1)
}

Hence, my submission is a function taking a string and returning the Hodorised equivalent.

Unfortunately, there doesn't seem to be any information about how Hodor actually works (apart from the source code of the interpreter), but it comes with a JS2HD translation script.

Note that Hodor's substitutions are also applied within string literals. So while you may just call the above function as

HODOR! ("CEE")

You can also use the following:

HODOR! ("Hodor... HooodorrHodor HooodorrHodor ")

where Hodor... HooodorrHodor HooodorrHodor will be substituted with CEE. Note that this means, that if your string itself contains certain forms of Hodor you'll have to encode it, or else it will be substituted. E.g. "Hodor. " is actually "m" in JavaScript. The catch is that the letters [dhor] (case insensitively) are not replaced at all, so you can't even encode this. One solution is to split up the literal, like "Hod"+"or. ", such that the substitution step doesn't find anything to decode.

Martin Ender

Posted 2015-04-16T12:19:18.737

Reputation: 184 808

36This makes me so happy. – Alex A. – 2015-04-16T14:28:08.630

1@AlexA. I think you meant to say "Hodor! Hodor hodor hodor! Hodor?" – MikeTheLiar – 2015-04-16T14:57:39.487

The last sentence punctuation is only ... instead of the newlines, not ..... – mbomb007 – 2015-04-16T16:19:43.273

1@mbomb007 The fourth . could be replaced by anything. It's a placeholder for the space that's usually there, which is removed with the final r.slice(0,-1). – Martin Ender – 2015-04-16T16:20:28.740

I see, never mind. – mbomb007 – 2015-04-16T16:21:30.730

Are you going to list the JS program as a submission, too? – mbomb007 – 2015-04-17T04:29:52.830

@mbomb007 No, I wasn't planning to. It wouldn't beat any other submission, it's probably not particularly well-golfed for JavaScript, and I should probably also convert it to ES6. – Martin Ender – 2015-04-17T09:36:30.707

1582 bytes but with a -65535 bonus for using the Hodor programming language gives this answer a score of -59713 and makes this answer the clear winner ;-) – Josh – 2015-04-20T02:51:42.937

This looks like Hodor was just belligerent and attempting to type out an email while uncontrollably hitting random symbols. – Magic Octopus Urn – 2017-05-25T19:57:01.683

5

Python 2, 219 198 bytes

Try it here

Uses the same method as Martin's JavaScript, and it's several bytes shorter in Python. I make use of Python 2.7's handy integer division. Thanks to Sp3000 for some golfing.

def f(s,r='',i=2):
    for j in s:c=ord(j);n=(c/4+16)%32;a=['']*(n/2+2);a[-~n/4]=','[:n%2];r+='H'+[' hodor'.join(a)[2:],'ODOR'][n==1]+['. ',['.\n\n',4*'.'][i>len(s)],'? ','! '][c%4];i+=1
    return r[:-1]

And for your own entertainment and my own enjoyment and curiosity...

Here it is as a lambda function!!!

Python 2, 349

Try it here, along with an older version of the program above.

f=lambda s:'H'.join(['']+[('ODOR'if(ord(s[i])/4+16)%32==1 else' hodor'.join((['']*(((ord(s[i])/4+16)%32)/2+2))[:((ord(s[i])/4+16)%32+1)/4]+([',']if ord(s[i])/4%2 else[''])+(['']*(((ord(s[i])/4+16)%32)/2+2))[((ord(s[i])/4+16)%32+1)/4+1*(ord(s[i])/4%2<1):])[2:])+['. ',4*'.'if i+2>len(s)else'.\n\n','? ','! '][ord(s[i])%4]for i in range(len(s))])[:-1]

Creating this involved deeper and deeper substitutions as well as some extra creativity.

  • Every j is replaced with s[i].
  • Every c is replaced with ord(s[i]).
  • Every n is replaced with (ord(s[i])/4+16)%32.

    • Except where I only need n%2, so I use (ord(s[i])/4%2 instead.
  • Finally, a is replaced with (['']*(((ord(s[i])/4+16)%32)/2+2))[:((ord(s[i])/4+16)%32+1)/4]+([',']if ord(s[i])/4%2 else[''])+(['']*(((ord(s[i])/4+16)%32)/2+2))[((ord(s[i])/4+16)%32+1)/4+1*(ord(s[i])/4%2<1):].

    • This is because we cannot assign a value, so we must split the list in half, conditionally append the comma, then append the last half again.

mbomb007

Posted 2015-04-16T12:19:18.737

Reputation: 21 944

1

I believe this gives 198?

– Sp3000 – 2015-04-16T22:51:17.790

Cool, I didn't know you could slice [:0] like that to get empty string. – mbomb007 – 2015-04-17T04:25:29.923

4

MUMPS, 284 236 bytes

New version: After looking at it for a while I came up with a shorter version (236 bytes):

H(H) S L=$L(H) F O=1:1:L D
 .S D=$A($E(H,O)),R=D#4,P=$S('R:".",R=2:"?",R=3:"!",O=L:"...",1:"."_$C(10,10)),E=D\4+16#32,(S,Q)="hodor" F F=1:1:E\2 S Q=S_$S(E#2&(F=(E\4+1)):", ",1:" ")_Q,$E(Q)="H" S:E=1 Q="HODOR"
 .W Q_P_$S(L=O:"",1:" ")
 Q

First version:

H(H) S L=$L(H) F O=1:1:L D
 .S S=$C(10),D=$A($E(H,O)),R=D#4,P=$S('R:".",R=2:"?",R=3:"!",O=L:"...",1:"."_S_S),E=D\4+16#32,(S,Q)="hodor ",G=6*(E+1\4) F F=1:1:E\2 S Q=S_Q
 .S Q=$E(Q,1,$L(Q)-1) S:E=1 Q="HODOR" S:E#2&(E>2) Q=$E(Q,1,G-1)_","_$E(Q,G,99) S $E(Q)="H" W Q_P_$S(L=O:"",1:" ")
 Q

Damn you, CJam! Maybe I could save some bytes using ObjectScript (there're list operators), but I doubt it.

Here's a somewhat verbose version:

VH(H)
 F I=1:1:$L(H) D              ; iterate over input string H
 .S O=$E(H,I)                 ; O is a single char
 .S D=$A(O)                   ; ascii code (dec)
 .S R=D#4                     ; #: mod, $S: $SELECT(condition:result,cond...)
 .S P=$S(R=0:".",R=2:"?",R=3:"!",I=$L(H):"...",1:"."_$C(10)_$C(10))
 .S E=D\4+16#32               ; \: integer division
 .S (S,Q)="hodor "            ; hodor
 .F J=1:1:E\2 S Q=S_Q         ; build hodor -"list"
 .I E=1 S Q="HODOR"           ; HODOR
 .I E'=1 S Q=$E(Q,1,$L(Q)-1)  ; remove trailing _
 .;                           ; insert ,
 .I E#2,E>2 S Q=$E(Q,1,6*(E+1\4)-1)_","_$E(Q,6*(E+1\4),99)
 .S $E(Q)="H"                 ; ^h->^H
 .W Q_P_$S($L(H)=I:"",1:" ")  ; Write and remove trailing _
 Q

trurl

Posted 2015-04-16T12:19:18.737

Reputation: 141

1

C# 378 Bytes

string x(string h){string[]f={". ",".\n\n","? ","! "};string[]a=new string[32];string s="";int i,j,c=0;for(i=0;i<32;i++){a[i]="hodor";if(i==1)a[i]=a[i].ToUpper();else{for(j=0;j<i/2;j++){if(i%2==1&&j==c/2)a[i]+=",";a[i]+=" hodor";}if(i%2==1)c++;a[i]=char.ToUpper(a[i][0])+a[i].Substring(1);}}foreach(char b in h){s+=a[(int)(Math.Floor((double)b/4)+16)%32]+f[(int)b%4];}return s;}

It's my first time golfing, so bare with me.

GonacFaria

Posted 2015-04-16T12:19:18.737

Reputation: 111

1Welcome to Programming Puzzles & Code Golf Stack Exchange! You can save some bytes by using a single-character function name instead of hodor. You can probably also remove some if not all of those newlines, and several spaces (e.g. after for oder the if). However, you should probably either count the using directive for System or fully qualify Console. – Martin Ender – 2015-04-20T14:37:08.730

Thank you for your help, I'll try to improve and save some bytes :D. – GonacFaria – 2015-04-20T14:38:48.523

When golfing C# code, it's not necessary to have a specific access modifier; so you can drop the public keyword to save some bytes. You can also remove the space between [] and the actual name of the variable that holds the array. Also, it's not necessary to convert a string to a char array when you iterate over all chars of a string in a foreach; you can simply do foreach (char c in h). – ProgramFOX – 2015-04-20T16:08:13.840

1Edited, thank you. Manage to bring it down to 378 bytes, this is fun. – GonacFaria – 2015-04-20T16:14:00.213

0

C++, 547 452 bytes

void H(string s){string e[4]={".",".\n\n","?","!"};string r;char c,m;int n=s.size();for(int i=0;i<n;i++){r.clear();c=s.at(i);m=c%4;r.append(A(c));r.append(e[m]);if(i==n-1){int k=r.size();r.pop_back();if(m==1){r.pop_back();r.append("..");}}cout<<r.c_str();}}string A(char x){string h("Hodor");int c=((int )floor(x/4)+16)%32;int n=c;bool o=(c%2==1);if(n==1)h="HODOR";else{while(n>1){h.append("hodor");if(o&&n==(int )(c/2)){h.append(",");}n--;}}return h;}

Ungolfed:

#include <iostream>
#include <math.h>
using namespace std;
void Hodorise(string s);
string FromAscii(char c);

void Hodorise(string s)
{
string end[4] = {". ",".\n\n","? ","! "};
string res;
char c, m;
int n = s.size();
for (int i = 0; i < n; i++)
{
res.clear();
c = s.at(i);
m = c % 4;
res.append(FromAscii(c));
res.append(end[m]);
if (i == n - 1)
{
int k = res.size();
res.pop_back();
if (m == 1)
{
res.pop_back();
res.append("..");
}

}
cout << res.c_str();
}
}

string FromAscii(char c)
{
string hodor("Hodor");
int code = ((int)floor(c / 4) + 16) % 32;
int n = code;
bool odd = (code % 2 == 1);
if (n == 1)hodor = "HODOR";
else
{
while (n > 1)
{
hodor.append(" hodor");
if (odd && n==(int)(code/2))
{
hodor.append(",");
}
n--;
}
}
return hodor;
}
#define N 3
int main()
{
string x[N] = { "F0", "CEE", "Hodor's real name is Walder.\nDid you know ?" };
for (size_t i = 0; i < N; i++)
{
cout << endl << x[i].c_str() << ":\n";
Hodorise(x[i]);
}

char c;
cin >> c;
return 0;
}

bacchusbeale

Posted 2015-04-16T12:19:18.737

Reputation: 1 235

1I count only 505 bytes. Did you count the line breaks as \r\n instead of \n? Also, why do you even need most of those line breaks at all? – Martin Ender – 2015-04-19T13:53:58.567

2The submission needs to include #include, using namespace std;, etc. – Potatoswatter – 2015-04-19T23:26:07.993

Most people submitting answers do not count #include or imports etc – bacchusbeale – 2015-04-20T19:44:50.083