title: Print the character names

text:
# Question
Title: Print the character names
Every Unicode character has a name, like "LATIN CAPITAL LETTER A". A Unicode character name may contain only uppercase letters, white spaces, and the minus sign.

Write a program that reads a text and outputs the names of each character on a new line. For example, if the input were "Hello, World!", the output would be

```
LATIN CAPITAL LETTER H
LATIN SMALL LETTER E
LATIN SMALL LETTER L
LATIN SMALL LETTER L
LATIN SMALL LETTER O
COMMA
SPACE
LATIN CAPITAL LETTER W
LATIN SMALL LETTER O
LATIN SMALL LETTER R
LATIN SMALL LETTER L
LATIN SMALL LETTER D
EXCLAMATION MARK

```
* Input should come from a file or from user input, not just a string in code.
* Output should be written to a file or stdout or printed to the screen.
* Internet and external libraries are not allowed, all necessary data should be in the code.
* Assume that the input only contains printable ASCII characters in the Basic Latin code range 32-126. You can ignore a trailing newline.
* All programming languages allowed. Shortest code in bytes wins.

The official Unicode character names can be found here. Other sources:

This is my first question so I'd appreciate any suggestion if this can be improved.

For the purpose of this challenge the list below shall be normative.

```
    32  0020        SPACE
!   33  0021        EXCLAMATION MARK
"   34  0022        QUOTATION MARK
#   35  0023        NUMBER SIGN
$   36  0024        DOLLAR SIGN
%   37  0025        PERCENT SIGN
&   38  0026        AMPERSAND
'   39  0027        APOSTROPHE
(   40  0028        LEFT PARENTHESIS
)   41  0029        RIGHT PARENTHESIS
*   42  002A        ASTERISK
+   43  002B        PLUS SIGN
,   44  002C        COMMA
-   45  002D        HYPHEN-MINUS
.   46  002E        FULL STOP
/   47  002F        SOLIDUS
0   48  0030        DIGIT ZERO
1   49  0031        DIGIT ONE
2   50  0032        DIGIT TWO
3   51  0033        DIGIT THREE
4   52  0034        DIGIT FOUR
5   53  0035        DIGIT FIVE
6   54  0036        DIGIT SIX
7   55  0037        DIGIT SEVEN
8   56  0038        DIGIT EIGHT
9   57  0039        DIGIT NINE
:   58  003A        COLON
;   59  003B        SEMICOLON
<   60  003C        LESS-THAN SIGN
=   61  003D        EQUALS SIGN
>   62  003E        GREATER-THAN SIGN
?   63  003F        QUESTION MARK
@   64  0040        COMMERCIAL AT
A   65  0041        LATIN CAPITAL LETTER A
B   66  0042        LATIN CAPITAL LETTER B
C   67  0043        LATIN CAPITAL LETTER C
D   68  0044        LATIN CAPITAL LETTER D
E   69  0045        LATIN CAPITAL LETTER E
F   70  0046        LATIN CAPITAL LETTER F
G   71  0047        LATIN CAPITAL LETTER G
H   72  0048        LATIN CAPITAL LETTER H
I   73  0049        LATIN CAPITAL LETTER I
J   74  004A        LATIN CAPITAL LETTER J
K   75  004B        LATIN CAPITAL LETTER K
L   76  004C        LATIN CAPITAL LETTER L
M   77  004D        LATIN CAPITAL LETTER M
N   78  004E        LATIN CAPITAL LETTER N
O   79  004F        LATIN CAPITAL LETTER O
P   80  0050        LATIN CAPITAL LETTER P
Q   81  0051        LATIN CAPITAL LETTER Q
R   82  0052        LATIN CAPITAL LETTER R
S   83  0053        LATIN CAPITAL LETTER S
T   84  0054        LATIN CAPITAL LETTER T
U   85  0055        LATIN CAPITAL LETTER U
V   86  0056        LATIN CAPITAL LETTER V
W   87  0057        LATIN CAPITAL LETTER W
X   88  0058        LATIN CAPITAL LETTER X
Y   89  0059        LATIN CAPITAL LETTER Y
Z   90  005A        LATIN CAPITAL LETTER Z
[   91  005B        LEFT SQUARE BRACKET
\   92  005C        REVERSE SOLIDUS
]   93  005D        RIGHT SQUARE BRACKET
^   94  005E        CIRCUMFLEX ACCENT
_   95  005F        LOW LINE
`   96  0060        GRAVE ACCENT
a   97  0061        LATIN SMALL LETTER A
b   98  0062        LATIN SMALL LETTER B
c   99  0063        LATIN SMALL LETTER C
d   100 0064        LATIN SMALL LETTER D
e   101 0065        LATIN SMALL LETTER E
f   102 0066        LATIN SMALL LETTER F
g   103 0067        LATIN SMALL LETTER G
h   104 0068        LATIN SMALL LETTER H
i   105 0069        LATIN SMALL LETTER I
j   106 006A        LATIN SMALL LETTER J
k   107 006B        LATIN SMALL LETTER K
l   108 006C        LATIN SMALL LETTER L
m   109 006D        LATIN SMALL LETTER M
n   110 006E        LATIN SMALL LETTER N
o   111 006F        LATIN SMALL LETTER O
p   112 0070        LATIN SMALL LETTER P
q   113 0071        LATIN SMALL LETTER Q
r   114 0072        LATIN SMALL LETTER R
s   115 0073        LATIN SMALL LETTER S
t   116 0074        LATIN SMALL LETTER T
u   117 0075        LATIN SMALL LETTER U
v   118 0076        LATIN SMALL LETTER V
w   119 0077        LATIN SMALL LETTER W
x   120 0078        LATIN SMALL LETTER X
y   121 0079        LATIN SMALL LETTER Y
z   122 007A        LATIN SMALL LETTER Z
{   123 007B        LEFT CURLY BRACKET
|   124 007C        VERTICAL LINE
}   125 007D        RIGHT CURLY BRACKET
~   126 007E        TILDE

```

# Answer
> 31 votes
# Java - 113 bytes (152 if read from command line)

Edit: removed useless curly brackets.

Edit2: removed unnecessary variable.

Edit3: Instead of Character.getName() I use c.getName().

Edit4: Passing string as command line argument.

With command line argument (113 bytes):

```
class Z{public static void main(String[]x){for(Character c:x[0].toCharArray())System.out.println(c.getName(c));}}

```

With read line (152 bytes):

```
class Z{public static void main(String[]x){for(Character c:new java.util.Scanner(System.in).nextLine().toCharArray())System.out.println(c.getName(c));}}

```

Java has everything needed. I'm sure this could be golfed down.

# Answer
> 18 votes
# Python 3, 56 bytes

Uses a built-in function `unicodedata.name()`, so this may be non-competent. The Java answer did it similarly, so I thought it was at least worth posting.

```
from unicodedata import*
for i in input():print(name(i))

```

# Answer
> 18 votes
# JavaScript (ES6) 594 ~~618 626~~

*Note* I could save ~30 bytes compressing the long string with atob/btoa, but the utf8 character above '~' are not well accepted by the Stack Exchange post editor. I prefer to keep a running snippet instead.

**Edit** 8 chars saved thx @Ypnypn

Obvious compression of repeated words. The newline inside backticks is significant and counted.

Test running the snippet in Firefox.

```
// TEST SUITE
// for testing purpose, redefine alert() to write inside the snippet body
alert=x=>O.innerHTML=x
// for testing purpose, redefine prompt() to have a default text containing all characters
_prompt=prompt
prompt=(i,s)=>{
  for(s='',i=32;i<127;i++)s+=String.fromCharCode(i);
  return _prompt("Insert your message or keep the default",s);
}

// That's the answer code:
z='SPACE/EXCLAMA0QUOTA0NUMBER1DOLLAR1PERCENT1AMPERSAND/APOSTROPHE3242ASTERISK/PLUS1COMMA/HYPHEN-MINUS/FULL STOP/78ZERO8ONE8TWO8THREE8FOUR8FIVE8SIX8SEVEN8EIGHT8NINE86SEMI6LESS-THAN1EQUALS1GREATER-THAN1QUES0COMMERCIAL AT3SQUARE5REVERSE 7/4SQUARE5CIRCUMFLEX9/LOW LINE/GRAVE93CURLY5VERTICAL LINE/4CURLY5TILDE'.replace(/\d/g,c=>'TION MARK/, SIGN/,PARENTHESIS/,/LEFT ,RIGHT , BRACKET/,COLON/,SOLIDUS,/DIGIT , ACCENT'.split`,`[c]).split`/`,alert([...prompt()].map(c=>(q=c.charCodeAt()-32)<33?z[q]:q<59?'LATIN CAPITAL LETTER '+c:q<65?z[q-26]:q<91?'LATIN SMALL LETTER '+c.toUpperCase():z[q-52]).join`
`)
```

```
<pre id=O></pre>
```

# Answer
> 10 votes
# R, ~~54 bytes~~ 62

```
library(Unicode)
cat(u_char_name(utf8ToInt(scan(,""))),sep="\n")

```

Edit: per @flodels comment, I need to read it from connection first, so had to add `scan`. This is also probably non-competent solution according to *all* the rules.

**Usage**

```
> cat(u_char_name(utf8ToInt(scan(,""))),sep="\n")
1: 'Hello, World!'
2:
Read 1 item
LATIN CAPITAL LETTER H
LATIN SMALL LETTER E
LATIN SMALL LETTER L
LATIN SMALL LETTER L
LATIN SMALL LETTER O
COMMA
SPACE
LATIN CAPITAL LETTER W
LATIN SMALL LETTER O
LATIN SMALL LETTER R
LATIN SMALL LETTER L
LATIN SMALL LETTER D
EXCLAMATION MARK

```

You can also wrap it up into a function for more convenient usage

```
UNI <- function(x)cat(paste0(u_char_name(utf8ToInt(x)),"\n"))

```

Then, the usage is just

```
UNI("Hello, World!")

```

# Answer
> 7 votes
# Perl 5 \+ `-M5.10.0 -MCompress::Zlib -00F`, 459 bytes

```
@d=split/,/,inflateInit->inflate(<DATA>);say$d[-32+ord]for@F
__END__
x.m.or.0.......!.#....I&I.......v......0O.)q.g.*...PH.q....u..k...85.:sgM\.8P..Fu......r..=tR...e......9k.{.2.xUj.P\_}..Qr...!..[..$O.2.%{.bmgl.....|U.tnC...K-?..;.3..1.\s......K>.....T..y.$v.E.....6.....JaM.$.G!.5$...A..5.....y...g....s.....Y0...s..1o...av.............;..)..R..G...8..t...K)k.e.~.J..Gi. .r\.v>.........!L.'..pF. \.f......aAX.6....P..BG8......._..
....W...s"9.t....
.2......

```

Try it online!

## Explanation

Pretty straight-forward, `@d` is constructed from Zlib compressed data (stored after `__END__`), which is just the compressed list of raw comma separated character names that is inflated, split on `,` and can be indexed via `ord - 32`. `-00` sets the input record separator to `\x00` (`NUL`) which slurps the `__DATA__` in one call to `<DATA>` instead of having it split on newline. `@F` is initialised with the input data as an array (via `-F`), which is iterated over and the corresponding index from `@d` is output.

---

# Perl 5 \+ `-M5.10.0 -F`, 672 bytes

```
$b=BRACKET;say+(SPACE,<"{EXCLAMATION,QUOTATION} MARK">,<"{NUMBER,DOLLAR,PERCENT} SIGN">,AMPERSAND,APOSTROPHE,<"{LEFT,RIGHT} PARENTHESIS">,ASTERISK,'PLUS SIGN',COMMA,'HYPHEN-MINUS','FULL STOP',$s=SOLIDUS,<"DIGIT {ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE}">,<{,SEMI}COLON>,<"{LESS-THAN,EQUALS,GREATER-THAN} SIGN">,'QUESTION MARK','COMMERCIAL AT',<"LATIN CAPITAL LETTER {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}">,"LEFT SQUARE $b","REVERSE $s","RIGHT SQUARE $b",'CIRCUMFLEX ACCENT','LOW LINE','GRAVE ACCENT',<"LATIN SMALL LETTER {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}">,"LEFT CURLY $b",'VERTICAL LINE',"RIGHT CURLY $b",TILDE)[-32+ord]for@F

```

Try it online!

## Explanation

A (marginally) less boring version of the script without tool-based compression, mostly taking advantage of `glob`s.

# Answer
> 7 votes
# C, 644 ~~656~~

Full program, reading from standard input

Test on Ideone

This is a porting of my JavaScript answer to C. The C language is good at manipulating single characters as numbers (no need of `.toUpperCase` and the like), but it's weaker in string manipulation.

```
char*s,*p,*q,b[999],*d=b+99,c,*l[129];
main(k){for(k=32,p="/SPACE/EXCLAMAaQUOTAaNUMBERbDOLLARbPERCENTbAMPERSAND/APOSTROPHEdcecASTERISK/PLUSbCOMMA/HYPHEN-MINUS/FULL STOP/hiZEROiONEiTWOiTHREEiFOURiFIVEiSIXiSEVENiEIGHTiNINE/gSEMIgLESSnbEQUALSbGREATERnbQUESaCOMMERCIAL ATdkfREVERSE h/ekfCIRCUMFLEXj/LOWmGRAVEjdlfVERTICALmelfTILDE/";
c=*p;p++)c>96?q?(p=q,q=0):(q=p,p=strchr("aTION MARK/b SIGN/cPARENTHESIS/d/LEFT eRIGHT f BRACKET/gCOLON/hSOLIDUSi/DIGIT j ACCENTkSQUARElCURLYm LINE/n-THANz",c)):c-47?*d++=c:(*d++=0,l[k++]=d);
for(;~(k=getchar());puts(k<65?l[k]:(k&31)<27?b:l[k<97?k-26:k-52]))sprintf(b,"LATIN %s LETTER %c",k<91?"CAPITAL":"SMALL",k&95);}

```

Less golfed

```
char *all = "/SPACE/EXCLAMAaQUOTAaNUMBERbDOLLARbPERCENTbAMPERSAND/APOSTROPHEdcecASTERISK/PLUSbCOMMA/HYPHEN-MINUS/FULL STOP/hiZEROiONEiTWOiTHREEiFOURiFIVEiSIXiSEVENiEIGHTiNINE/gSEMIgLESSnbEQUALSbGREATERnbQUESaCOMMERCIAL ATdkfREVERSE h/ekfCIRCUMFLEXj/LOWmGRAVEjdlfVERTICALmelfTILDE/";
char *subs = "aTION MARK/b SIGN/cPARENTHESIS/d/LEFT eRIGHT f BRACKET/gCOLON/hSOLIDUSi/DIGIT j ACCENTkSQUARElCURLYm LINE/n-THANz";

main(int k)
{
    char c, *s, *p, *q=0,
    b[999], // work buffer
    *d = b+99, // first part of buffer is used later
    *l[129]; // characters descriptions (used 32 to 126)

    // Uncompress the descriptions of all char except letters
    for(k = 32, p = all; c = *p; ++p)
    {
       c >= 'a' // substitution word are marked as lowercase letters
        ? q
           ? (p = q, q = 0)
           : (q = p, p = strchr(subs, c))
        : c != '/'
           ? *d++ = c
           : (*d++ = 0, l[k++] = d); // end char description
    }
    // Scan the input string and print each char description
    for(; (k=getchar()) != -1; )
    {
       sprintf(b,"LATIN %s LETTER %c", k<91 ? "CAPITAL":"SMALL", k & 95);
       puts( k<65 ? l[k] : k<91 ? b : k<97 ? l[k-26] : k<123 ? b : l[k-52]);
    }
}

```

# Answer
> 7 votes
# Perl 6, 21 bytes

I did not see a rule specifically against using a built-in method for getting the unicode names.
(Also the Java answer which is the currently highest voted one does the same)

```
.say for get.uninames

```

# Answer
> 6 votes
# awk - 794 739

```
     1  LATIN CAPITAL LETTER B
     2  LATIN CAPITAL LETTER E
     3  LATIN CAPITAL LETTER G
     4  LATIN CAPITAL LETTER I
     5  LATIN CAPITAL LETTER N
     6  LEFT CURLY BRACKET
     7  LATIN SMALL LETTER S
     8  LATIN SMALL LETTER P
     9  LATIN SMALL LETTER L
    10  LATIN SMALL LETTER I
    11  LATIN SMALL LETTER T
    12  LEFT PARENTHESIS
    13  QUOTATION MARK
    14  LATIN SMALL LETTER I
    15  COMMA
    16  LATIN CAPITAL LETTER L
    17  LATIN SMALL LETTER V
    18  COMMA
    19  LATIN CAPITAL LETTER S
    20  LATIN SMALL LETTER V
    21  COMMA
    22  LATIN SMALL LETTER A
    23  LATIN SMALL LETTER X
    24  COMMA
    25  CIRCUMFLEX ACCENT
    26  LATIN SMALL LETTER X
    27  COMMA
    28  LEFT SQUARE BRACKET
    29  LATIN SMALL LETTER X
    30  COMMA
    31  LATIN CAPITAL LETTER Q
    32  COMMA
    33  LATIN CAPITAL LETTER O
    34  COMMA
    35  LATIN SMALL LETTER T
    36  LATIN CAPITAL LETTER K
    37  COMMA
    38  LATIN SMALL LETTER C
    39  LATIN CAPITAL LETTER K
    40  COMMA
    41  LATIN CAPITAL LETTER V
    42  COMMA
    43  LATIN SMALL LETTER Q
    44  LATIN SMALL LETTER X
    45  COMMA
    46  LATIN SMALL LETTER G
    47  COMMA
    48  LATIN CAPITAL LETTER I
    49  COMMA
    50  LATIN SMALL LETTER W
    51  LATIN SMALL LETTER U
    52  COMMA
    53  LATIN CAPITAL LETTER X
    54  COMMA
    55  LATIN SMALL LETTER B
    56  LATIN SMALL LETTER Y
    57  COMMA
    58  LATIN SMALL LETTER B
    59  LEFT CURLY BRACKET
    60  COMMA
    61  LATIN SMALL LETTER B
    62  LATIN SMALL LETTER Z
    63  COMMA
    64  LATIN SMALL LETTER B
    65  LATIN SMALL LETTER D
    66  COMMA
    67  LATIN SMALL LETTER B
    68  LATIN SMALL LETTER P
    69  COMMA
    70  LATIN SMALL LETTER B
    71  LATIN SMALL LETTER R
    72  COMMA
    73  LATIN SMALL LETTER B
    74  RIGHT CURLY BRACKET
    75  COMMA
    76  LATIN SMALL LETTER B
    77  LATIN SMALL LETTER K
    78  COMMA
    79  LATIN SMALL LETTER B
    80  LATIN SMALL LETTER L
    81  COMMA
    82  LATIN SMALL LETTER B
    83  LATIN SMALL LETTER O
    84  COMMA
    85  LATIN SMALL LETTER E
    86  COMMA
    87  LATIN CAPITAL LETTER P
    88  COMMA
    89  LATIN CAPITAL LETTER R
    90  LATIN SMALL LETTER X
    91  COMMA
    92  LOW LINE
    93  LATIN SMALL LETTER X
    94  COMMA
    95  LATIN CAPITAL LETTER J
    96  LATIN SMALL LETTER X
    97  COMMA
    98  LATIN CAPITAL LETTER U
    99  LATIN SMALL LETTER V
   100  COMMA
   101  LATIN CAPITAL LETTER M
   102  TILDE
   103  COMMA
   104  SPACE
   105  LATIN SMALL LETTER T
   106  GRAVE ACCENT
   107  LATIN CAPITAL LETTER Y
   108  COMMA
   109  LATIN CAPITAL LETTER Z
   110  LATIN CAPITAL LETTER X
   111  COMMA
   112  LATIN SMALL LETTER C
   113  GRAVE ACCENT
   114  LATIN CAPITAL LETTER Y
   115  COMMA
   116  LATIN CAPITAL LETTER N
   117  REVERSE SOLIDUS
   118  REVERSE SOLIDUS
   119  COMMA
   120  VERTICAL LINE
   121  LATIN SMALL LETTER S
   122  COMMA
   123  LATIN SMALL LETTER M
   124  REVERSE SOLIDUS
   125  REVERSE SOLIDUS
   126  COMMA
   127  SPACE
   128  LATIN SMALL LETTER T
   129  LATIN SMALL LETTER H
   130  LATIN CAPITAL LETTER Y
   131  COMMA
   132  LATIN CAPITAL LETTER T
   133  LATIN SMALL LETTER S
   134  COMMA
   135  LATIN SMALL LETTER C
   136  LATIN SMALL LETTER H
   137  LATIN CAPITAL LETTER Y
   138  COMMA
   139  LATIN SMALL LETTER F
   140  SPACE
   141  LATIN CAPITAL LETTER H
   142  LATIN CAPITAL LETTER Y
   143  LATIN CAPITAL LETTER P
   144  LATIN CAPITAL LETTER H
   145  LATIN CAPITAL LETTER E
   146  LATIN CAPITAL LETTER N
   147  HYPHEN-MINUS
   148  LATIN CAPITAL LETTER M
   149  LATIN CAPITAL LETTER I
   150  LATIN CAPITAL LETTER N
   151  LATIN CAPITAL LETTER U
   152  LATIN CAPITAL LETTER S
   153  SPACE
   154  LATIN CAPITAL LETTER G
   155  LATIN CAPITAL LETTER R
   156  LATIN CAPITAL LETTER E
   157  LATIN CAPITAL LETTER A
   158  LATIN CAPITAL LETTER T
   159  LATIN CAPITAL LETTER E
   160  LATIN CAPITAL LETTER R
   161  HYPHEN-MINUS
   162  LATIN CAPITAL LETTER T
   163  LATIN CAPITAL LETTER H
   164  LATIN CAPITAL LETTER A
   165  LATIN CAPITAL LETTER N
   166  SPACE
   167  LATIN CAPITAL LETTER P
   168  LATIN CAPITAL LETTER A
   169  LATIN CAPITAL LETTER R
   170  LATIN CAPITAL LETTER E
   171  LATIN CAPITAL LETTER N
   172  LATIN CAPITAL LETTER T
   173  LATIN CAPITAL LETTER H
   174  LATIN CAPITAL LETTER E
   175  LATIN CAPITAL LETTER S
   176  LATIN CAPITAL LETTER I
   177  LATIN CAPITAL LETTER S
   178  SPACE
   179  LATIN CAPITAL LETTER E
   180  LATIN CAPITAL LETTER X
   181  LATIN CAPITAL LETTER C
   182  LATIN CAPITAL LETTER L
   183  LATIN CAPITAL LETTER A
   184  LATIN CAPITAL LETTER M
   185  LATIN CAPITAL LETTER A
   186  LATIN CAPITAL LETTER T
   187  LATIN CAPITAL LETTER I
   188  LATIN CAPITAL LETTER O
   189  LATIN CAPITAL LETTER N
   190  SPACE
   191  LATIN CAPITAL LETTER C
   192  LATIN CAPITAL LETTER O
   193  LATIN CAPITAL LETTER M
   194  LATIN CAPITAL LETTER M
   195  LATIN CAPITAL LETTER E
   196  LATIN CAPITAL LETTER R
   197  LATIN CAPITAL LETTER C
   198  LATIN CAPITAL LETTER I
   199  LATIN CAPITAL LETTER A
   200  LATIN CAPITAL LETTER L
   201  SPACE
   202  LATIN CAPITAL LETTER C
   203  LATIN CAPITAL LETTER I
   204  LATIN CAPITAL LETTER R
   205  LATIN CAPITAL LETTER C
   206  LATIN CAPITAL LETTER U
   207  LATIN CAPITAL LETTER M
   208  LATIN CAPITAL LETTER F
   209  LATIN CAPITAL LETTER L
   210  LATIN CAPITAL LETTER E
   211  LATIN CAPITAL LETTER X
   212  SPACE
   213  LATIN CAPITAL LETTER A
   214  LATIN CAPITAL LETTER P
   215  LATIN CAPITAL LETTER O
   216  LATIN CAPITAL LETTER S
   217  LATIN CAPITAL LETTER T
   218  LATIN CAPITAL LETTER R
   219  LATIN CAPITAL LETTER O
   220  LATIN CAPITAL LETTER P
   221  LATIN CAPITAL LETTER H
   222  LATIN CAPITAL LETTER E
   223  SPACE
   224  LATIN CAPITAL LETTER S
   225  LATIN CAPITAL LETTER E
   226  LATIN CAPITAL LETTER M
   227  LATIN CAPITAL LETTER I
   228  LATIN CAPITAL LETTER C
   229  LATIN CAPITAL LETTER O
   230  LATIN CAPITAL LETTER L
   231  LATIN CAPITAL LETTER O
   232  LATIN CAPITAL LETTER N
   233  SPACE
   234  LATIN CAPITAL LETTER A
   235  LATIN CAPITAL LETTER M
   236  LATIN CAPITAL LETTER P
   237  LATIN CAPITAL LETTER E
   238  LATIN CAPITAL LETTER R
   239  LATIN CAPITAL LETTER S
   240  LATIN CAPITAL LETTER A
   241  LATIN CAPITAL LETTER N
   242  LATIN CAPITAL LETTER D
   243  SPACE
   244  LATIN CAPITAL LETTER L
   245  LATIN CAPITAL LETTER E
   246  LATIN CAPITAL LETTER S
   247  LATIN CAPITAL LETTER S
   248  HYPHEN-MINUS
   249  LATIN CAPITAL LETTER T
   250  LATIN CAPITAL LETTER H
   251  LATIN CAPITAL LETTER A
   252  LATIN CAPITAL LETTER N
   253  SPACE
   254  LATIN CAPITAL LETTER Q
   255  LATIN CAPITAL LETTER U
   256  LATIN CAPITAL LETTER O
   257  LATIN CAPITAL LETTER T
   258  LATIN CAPITAL LETTER A
   259  LATIN CAPITAL LETTER T
   260  LATIN CAPITAL LETTER I
   261  LATIN CAPITAL LETTER O
   262  LATIN CAPITAL LETTER N
   263  SPACE
   264  LATIN CAPITAL LETTER V
   265  LATIN CAPITAL LETTER E
   266  LATIN CAPITAL LETTER R
   267  LATIN CAPITAL LETTER T
   268  LATIN CAPITAL LETTER I
   269  LATIN CAPITAL LETTER C
   270  LATIN CAPITAL LETTER A
   271  LATIN CAPITAL LETTER L
   272  SPACE
   273  LATIN CAPITAL LETTER Q
   274  LATIN CAPITAL LETTER U
   275  LATIN CAPITAL LETTER E
   276  LATIN CAPITAL LETTER S
   277  LATIN CAPITAL LETTER T
   278  LATIN CAPITAL LETTER I
   279  LATIN CAPITAL LETTER O
   280  LATIN CAPITAL LETTER N
   281  SPACE
   282  LATIN CAPITAL LETTER A
   283  LATIN CAPITAL LETTER S
   284  LATIN CAPITAL LETTER T
   285  LATIN CAPITAL LETTER E
   286  LATIN CAPITAL LETTER R
   287  LATIN CAPITAL LETTER I
   288  LATIN CAPITAL LETTER S
   289  LATIN CAPITAL LETTER K
   290  SPACE
   291  LATIN CAPITAL LETTER C
   292  LATIN CAPITAL LETTER A
   293  LATIN CAPITAL LETTER P
   294  LATIN CAPITAL LETTER I
   295  LATIN CAPITAL LETTER T
   296  LATIN CAPITAL LETTER A
   297  LATIN CAPITAL LETTER L
   298  SPACE
   299  LATIN CAPITAL LETTER S
   300  LATIN CAPITAL LETTER O
   301  LATIN CAPITAL LETTER L
   302  LATIN CAPITAL LETTER I
   303  LATIN CAPITAL LETTER D
   304  LATIN CAPITAL LETTER U
   305  LATIN CAPITAL LETTER S
   306  SPACE
   307  LATIN CAPITAL LETTER B
   308  LATIN CAPITAL LETTER R
   309  LATIN CAPITAL LETTER A
   310  LATIN CAPITAL LETTER C
   311  LATIN CAPITAL LETTER K
   312  LATIN CAPITAL LETTER E
   313  LATIN CAPITAL LETTER T
   314  SPACE
   315  LATIN CAPITAL LETTER R
   316  LATIN CAPITAL LETTER E
   317  LATIN CAPITAL LETTER V
   318  LATIN CAPITAL LETTER E
   319  LATIN CAPITAL LETTER R
   320  LATIN CAPITAL LETTER S
   321  LATIN CAPITAL LETTER E
   322  SPACE
   323  LATIN CAPITAL LETTER P
   324  LATIN CAPITAL LETTER E
   325  LATIN CAPITAL LETTER R
   326  LATIN CAPITAL LETTER C
   327  LATIN CAPITAL LETTER E
   328  LATIN CAPITAL LETTER N
   329  LATIN CAPITAL LETTER T
   330  SPACE
   331  LATIN CAPITAL LETTER A
   332  LATIN CAPITAL LETTER C
   333  LATIN CAPITAL LETTER C
   334  LATIN CAPITAL LETTER E
   335  LATIN CAPITAL LETTER N
   336  LATIN CAPITAL LETTER T
   337  SPACE
   338  LATIN CAPITAL LETTER L
   339  LATIN CAPITAL LETTER E
   340  LATIN CAPITAL LETTER T
   341  LATIN CAPITAL LETTER T
   342  LATIN CAPITAL LETTER E
   343  LATIN CAPITAL LETTER R
   344  SPACE
   345  LATIN CAPITAL LETTER D
   346  LATIN CAPITAL LETTER O
   347  LATIN CAPITAL LETTER L
   348  LATIN CAPITAL LETTER L
   349  LATIN CAPITAL LETTER A
   350  LATIN CAPITAL LETTER R
   351  SPACE
   352  LATIN CAPITAL LETTER E
   353  LATIN CAPITAL LETTER Q
   354  LATIN CAPITAL LETTER U
   355  LATIN CAPITAL LETTER A
   356  LATIN CAPITAL LETTER L
   357  LATIN CAPITAL LETTER S
   358  SPACE
   359  LATIN CAPITAL LETTER S
   360  LATIN CAPITAL LETTER Q
   361  LATIN CAPITAL LETTER U
   362  LATIN CAPITAL LETTER A
   363  LATIN CAPITAL LETTER R
   364  LATIN CAPITAL LETTER E
   365  SPACE
   366  LATIN CAPITAL LETTER N
   367  LATIN CAPITAL LETTER U
   368  LATIN CAPITAL LETTER M
   369  LATIN CAPITAL LETTER B
   370  LATIN CAPITAL LETTER E
   371  LATIN CAPITAL LETTER R
   372  SPACE
   373  LATIN CAPITAL LETTER D
   374  LATIN CAPITAL LETTER I
   375  LATIN CAPITAL LETTER G
   376  LATIN CAPITAL LETTER I
   377  LATIN CAPITAL LETTER T
   378  SPACE
   379  LATIN CAPITAL LETTER R
   380  LATIN CAPITAL LETTER I
   381  LATIN CAPITAL LETTER G
   382  LATIN CAPITAL LETTER H
   383  LATIN CAPITAL LETTER T
   384  SPACE
   385  LATIN CAPITAL LETTER T
   386  LATIN CAPITAL LETTER H
   387  LATIN CAPITAL LETTER R
   388  LATIN CAPITAL LETTER E
   389  LATIN CAPITAL LETTER E
   390  SPACE
   391  LATIN CAPITAL LETTER C
   392  LATIN CAPITAL LETTER O
   393  LATIN CAPITAL LETTER L
   394  LATIN CAPITAL LETTER O
   395  LATIN CAPITAL LETTER N
   396  SPACE
   397  LATIN CAPITAL LETTER T
   398  LATIN CAPITAL LETTER I
   399  LATIN CAPITAL LETTER L
   400  LATIN CAPITAL LETTER D
   401  LATIN CAPITAL LETTER E
   402  SPACE
   403  LATIN CAPITAL LETTER C
   404  LATIN CAPITAL LETTER O
   405  LATIN CAPITAL LETTER M
   406  LATIN CAPITAL LETTER M
   407  LATIN CAPITAL LETTER A
   408  SPACE
   409  LATIN CAPITAL LETTER C
   410  LATIN CAPITAL LETTER U
   411  LATIN CAPITAL LETTER R
   412  LATIN CAPITAL LETTER L
   413  LATIN CAPITAL LETTER Y
   414  SPACE
   415  LATIN CAPITAL LETTER S
   416  LATIN CAPITAL LETTER P
   417  LATIN CAPITAL LETTER A
   418  LATIN CAPITAL LETTER C
   419  LATIN CAPITAL LETTER E
   420  SPACE
   421  LATIN CAPITAL LETTER S
   422  LATIN CAPITAL LETTER M
   423  LATIN CAPITAL LETTER A
   424  LATIN CAPITAL LETTER L
   425  LATIN CAPITAL LETTER L
   426  SPACE
   427  LATIN CAPITAL LETTER S
   428  LATIN CAPITAL LETTER E
   429  LATIN CAPITAL LETTER V
   430  LATIN CAPITAL LETTER E
   431  LATIN CAPITAL LETTER N
   432  SPACE
   433  LATIN CAPITAL LETTER E
   434  LATIN CAPITAL LETTER I
   435  LATIN CAPITAL LETTER G
   436  LATIN CAPITAL LETTER H
   437  LATIN CAPITAL LETTER T
   438  SPACE
   439  LATIN CAPITAL LETTER G
   440  LATIN CAPITAL LETTER R
   441  LATIN CAPITAL LETTER A
   442  LATIN CAPITAL LETTER V
   443  LATIN CAPITAL LETTER E
   444  SPACE
   445  LATIN CAPITAL LETTER L
   446  LATIN CAPITAL LETTER A
   447  LATIN CAPITAL LETTER T
   448  LATIN CAPITAL LETTER I
   449  LATIN CAPITAL LETTER N
   450  SPACE
   451  LATIN CAPITAL LETTER N
   452  LATIN CAPITAL LETTER I
   453  LATIN CAPITAL LETTER N
   454  LATIN CAPITAL LETTER E
   455  SPACE
   456  LATIN CAPITAL LETTER F
   457  LATIN CAPITAL LETTER O
   458  LATIN CAPITAL LETTER U
   459  LATIN CAPITAL LETTER R
   460  SPACE
   461  LATIN CAPITAL LETTER P
   462  LATIN CAPITAL LETTER L
   463  LATIN CAPITAL LETTER U
   464  LATIN CAPITAL LETTER S
   465  SPACE
   466  LATIN CAPITAL LETTER F
   467  LATIN CAPITAL LETTER I
   468  LATIN CAPITAL LETTER V
   469  LATIN CAPITAL LETTER E
   470  SPACE
   471  LATIN CAPITAL LETTER L
   472  LATIN CAPITAL LETTER I
   473  LATIN CAPITAL LETTER N
   474  LATIN CAPITAL LETTER E
   475  SPACE
   476  LATIN CAPITAL LETTER L
   477  LATIN CAPITAL LETTER E
   478  LATIN CAPITAL LETTER F
   479  LATIN CAPITAL LETTER T
   480  SPACE
   481  LATIN CAPITAL LETTER S
   482  LATIN CAPITAL LETTER T
   483  LATIN CAPITAL LETTER O
   484  LATIN CAPITAL LETTER P
   485  SPACE
   486  LATIN CAPITAL LETTER M
   487  LATIN CAPITAL LETTER A
   488  LATIN CAPITAL LETTER R
   489  LATIN CAPITAL LETTER K
   490  SPACE
   491  LATIN CAPITAL LETTER F
   492  LATIN CAPITAL LETTER U
   493  LATIN CAPITAL LETTER L
   494  LATIN CAPITAL LETTER L
   495  SPACE
   496  LATIN CAPITAL LETTER S
   497  LATIN CAPITAL LETTER I
   498  LATIN CAPITAL LETTER G
   499  LATIN CAPITAL LETTER N
   500  SPACE
   501  LATIN CAPITAL LETTER Z
   502  LATIN CAPITAL LETTER E
   503  LATIN CAPITAL LETTER R
   504  LATIN CAPITAL LETTER O
   505  SPACE
   506  LATIN CAPITAL LETTER T
   507  LATIN CAPITAL LETTER W
   508  LATIN CAPITAL LETTER O
   509  SPACE
   510  LATIN CAPITAL LETTER O
   511  LATIN CAPITAL LETTER N
   512  LATIN CAPITAL LETTER E
   513  SPACE
   514  LATIN CAPITAL LETTER L
   515  LATIN CAPITAL LETTER O
   516  LATIN CAPITAL LETTER W
   517  SPACE
   518  LATIN CAPITAL LETTER S
   519  LATIN CAPITAL LETTER I
   520  LATIN CAPITAL LETTER X
   521  SPACE
   522  LATIN CAPITAL LETTER A
   523  LATIN CAPITAL LETTER T
   524  QUOTATION MARK
   525  COMMA
   526  LATIN SMALL LETTER W
   527  RIGHT PARENTHESIS
   528  SEMICOLON
   529  LATIN SMALL LETTER Y
   530  EQUALS SIGN
   531  LATIN SMALL LETTER W
   532  LEFT SQUARE BRACKET
   533  DIGIT TWO
   534  RIGHT SQUARE BRACKET
   535  SEMICOLON
   536  LATIN SMALL LETTER F
   537  LATIN SMALL LETTER O
   538  LATIN SMALL LETTER R
   539  LEFT PARENTHESIS
   540  LATIN SMALL LETTER X
   541  EQUALS SIGN
   542  LATIN SMALL LETTER W
   543  LEFT SQUARE BRACKET
   544  DIGIT ONE
   545  RIGHT SQUARE BRACKET
   546  SEMICOLON
   547  LATIN SMALL LETTER I
   548  PLUS SIGN
   549  PLUS SIGN
   550  LESS-THAN SIGN
   551  DIGIT TWO
   552  DIGIT SIX
   553  SEMICOLON
   554  LATIN SMALL LETTER X
   555  EQUALS SIGN
   556  LATIN SMALL LETTER X
   557  QUOTATION MARK
   558  LATIN SMALL LETTER N
   559  LATIN CAPITAL LETTER W
   560  RIGHT SQUARE BRACKET
   561  COMMA
   562  QUOTATION MARK
   563  RIGHT PARENTHESIS
   564  LATIN SMALL LETTER Y
   565  EQUALS SIGN
   566  LATIN SMALL LETTER Y
   567  QUOTATION MARK
   568  LATIN SMALL LETTER N
   569  LATIN SMALL LETTER J
   570  RIGHT SQUARE BRACKET
   571  COMMA
   572  QUOTATION MARK
   573  SEMICOLON
   574  LATIN SMALL LETTER F
   575  LATIN SMALL LETTER O
   576  LATIN SMALL LETTER R
   577  LEFT PARENTHESIS
   578  LATIN SMALL LETTER S
   579  LATIN SMALL LETTER P
   580  LATIN SMALL LETTER L
   581  LATIN SMALL LETTER I
   582  LATIN SMALL LETTER T
   583  LEFT PARENTHESIS
   584  LATIN SMALL LETTER X
   585  SPACE
   586  LATIN SMALL LETTER Y
   587  SPACE
   588  LATIN SMALL LETTER W
   589  LEFT SQUARE BRACKET
   590  DIGIT THREE
   591  RIGHT SQUARE BRACKET
   592  COMMA
   593  LATIN SMALL LETTER B
   594  COMMA
   595  QUOTATION MARK
   596  COMMA
   597  QUOTATION MARK
   598  RIGHT PARENTHESIS
   599  SEMICOLON
   600  LATIN SMALL LETTER J
   601  PLUS SIGN
   602  PLUS SIGN
   603  LESS-THAN SIGN
   604  DIGIT ONE
   605  DIGIT TWO
   606  DIGIT SIX
   607  SEMICOLON
   608  LATIN CAPITAL LETTER F
   609  LATIN CAPITAL LETTER S
   610  EQUALS SIGN
   611  LOW LINE
   612  RIGHT PARENTHESIS
   613  LATIN SMALL LETTER D
   614  LEFT SQUARE BRACKET
   615  LATIN SMALL LETTER S
   616  LATIN SMALL LETTER P
   617  LATIN SMALL LETTER R
   618  LATIN SMALL LETTER I
   619  LATIN SMALL LETTER N
   620  LATIN SMALL LETTER T
   621  LATIN SMALL LETTER F
   622  LEFT PARENTHESIS
   623  QUOTATION MARK
   624  PERCENT SIGN
   625  LATIN SMALL LETTER C
   626  QUOTATION MARK
   627  COMMA
   628  LATIN SMALL LETTER J
   629  RIGHT PARENTHESIS
   630  RIGHT SQUARE BRACKET
   631  EQUALS SIGN
   632  LATIN SMALL LETTER J
   633  RIGHT CURLY BRACKET
   634  LEFT CURLY BRACKET
   635  LATIN SMALL LETTER F
   636  LATIN SMALL LETTER O
   637  LATIN SMALL LETTER R
   638  LEFT PARENTHESIS
   639  LATIN SMALL LETTER K
   640  EQUALS SIGN
   641  DIGIT ZERO
   642  SEMICOLON
   643  LATIN SMALL LETTER K
   644  PLUS SIGN
   645  PLUS SIGN
   646  LESS-THAN SIGN
   647  LATIN CAPITAL LETTER N
   648  LATIN CAPITAL LETTER F
   649  SEMICOLON
   650  LATIN SMALL LETTER P
   651  LATIN SMALL LETTER R
   652  LATIN SMALL LETTER I
   653  LATIN SMALL LETTER N
   654  LATIN SMALL LETTER T
   655  SPACE
   656  LATIN SMALL LETTER I
   657  EQUALS SIGN
   658  LOW LINE
   659  RIGHT PARENTHESIS
   660  LATIN SMALL LETTER W
   661  LATIN SMALL LETTER H
   662  LATIN SMALL LETTER I
   663  LATIN SMALL LETTER L
   664  LATIN SMALL LETTER E
   665  LEFT PARENTHESIS
   666  LATIN SMALL LETTER I
   667  PLUS SIGN
   668  PLUS SIGN
   669  LESS-THAN SIGN
   670  LATIN SMALL LETTER S
   671  LATIN SMALL LETTER P
   672  LATIN SMALL LETTER L
   673  LATIN SMALL LETTER I
   674  LATIN SMALL LETTER T
   675  LEFT PARENTHESIS
   676  LATIN SMALL LETTER B
   677  LEFT SQUARE BRACKET
   678  LATIN SMALL LETTER D
   679  LEFT SQUARE BRACKET
   680  DOLLAR SIGN
   681  LATIN SMALL LETTER K
   682  RIGHT SQUARE BRACKET
   683  HYPHEN-MINUS
   684  DIGIT THREE
   685  DIGIT ONE
   686  RIGHT SQUARE BRACKET
   687  COMMA
   688  LATIN SMALL LETTER Q
   689  RIGHT PARENTHESIS
   690  RIGHT PARENTHESIS
   691  LATIN SMALL LETTER P
   692  LATIN SMALL LETTER R
   693  LATIN SMALL LETTER I
   694  LATIN SMALL LETTER N
   695  LATIN SMALL LETTER T
   696  LATIN SMALL LETTER F
   697  LEFT PARENTHESIS
   698  LATIN SMALL LETTER Z
   699  EQUALS SIGN
   700  LATIN SMALL LETTER W
   701  LEFT SQUARE BRACKET
   702  LATIN SMALL LETTER D
   703  LEFT SQUARE BRACKET
   704  LATIN SMALL LETTER Q
   705  LEFT SQUARE BRACKET
   706  LATIN SMALL LETTER I
   707  RIGHT SQUARE BRACKET
   708  RIGHT SQUARE BRACKET
   709  HYPHEN-MINUS
   710  DIGIT SIX
   711  DIGIT NINE
   712  RIGHT SQUARE BRACKET
   713  RIGHT PARENTHESIS
   714  QUOTATION MARK
   715  SPACE
   716  QUOTATION MARK
   717  LEFT PARENTHESIS
   718  LATIN SMALL LETTER Z
   719  TILDE
   720  SOLIDUS
   721  LATIN CAPITAL LETTER T
   722  LATIN CAPITAL LETTER T
   723  SOLIDUS
   724  QUESTION MARK
   725  LATIN SMALL LETTER T
   726  LATIN SMALL LETTER O
   727  LATIN SMALL LETTER U
   728  LATIN SMALL LETTER P
   729  LATIN SMALL LETTER P
   730  LATIN SMALL LETTER E
   731  LATIN SMALL LETTER R
   732  LEFT PARENTHESIS
   733  DOLLAR SIGN
   734  LATIN SMALL LETTER K
   735  RIGHT PARENTHESIS
   736  COLON
   737  LOW LINE
   738  RIGHT PARENTHESIS
   739  RIGHT CURLY BRACKET

```

Just kidding ;D

```
BEGIN{split("i,Lv,Sv,ax,^x,[x,Q,O,tK,cK,V,qx,g,I,wu,X,by,b{,bz,bd,bp,br,b},bk,bl,bo,e,P,Rx,_x,Jx,Uv,M~, t`Y,ZX,c`Y,N\\,|s,m\\, thY,Ts,chY,f HYPHEN-MINUS GREATER-THAN PARENTHESIS EXCLAMATION COMMERCIAL CIRCUMFLEX APOSTROPHE SEMICOLON AMPERSAND LESS-THAN QUOTATION VERTICAL QUESTION ASTERISK CAPITAL SOLIDUS BRACKET REVERSE PERCENT ACCENT LETTER DOLLAR EQUALS SQUARE NUMBER DIGIT RIGHT THREE COLON TILDE COMMA CURLY SPACE SMALL SEVEN EIGHT GRAVE LATIN NINE FOUR PLUS FIVE LINE LEFT STOP MARK FULL SIGN ZERO TWO ONE LOW SIX AT",w);x=w[1];for(y=w[2];C++<26;x=x"nW],")y=y"nj],";for(split(x y w[3],b,",");j++<126;FS=_)d[sprintf("%c",j)]=j}{for(k=0;k++<NF;print i=_)while(i++<split(b[d[$k]-31],q))printf(z=w[d[q[i]]-69])" "(z~/TT/?toupper($k):_)}

```

Works with stdin/stdout.

More "readable":

```
BEGIN{

  # This string (508 bytes) holds a representation of the character names in
  # the right order, plus a list of the used words.

    split("i,Lv,Sv,ax,^x,[x,Q,O,tK,cK,V,qx,g,I,wu,X,by,b{,bz,bd,bp,br,b},bk,bl,bo,
    e,P,Rx,_x,Jx,Uv,M~, t`Y,ZX,c`Y,N\\,|s,m\\, thY,Ts,chY,f HYPHEN-MINUS GREATER-T
    HAN PARENTHESIS EXCLAMATION COMMERCIAL CIRCUMFLEX APOSTROPHE SEMICOLON AMPERSA
    ND LESS-THAN QUOTATION VERTICAL QUESTION ASTERISK CAPITAL SOLIDUS BRACKET REVE
    RSE PERCENT ACCENT LETTER DOLLAR EQUALS SQUARE NUMBER DIGIT RIGHT THREE COLON
    TILDE COMMA CURLY SPACE SMALL SEVEN EIGHT GRAVE LATIN NINE FOUR PLUS FIVE LINE
     LEFT STOP MARK FULL SIGN ZERO TWO ONE LOW SIX AT",w);

  # Since the letters each appear 26 times I construct that part at runtime.
  # The array b will hold the coded combinations of which words need to
  # be printed for each input character.

    x=w[1];
    for(y=w[2];C++<26;x=x"nW],")
        y=y"nj],";

  # The array d is an ASCIICodeFromChar function replacement.
  # I set the field separator to empty, so each character of the input is
  # an input field. That's why using a BEGIN part was mandatory.

    for(split(x y w[3],b,",");j++<126;FS=_)
        d[sprintf("%c",j)]=j
}

  # Here I go through the element of b that matches the input and print
  # the requested words, using the input to produce a capital letter if
  # needed. I excluded these from the word list to save another 26 bytes

{
    for(k=0;k++<NF;print i=_)
        while(i++<split(b[d[$k]-31],q))
            printf(z=w[d[q[i]]-69])" "(z~/TT/?toupper($k):_)
}

```

# Answer
> 6 votes
# C++11, 739 bytes

```
#include<iostream>
#define D,"DIGIT "
#define G" SIGN",
int main(){std::string a=" BRACKET",s="SQUARE"+a,c="CURLY"+a,t="TION MARK",p="PARENTHESIS",l="LEFT ",r="RIGHT ",x="LATIN ",y="L LETTER ",z[]{"SPACE","EXCLAMA"+t,"QUOTA"+t,"NUMBER"G"DOLLAR"G"PERCENT"G"AMPERSAND","APOSTROPHE",l+p,r+p,"ASTERISK","PLUS"G"COMMA","HYPHEN-MINUS","FULL STOP","SOLIDUS"D"ZERO"D"ONE"D"TWO"D"THREE"D"FOUR"D"FIVE"D"SIX"D"SEVEN"D"EIGHT"D"NINE","COLON","SEMICOLON","LESS-THAN"G"EQUALS"G"GREATER-THAN"G"QUES"+t,"COMMERCIAL AT",l+s,"REVERSE SOLIDUS",r+s,"CIRCUMFLEX ACCENT","LOW LINE","GRAVE ACCENT",l+c,"VERTICAL LINE",r+c,"TILDE"};getline(std::cin,s);for(char c:s)std::cout<<(c<65?z[c-32]:c<91?x+"CAPITA"+y+c:(c-=32,c<65?z[c-26]:c<91?x+"SMAL"+y+c:z[c-52]))+"\n";}

```

Based on sweerpotato's solution, but modified heavily.

# Answer
> 5 votes
## C++14, 1043 1000 998 996 972 bytes

Grotesque solution in C++14:

```
#include<iostream>
#include<map>
#define b cout
#define d string
#define e },{
using namespace std;char l='\n';d s[]{"DIGIT ","LATIN CAPITAL LETTER ","LATIN SMALL LETTER "};map<char, d> m{{' ',"SPACE"e'!',"EXCLAMATION MARK"e'\"',"QUOTATION MARK"e'#',"NUMBER SIGN"e'$',"DOLLAR SIGN"e'%',"PERCENT SIGN"e'&',"AMPERSAND"e'\'',"APOSTROPHE"e'(',"LEFT PARENTHESIS"e')',"RIGHT PARENTHESIS"e'*',"ASTERISK"e'+',"PLUS SIGN"e',',"COMMA"e'-',"HYPHEN-MINUS"e'.',"FULL STOP"e'/',"SOLIDUS"e':',"COLON"e';',"SEMICOLON"e'<',"LESS-THAN SIGN"e'=',"EQUALS SIGN"e'>',"GREATER-THAN SIGN"e'?',"QUESTION MARK"e'@',"COMMERCIAL AT"e'[',"LEFT SQUARE BRACKET"e'\\',"REVERSE SOLIDUS"e']',"RIGHT SQUARE BRACKET"e'^',"CIRCUMFLEX ACCENT"e'_',"LOW LINE"e'`',"GRAVE ACCENT"e'{',"LEFT CURLY BRACKET"e'|',"VERTICAL LINE"e'}',"RIGHT CURLY BRACKET"e'~',"TILDE"}};int main(){d str;getline(cin,str);for(char c:str){islower(c)?b<<s[2]<<(char)(c-32):isupper(c)?b<<s[1]<<c:isdigit(c)?b<<*s<<c:b<<m.at(c);b<<l;}}

```

*Thanks to kirbyfan64sos for golfing off two bytes*

# Answer
> 5 votes
# Common Lisp (SBCL), ~~52~~ 79

```
(map()(lambda(y)(format t"~:@(~A~)~%"(substitute #\  #\_(char-name y))))(read))

```

This is built-in and implementation-dependent, so you may want to ignore it when choosing the accepted answer. This is not enough to beat Python, unfortunately. The updated version conforms to the expected output (I have to replace underscores by spaces).

## Example

```
CL-USER> (map()(lambda(y)(format t"~:@(~A~)~%"(substitute #\  #\_(char-name y))))(read))
"(λ(r)(* 2 ᴨ r))"
LEFT PARENTHESIS
GREEK SMALL LETTER LAMDA
LEFT PARENTHESIS
LATIN SMALL LETTER R
RIGHT PARENTHESIS
LEFT PARENTHESIS
ASTERISK
SPACE
DIGIT TWO
SPACE
GREEK LETTER SMALL CAPITAL PI
SPACE
LATIN SMALL LETTER R
RIGHT PARENTHESIS
RIGHT PARENTHESIS

```

# Answer
> 4 votes
# Pyth, 41

```
$from unicodedata import name as neg$Vz_N

```

Uses same builtin as mbomb007's python answer. Note that this cannot be executed online because the `$` operator is unsafe.

# Answer
> 4 votes
# CJam, 517

```
l{i32-["SPACE""EXCLAMA""TION MARK":T+"QUOTA"T+"NUMBER DOLLAR PERCENT"{S/" SIGN"am*~}:H~"AMPERSAND""APOSTROPHE""LEFT PARENTHESIS":L"RIGHT ":R1$5>+"ASTERISK""PLUS"H"COMMA""HYPHEN-MINUS""FULL STOP""SOLIDUS":D"DIGIT "a"ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE"S/m*~"COLON""SEMI"1$+"LESS-THAN EQUALS GREATER-THAN"H"QUES"T+"COMMERCIAL AT""CAPITA"{["LATIN "\"L LETTER "]a'[,65>m*~L5<}:Z~"SQUARE BRACKET":Q+"REVERSE "D+RQ+"CIRCUMFLEX ACCENT""LOW LINE""GRAVE"2$A>+"SMAL"Z"CURLY"33$B>+:C+"VERTICAL LINE"RC+"TILDE"]=N}/

```

Online version

I have tried different solutions but simply storing all the names in a huge array seems most efficient.

This is my first real CJam program by the way.

# Answer
> 4 votes
# Clojure, 56 bytes

```
(doseq[c(read-line)](println(Character/getName(int c))))

```

Inspired by @peter's answer. Uses Clojure for the Java interop.

# Answer
> 4 votes
# Perl - 894 bytes

Lovingly crafted by hand. First time golfing in Perl so any tips are appreciated.

```
$_=$ARGV[0];s/(.)/$1\n/g;s/([A-Z])/& CAPITAL' $1/g;s/([a-z])/& SMALL' \U$1/g;s/,/COMMA/g;s/& /LATIN /g;s/' / LETT, /g;s/&/AMP,SAND/g;s/'/APOSTROPHE/g;s/ \n/SPACE\n/g;s/\*/AST,ISK/g;s/-/HYPHEN-MINUS/g;s/\./FULL STOP/g;s/@/COMM,CIAL AT/g;s/~/TILDE/g;s/:/&/g;s/;/SEMI&/g;s/&/COLON/g;s/\|/V,TICAL&/g;s/_/LOW&/g;s/&/ LINE/g;s/\^/CIRCUMFLEX&/g;s/`/GRAVE&/g;s/&/ ACCENT/g;s/\//&/g;s/\\/REV,SE &/g;s/&/SOLIDUS/g;s/!/!&/g;s/"/"&/g;s/\?/?&/g;s/!/EXCLAMA/g;s/"/QUOTA/g;s/\?/QUES/g;s/&/TION MARK/g;s/#/NUMB,&/g;s/\$/DOLLAR&/g;s/%/P,CENT&/g;s/\+/PLUS&/g;s/</LESS-THAN&/g;s/=/EQUALS&/g;s/>/GREAT,-THAN&/g;s/&/ SIGN/g;s/\(/<&/g;s/\)/>&/g;s/&/ PARENTHESIS/g;s/\[/<&/g;s/\]/>&/g;s/&/ SQUARE'/g;s/{/<&/g;s/}/>&/g;s/&/ CURLY'/g;s/'/ BRACKET/g;s/</LEFT/g;s/>/RIGHT/g;s/0/&Z,O/g;s/1/&ONE/g;s/2/&TWO/g;s/3/&THREE/g;s/4/&FOUR/g;s/5/&FIVE/g;s/6/&SIX/g;s/7/&SEVEN/g;s/8/&EIGHT/g;s/9/&NINE/g;s/&/DIGIT /g;s/,/ER/g;print;

```

# Answer
> 3 votes
## C++14 ~~716~~ ~~706~~ 704

```
#include<iostream>
char*q,x,b[584],*t=b,a[]=R"(space}exclamation|mark}quot"-number|sign}dolla!apercent!mam"%sand}apostrophe}left|par%3hesis}righ"Wasterisk}plus*<comma}hy)#n{minus}full|stop}solid"Ldigit|zero!Tone!Gtw"kthre#&four!Uiv#&six!Heve>^!_e6r!ani,1colon}semi!Fless{than8Eequal:$grea<s$2quesMj>EJoial|at}lQ9n|capit"?let('|Jes+\re|bracket}r5urse|C5M?%2circumflex|acXR}low|l:bgrave#'0=smaNy0+curly*s/Ytic4z)$/\$itilde)",*s=a;int c,z,l='{';int main(){for(;x=*s++;)if(z=x-32,x>96)*t++=x<l?z:"- "[x%l];else for(c=z*95+*s++-32,q=t-c/13,x=3+c%13;x--;)*t++=*q++;while(std::cin.get(x)){for(s=b,z=0,c=x<65?x-32:x<91?z=33:x<97?x-57:x<l?z=40:x-82;c--;)while(*s++);auto&o=std::cout<<s;(z?o.put(x&~32):o)<<"\n";}}

```

Live version.

With some whitespace:

```
#include <iostream>

// a is compressed using an LZ like compression scheme
char *q, x, b[584],
    *t = b,
    a[] =
        R"(space}exclamation|mark}quot"-number|sign}dolla!apercent!mam"%sand}apostrophe}left|par%3hesis}righ"Wasterisk}plus*<comma}hy)#n{minus}full|stop}solid"Ldigit|zero!Tone!Gtw"kthre#&four!Uiv#&six!Heve>^!_e6r!ani,1colon}semi!Fless{than8Eequal:$grea<s$2quesMj>EJoial|at}lQ9n|capit"?let('|Jes+\re|bracket}r5urse|C5M?%2circumflex|acXR}low|l:bgrave#'0=smaNy0+curly*s/Ytic4z)$/\$itilde)",
    *s = a;

int c, z, l = '{';

int main() {
    // Decompress from a into b
    for (; x = *s++;)
        if (z = x - 32, x > 96)
            *t++ = x < l ? z : "- "[x % l];
        else
            for (c = z * 95 + *s++ - 32, q = t - c / 13, x = 3 + c % 13; x--;) *t++ = *q++;

    // Process input a char at a time, performing a lookup into b for the c'th null separated string
    while (std::cin.get(x)) {
        for (s = b, z = 0,
            c = x < 65 ? x - 32 : x < 91 ? z = 33 : x < 97 ? x - 57 : x < l ? z = 40 : x - 82;
             c--;)
            while (*s++)
                ;
        auto& o = std::cout << s;
        (z ? o.put(x & ~32) : o) << "\n";
    }
}

```

The compressed string `a` decompresses to:

> space}exclamation|mark}quotation|mark}number|sign}dollar|sign}percent|sign}ampersand}apostrophe}left|parenthesis}right|parenthesis}asterisk}plus|sign}comma}hyphen{minus}full|stop}solidus}digit|zero}digit|one}digit|two}digit|three}digit|four}digit|five}digit|six}digit|seven}digit|eight}digit|nine}colon}semicolon}less{than|sign}equals|sign}greater{than|sign}question|mark}commercial|at}latin|capital|letter|}left|square|bracket}reverse|solidus}right|square|bracket}circumflex|accent}low|line}grave|accent}latin|small|letter|}left|curly|bracket}vertical|line}right|curly|bracket}tilde

And during decompression `}` is replaced with `\0`, `|` with  (space) and `{` with `-` and lowercase letters are converted to uppercase.

The string is compressed LZ style as either a literal `[a-~]` or a two character encoded offset/length to a match earlier in the string.

# Answer
> 1 votes
# Factor, 58 bytes

```
[ readln [ char>name "-"" " replace >upper print ] each ]

```

Pretty simple; does the exact same thing as the Java and Perl 6 answers.

# Answer
> 1 votes
# Go, 145 bytes

```
package main
import(."golang.org/x/text/unicode/runenames"
."fmt")
func main(){r:='!'
for{_,e:=Scanf("%c",&r)
if e!=nil{break}
println(Name(r))}}

```

Some have address a concern with the above answer. I tried vendoring the code in question, but my answer bypassed the 65,536 byte limit \[1\], so I think the above answer is fine as is.

1. https://github.com/golang/text/blob/v0.3.6/unicode/runenames/tables13.0.0.go

# Answer
> -1 votes
# PHP\>=7, 54 Bytes

```
for(;a&$c=$argn[$i++];)echo"
".IntlChar::charName($c);

```

IntlChar::charName

---
Tags: code-golf, unicode
---


# Question
Title: Codegolf Rainbow : Sorting Colors with Reflection
## Introduction:

After I posted two rainbow-related challenges: *Codegolf Rainbow : Fun with Integer-Arrays* 1 and *Codegolf Rainbow : Draw in Black-and-White* 2, the following comment was made by *@ChrisM* in the ASCII (*Draw in Black-and-White*) challenge:

> Maybe you know this and it's by design (I know that rainbows are not rhombuses or ascii, too, and higher orders' positions get more complicated), but aren't the colours reversed in the 2nd rainbow?

And he's indeed right. When you see a double rainbow, the second one is actually a reflection of the first, so the colors are reversed. With three rainbows, it's an actual double rainbow, with the third one being a reflection of one of the other two. And with four, there are two rainbows, and two reflections of those.

So, let's make a third related challenge using that fact.

## Challenge:

Inputs: A positive integer `n` which is `>=2`, and a list of integers of size `>= n+1`.
Output: The same list ordered as follows:

1. First split the input lists in sub-lists of size `n` (where the trailing sub-list could be of any size in the range `[1,n]`).
2. Then we do the following based on the amount of sub-lists `m`:
    * Sort the first `m - m//2` amount of sub-lists from lowest to highest (where `//` is integer-divide). (I.e. with 6 sub-lists the first three will be sorted from lowest to highest; with 5 sub-lists the fist three will be sorted from lowest to highest.)
    * Sort the last `m//2` amount of sub-lists from highest to lowest (where `//` is integer-divide). (I.e. with 6 sub-lists the last three will be sorted from highest to lowest; with 5 sub-lists the last two will be sorted from highest to lowest.)
3. Merge all sub-lists together to form a single list again

### Examples:

Inputs: `n=7` and `[3,2,1,-4,5,6,17,2,0,3,5,4,66,-7,7,6,-5,2,10]`
Step 1: `[[3,2,1,-4,5,6,17],[2,0,3,5,4,66,-7],[7,6,-5,2,10]]`
Step 2: `[[-4,1,2,3,5,6,17],[-7,0,2,3,4,5,66],[10,7,6,2,-5]]`
Step 3 / Output: `[-4,1,2,3,5,6,17,-7,0,2,3,4,5,66,10,7,6,2,-5]`

Inputs: `n=4` and `[7,4,-8,9,3,19,0,-23,-13,13]`
Step 1: `[[7,4,-8,9],[3,19,0,-23],[-13,13]]`
Step 2: `[[-8,4,7,9],[-23,0,3,19],[13,-13]]`
Step 3 / Output: `[-8,4,7,9,-23,0,3,19,13,-13]`

## Challenge rules:

* The integer input `n` is guaranteed to be larger than 1.
* The size of the integer-list is guaranteed to be larger than `n`.
* The trailing sub-list can be smaller than `n` (as can be seen in the examples and test cases).
* I/O format is flexible in any reasonable format. Can be a list/array of integers or decimals, a comma/space/newline delimited string, stream of integers, etc. (Output may not be a 2D list of lists like step 2. Step 3 to flatten it back into a single list is required for this challenge.)

## General rules:

* This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* Default Loopholes are forbidden.
* If possible, please add a link with a test for your code.
* Also, adding an explanation for your answer is highly recommended.

## Test cases:

```
Inputs: n=7 and [3,2,1,-4,5,6,17,2,0,3,5,4,66,-7,7,6,-5,2,10]
Output: [-4,1,2,3,5,6,17,-7,0,2,3,4,5,66,10,7,6,2,-5]

Inputs: n=4 and [7,4,-8,9,3,19,0,-23,-13,13]
Output: [-8,4,7,9,-23,0,3,19,13,-13]

Inputs: n=2 and [7,-3,1]
Output: [-3,7,1]

Inputs: n=3 and [1,6,99,4,2]
Output: [1,6,99,4,2]

Inputs: n=2 and [5,2,9,3,-5,-5,11,-5,4,12,9,-2,0,4,1,10,11]
Output: [2,5,3,9,-5,-5,-5,11,4,12,9,-2,4,0,10,1,11]

Inputs: n=3 and [5,2,9,3,-5,-5,11,-5,4,12,9,-2,0,4,1,10,11]
Output: [2,5,9,-5,-5,3,-5,4,11,12,9,-2,4,1,0,11,10]

```

# Answer
> 6 votes
# Brachylog, ~~18~~ ~~17~~ 16 bytes

```
ġ₎↔ḍ↔{izo₎ᵐ↔}ᶠcc

```

Try it online!

-1 byte thanks to @sundar

Expects input as `[<integer list>, n]`. Note that negative integers are represented with `_`, Brachylog's "low minus". Output variable is `R`.

First time attempting Brachylog, so I imagine it's sub-optimal and ripe for reducing in bytes.

## Explanation

Partition, bifurcate, sort based on index (0: asc, 1: desc), flatten.

```
ġ₎               | split head of input into groups of length n (last of list)
  ↔              | reverse so that...
   ḍ             | dichotomize splits in two, attaching any additional element to the second list
    ↔            | reverse so first half of partitions corresponds to the 0 index
     {      }    | apply
      i          | : append index
       z         | : zip each sublist with the index of its parent
        o₎ᵐ      | : map over sublists, ordering by the zipped index
           ↔     | : undo earlier reverse
             ᶠ   | find all outputs
              cc | flatten two levels

```

# Answer
> 3 votes
# Jelly, 9 bytes

```
sṢ€ŒHUÐeF

```

Try it online!

# Answer
> 2 votes
# Python 2, 82 bytes

```
lambda n,l:sum([sorted(l[i:i+n],reverse=i>len(l)/2)for i in range(0,len(l),n)],[])

```

Try it online!

# Answer
> 2 votes
# 05AB1E (legacy), 9 bytes

```
ô€{2ä`í«˜

```

Try it online!

Try it online! in 05AB1E (Elixir rewrite) – expects input to be on the stack, a default I/O method.

Kevin came up with his own 11-byter which I used to get to 10. Then I came up with something else for 9 bytes.

# Answer
> 2 votes
# Japt, 10 bytes

```
òV ®nÃÇwÃc

```

---

```
Also 10 bytes
òV mn ow c

```

Try it online!

# Answer
> 2 votes
# JavaScript (ES6), ~~82~~ 81 bytes

*Saved 1 byte thanks to @redundancy*

Takes input as `(list)(n)`.

```
a=>n=>(g=z=>a+a?[...a.splice(0,n).sort((x,y)=>1/z?x-y:y-x),...g(a[i+=n])]:a)(i=0)

```

Try it online!

# Answer
> 2 votes
# Clojure, 90 bytes

```
#(for[i[0 1]j((split-at(/(count %)2%2)(partition-all %2%))i)k(([seq reverse]i)(sort j))]k)

```

Try it online!

# Answer
> 1 votes
# Vyxal, 23 bytes

```
ẇD:L½:£⌈Ẏvs⅛_¥⌈ȯvsvṘ⅛¾f

```

Try it Online!

A big mess.

---
Tags: code-golf, number, array, sorting, subsequence
---


title: The kitten command

text:
# Question
Title: The kitten command
A kitten is much like a cat. Some of the main differences are cuteness, lack of intelligence, and size. Similarly, the `cat` command is different from the `kitten` command. Fortunately, there is only one difference in this case. In the kitten command, all uppercase letters are replaced with lowercase letters.

---

# Objective

To implement a program that behaves similarly to `cat`. All characters `[A-Z]` are outputted lowercase.

---

# Input

A list of files as command line arguments. If no files are listed, then read from standard input. The input may contain unprintable characters and characters outside the ASCII range.

---

# Output

If input is a bunch of files, concatenate the contents and output all characters as lowercase. If reading from STDIN, output the contents of STDIN with all uppercase letters as lowercase.

Note: Only make the characters `[A-Z]` lowercase. It is unacceptable if any other characters are made lowercase.

---

## Examples

```
$ echo "HelLo" > file.txt
$ kitten file.txt
hello
$ echo "Good Bye" | kitten
good bye
$ echo "Ä" | kitten
Ä

```

As usual with , least bytes wins.

## Leaderboards

---

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
# Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
# Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
# Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the leaderboard snippet:

```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=59029,OVERRIDE_USER=32700;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
# Perl, 6 bytes

5 bytes code + 1 byte command line

```
$_=lc

```

Example usage:

```
echo ABCdef | perl -p kitten.pl
abcdef

```

Confirmation of correct Unicode behaviour:

```
echo "HelloÉ" | perl -p kitten.pl
helloÉ

```
> 54 votes

# Answer
# Bash, 19 bytes

```
cat "$@"|tr A-Z a-z

```

The best way to make kittens is to use actual cats.

### Example run

```
$ ./kitten kitten
cat "$@"|tr a-z a-z

```
> 182 votes

# Answer
# Perl, 11 bytes

10 bytes code + 1 byte command line

```
y/A-Z/a-z/

```

Example usage:

```
perl -p entry.pl input1.txt input2.txt
echo "ABCdef" | perl -p entry.pl

```
> 22 votes

# Answer
# Python 3, 77 bytes

```
from fileinput import*
print(end=b''.join(input(mode='rb')).lower().decode())

```
> 15 votes

# Answer
# Ruby, 13 bytes

The byte count includes 1 byte for the `p` flag. Run it like so: `ruby -p kitten.rb`.

```
$_.downcase!

```

Takes input from stdin or file arguments, just like grown up cat.
> 11 votes

# Answer
# PowerShell, 112 Bytes

```
function l([string]$a){97..122|%{[char]$b=$_;$a=$a-split$b-join$b};$a}if($args){$args|%{l(gc $_)}}else{l $input}

```

Horrendously unreadable. Here's a slightly expanded version below:

```
function l([string]$a){
  97..122|%{
    [char]$b=$_
    $a=$a-split$b-join$b
  }
  $a
}

if($args){
  $args|%{
    l(gc $_)
  }
}
else{
  l $input
}

```

Defines an internal function `l` which iterates over a loop from 97 to 112 (i.e., ASCII `a` to ASCII `z`). Splits the input string over that character (yay case-insensitive default), the rejoins it with the "correct" lower case. Do note that yes, this means "Test" would briefly become "T st" as it's iterating through the `e`, for example. Doesn't affect output.

The second half is the tricky bit to figure out if we have pipeline input (equivalent to stdin for PowerShell) or command-line input. The special variable `$args` is only present if command-line input is present, so we loop over each one, `gc` (for `Get-Content`) and schlep that up to `l`. Otherwise, we just schlep our `$input` up to `l`. Note that we could swap our if/else statements (i.e., `if($input)`), but since "input" is one character longer than "args" this way is shorter.
> 5 votes

# Answer
# R, 97 bytes

```
cat(chartr("A-Z","a-z",sapply(if(length(a<-commandArgs(T))){a}else{"stdin"},readLines)),sep="\n")

```

Usage:

```
$ echo "HeLlo" > file.txt
$ Rscript kitten.R file.txt
hello
$ echo "Good Bye" | Rscript kitten.R
good bye
$ echo "bLABLa" > file2.txt
$ Rscript kitten.R file.txt file2.txt
hello
blabla
$ echo Ä | Rscript kitten.R
Ä

```
> 5 votes

# Answer
# CoffeeScript, 292 bytes

```
f=require 'fs';d='';p=process;v=p.argv;s=p.stdin;l=((d)=>console.log d.replace /([A-Z])/g,(a,l)=>l.toLowerCase());if v.length>2 then(v.forEach (v,i)=>if i>1 then(f.exists v, (e) =>if e then(f.readFile v,'utf-8',(r,d)=>l d) else l v))else(s.resume();(s.on 'data',(c)=>d+=c);s.on 'end',()=>l d)

```

Usage:

```
$ echo "HelLo" > file.txt
$ coffee kitten.coffee file.txt
hello
$ echo "Good Bye" | coffee kitten.coffee
good bye
$ echo "Ä" | kitten
Ä
$ coffee kitten.coffee file.txt SoMeTeXt
sometext
hello

```

My first participation on codegolf so please don't be rude :).

For sure this code can be golfed more and coffee/javascript isn't the best choice to do that, but it does what's expected.

When it reads arguments it also takes care about file existency (if file does not exists, the string is kittened.)

Any help or advice to improve this code is welcome !
> 5 votes

# Answer
# Julia, 123 bytes

```
f(s)=for l=readlines(s) print(replace(l,r"[A-Z]",lowercase))end
A=ARGS
length(A)>0?for i=A open(f,i)end:open(f,readline())

```

Ungolfed:

```
function file_to_lower(s::Stream)
    # Loop over the lines of the input stream
    for l in readlines(r)
        # Print the lowercased line
        print(replace(l, r"[A-Z]", lowercase))
    end
end

if length(ARGS) > 0
    # Loop over the files specified from the command line
    for i in ARGS
        # Open the file, apply the function, then close it
        open(file_to_lower, i)
    end
else
    # Get the input file from STDIN
    open(file_to_lower, readline())
end

```
> 4 votes

# Answer
# Python 2, ~~100~~ ~~102~~ 97 bytes

*Functionality corrected (and 4 bytes added) by matsjoyce. Fortunately, I saved two bytes by switching to Python 2.*

```
from sys import*;print''.join(f.read().lower()for f in(map(open,argv[1:])if argv[1:]else[stdin]))

```

Takes arguments from the command line, or from STDIN if no arguments found.

This abuses the default arguments of some functions. By default, `open` uses read-only text mode, which is exactly what we want. `read`, if called with no arguments, will return all text in the stream.

Ungolfed:

```
import sys

if len(sys.argv) > 1:              # If we have command-line arguments:
    source = []                    # Initialize an empty list
    for path in sys.argv[1:]:      # Iterate through every filename we have
        kitfile = open(path, 'rt') # Open the file in read-only text mode
        source.append(kitfile)     # Add it to the list
else:                              # Otherwise, if the args are empty:
    source = [sys.stdin]           # Set our source to STDIN wrapped in a list

kittened = []                      # Initialize an empty list
for kitfile in source:             # Iterate through every file (or just STDIN)
    text = kitfile.read()          # Read everything from the stream
    kitten_text = text.lower()     # Make it lowercase
    kittened.append(kitten_text)   # Add it to the list
final = ''.join(kittened)          # Join everything together
print final                        # Print the result

```
> 4 votes

# Answer
# Python 2, 53 bytes

```
from fileinput import*
print''.join(input()).lower(),

```
> 4 votes

# Answer
# CJam, 18 bytes

```
ea_:gs{q}?'_,_eler

```

The list of files must be supplied in form of URLs, which is the only format CJam understands.

### Example runs

```
$ cjam kitten <<< "AaÁáÄä"
aaÁáÄä
$ cjam kitten file:///home/dennis/kitten file:///home/dennis/kitten
ea_:gs{q}?'_,_elerea_:gs{q}?'_,_eler

```

### How it works

```
ea                  Push the array of command-line arguments.
  _                 Push a copy.
   :g               Retrieve the contents of all files with those URLS.
     s              Flatten the resulting array of strings.
      {q}           Push a block that reads all input from STDIN.
         ?          Select the string of the array of args is non-empty.
                    Otherwise, execute the code block.
          '_,       Push the string of all ASCII characters before _.
             _el    Push a copy and convert it to lowercase.
                er  Perform transliteration.

```
> 4 votes

# Answer
# C, ~~106~~ 108 bytes

*Edit: Fixed a mistake that creeped in when squeezing bytes. Stdin wasn't working, now it is.*

I'm pretty sure I could squeeze some bytes away, but here's an easy-to-grasp, not at all language abusive, submission:

```
main(n,s,f,c)void**s;{for(f=n-1?open(*++s,0,0):0;read(f,&c,1);putchar(64<c&c<91?c+32:c));n-->2&&main(n,s);}

```

And a somewhat more neatly formatted version for reading:

```
main(n,s,f,c)
void**s;
{
    for(f=n-1?open(*++s,0,0):0; read(f,&c,1); putchar(64<c&c<91?c+32:c));
    n-->2&&main(n,s);
}

```
> 4 votes

# Answer
# Python 3, ~~124~~ 123 bytes

---

```
from sys import*
for f in list(map(open,argv[1:]))or[stdin]:print(f.read().translate({i:i+32for i in range(65,91)}),end="")

```

Python eats kittens!

```
$ python kitten.py file.txt
hello
$ echo "Good Bye" | python kitten.py
good bye
$ echo "Ä" | python kitten.py
Ä

```
> 3 votes

# Answer
## Haskell, 133

```
import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

```

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

Explaining `l`, the function to lowercase one character:

* `sum[32|condition]` is a shorter form of `if condition then 32 else 0`.
* `[x..]!!count` is `iterate succ x !! count` is `toEnum $ fromEnum x + count` and shorter than importing and using `Data.Char.toLower` with a condition to restrict it to ASCII.
* `'@'` and `'['` are the characters immediately preceding `A` and following `Z`, so that I can use `<` instead of `<=`.

Thanks to Anders Kaseorg for contributing the `sum[...|...]` and `[x..]!!` tricks.
> 2 votes

# Answer
# Mathematica, 66 bytes

```
kit=StringReplace[#,x:RegularExpression["[A-Z]"]:>ToLowerCase[x]]&

```

Called as

```
kit@"HelLo"

```

Mathematica already has a `ToLowerCase` function, but it converts special (Unicode and mathematical) characters as well. So I had to kittenize it. This function will take any input.
> 2 votes

# Answer
# C#, ~~230~~ 226 bytes

```
namespace System{using Linq;class P{static void Main(string[]a){Console.Write(string.Concat((a.Length>0?string.Concat(a.Select(f=>IO.File.ReadAllText(f))):Console.In.ReadToEnd()).Select(c=>c>'@'&&c<'['?char.ToLower(c):c)));}}}

```

Ungolfed:

```
namespace System
{
    using Linq;
    class P
    {
        static void Main(string[] a)
        {
            Console.Write(                                                  // Print...
                string.Concat(                                                  // ...all chars combined to a string...
                    (a.Length > 0 ?                                             // ...commandline arguments?...
                        string.Concat(a.Select(f => IO.File.ReadAllText(f))) :  // ...then all files as single string...
                        Console.In.ReadToEnd()                                  // ...else STDIN input
                    ).Select(c => c > '@' && c < '[' ? char.ToLower(c) : c)     // ...Lowercase only A..Z
                )
            );
        }
    }
}

```
> 2 votes

# Answer
# C#, 342 bytes

* takes file list from passed arguments.
* read every char in every file than only converts to lower case if and only if the character in the A..Z range than send it to STDOUT.
* If there is no file list than reads STDIN, reads every char, converts to lower case if and only if the character in the A..Z range than send it to STDOUT.

```
namespace System{
using IO;
using Linq;
class P{
static void Main(string[]a){
Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};
if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));
else
while(true) Console.In.ReadLine().ToCharArray().ToList().ForEach(e);
}
}
}

```

# C#, 319 bytes

single-liner, same as above:

```
namespace System{using IO;using Linq;class P{static void Main(string[]a){Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));else while(true)Console.In.ReadLine().ToCharArray().ToList().ForEach(e);}}}

```
> 1 votes

# Answer
# S.I.L.O.S 179 characters

```
loadLine :
a = 256
x = get a
lbla
X = x
B = x
C = 91
B - 64
if B c
printChar x
GOTO x
lblc
C - x
if C D
printChar x
GOTO x
lblD
x + 32
printChar x
lblx
a + 1
x = get a
if x a
lblb

```

Feel free to try this code online!

---

Essentially it translates to this in pusedocode.
```
String input = input();
for(char c in input)
if(c is uppercase) print c + 32/*lowercase c*/else print c

```
> 1 votes

# Answer
# 05AB1E, 4 bytes

```
AuA‡

```

Try it online! Beats all other answers.

```
AuA‡  # full program
   ‡  # replace all characters of...
A     # "abcdefghijklmnopqrstuvwxyz"...
 u    # in uppercase...
   ‡  # with corresponding character in...
  A   # "abcdefghijklmnopqrstuvwxyz"...
   ‡  # in...
      # implicit input
      # implicit output

```
> 1 votes

# Answer
# Vyxal, 24 bitsv1, 3 bytes

```
kAnĿ

```

Try it Online!

The power of context variable overloads and range coding! Simply transliterate the uppercase alphabet to the lowercase alphabet.
> 1 votes

# Answer
# Go, 89 bytes

```
package main
import(."fmt"
."strings")
func main(){s:=""
for{Scan(&s)
print(ToLower(s))}}

```
> 1 votes

# Answer
# Julia 1.x, 65 bytes

```
!s=print.(c+32('@'<c<'[') for c=read(s,String))
.!ARGS>[]||!stdin

```

Try it online! (stdin)

Try it online! (files)
> 1 votes

# Answer
# sed, 14 bytes

```
s/[A-Z]/\L\0/g

```

Run with `env -i sed -f kitten.sed`.
> 0 votes

# Answer
# Java, 198 bytes

```
b->B->{B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;};

```

You are forced to use the above lambda with files, so there's no need to take input from STDIN! Also, it's a `Function<File[], UnaryOperator<String>>`. It's used like `foo.apply(anArrayOfFiles).apply(anything)`.

As something that makes more sense to those who are new to Java, it takes 223 bytes:

```
String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}

```

As something that compiles, it takes up 232 bytes:

```
class a{String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}}

```
> 0 votes

# Answer
# Japt, 5 bytes

```
;dBíC

```

Try it

# Japt v2.0a0, 5 bytes

```
r\A_v

```

Try it
> 0 votes

---
Tags: code-golf, string, file-system
---


# Question
Title: Project Euler 1: Multiples in constant time
The purpose of this challenge is to solve the original first Project Euler problem, but as the title suggests in constant time (with respect to the size of the interval).

> Find the sum of all the multiples from a list of numbers in some defined range, in such a way that the running time of your program runs in constant time \[\\$\mathcal{O}(1)\\$\] with respect to the size of the range

Let us step through the problem statement with an handful of small examples.

---

**Example 1:** Let `[3,5]` be our list of numbers, and let our range be `[1, 999]` meaning every natural number starting with `1` up to and including `999`. To do this in linear time we can do as follows. The multiples of 3 and 5 are

$$ \begin{align\*} 3 + 6 + 9 + 12 + \color{red}{15}+18+\cdots+999=3(1+2+3+\cdots+333)=3\\,T\_{333}\\ 5 + 10 + \color{red}{15} + 20 + \cdots+995=5(1+2+3+\cdots+199)=5\\,T\_{199} \end{align\*} $$

Where \\$T\_{333}\\$ is the 333rd triangular number. \\$T\_n=n(n+1)/2\\$. However, simply adding \\$3T\_{333}\\$ and \\$5T\_{199}\\$, makes us *over count*. We will then count every number that is both a multiple of `3` and `5` (15, 30, 45...) twice. Thus, our final answer, *in constant time with respect to the input range* is

$$3T\_{333} + 5T\_{199}-15 T\_{66}$$

Where \\$66\\$ was chosen because it is the largest value such that \\$66\cdot15\<999\\$.

---

**Example 2:** Let `[6,9]` be our list of numbers, we might suspect that our answer will be

$$\text{Multiples of } 6 + \text{Multiples of } 9 - \text{Multiples of } 6 \cdot 9=54 $$

However this is leads to an error, as the first number counted in the multiples of \\$6\\$ and \\$9\\$ is \\$18\\$ *not* \\$54\\$. So

$$\text{Multiples of } 6 + \text{Multiples of } 9 - \text{Multiples of } 18 $$

gives the correct answer. Where, for instance, we could have done \\$\text{lcm}(6,9)=6\cdot9/\text{gcd}(6,9)=18\\$.

---

**Example 3:** Let `[3,5,7]` be our list of multiples, were we again is dropping the range for the sake of brevity. The easiest is now to use the inclusion-exclusion principle.

So our answer will be

$$ \begin{align} &\text{Multiples of } 3 + \text{Multiples of } 5 + \text{Multiples of } 7 \\ \- &\text{Multiples of lcm} (3,5) - \text{Multiples of lcm} (3, 7) - \text{Multiples of lcm} (5, 7) \\ + & \text{Multiples of lcm} (3, 5, 7) \end{align} $$

---

**Input**

A list of multiples (or divisors if you will), and a range. You may take input in any convenient method

**Output**

A single number/string/float ( representing the sum of every number divisible by at least one of the numbers in `multiples=[3,5,...]` in range `[start, stop]`)

---

**Restrictions and assumptions**

* **You *only* have to make sure your program runs in constant time with respect to the size of the range we are working over** How, you choose the handle the multiples/divisors is up to you
* The range is always assumed to be non-empty, with inclusive endpoints. Meaning `[10, 10]` contains `10`.
* We are working over the integers meaning every multiple and range will be whole non-negative numbers.

---

**Test cases**

Our test cases will be on the form `list of multiples`, `range`, `sum`.

```
[7]                  [1000,   1000]                0
[3, 5]               [1000,   1000]             1000
[3, 5]               [   1,    999]           233168
[3, 5, 7]            [ 300,    600]            73558
[9,10]               [   1,    999]            99504
[6, 9]               [   1,    999]           111390
[6, 9, 10, 5, 5, 9]  [ 1234,  4321]          3240486
[3, 5]               [10**7, 10**8] 2310000085000000

```

You may use the following code below to test your implementation, note that the implementation below does *not* run in constant time with respect to the input

```
def naive(multiples, start, stop):
    total = 0
    for num in range(start, stop + 1):
        for m in multiples:
            if num % m == 0:
                total += num
                break
    return total

```

This is so shortest code wins!

# Answer
> 9 votes
# Jelly, 20 bytes

```
+Ø.÷€AĊc2ḋIɓN;æl¥ƒ-Ḋ

```

Try it online!

Port of my own APL answer. Trailing `ɓ` chain trick is indeed strong :P

### How it works

```
+Ø.÷€AĊc2ḋIɓN;æl¥ƒ-Ḋ    Dyadic link; left=range, right=divisors
xxxxxxxxxxxɓyyyyyyyy    x(left, y(right, left))
            N;æl¥ƒ-Ḋ    y: subset LCMs, negative for even-sized ones
            N           Negate the divisors
                 ƒ-     Starting with -1, reduce by
             ;æl¥         current list ++ LCM(current list, next num)
                   Ḋ    Remove the leading -1
+Ø.÷€AĊc2ḋI    x: range(start, end), subset LCMs -> answer
+Ø.            Add 1 to the end
   ÷€AĊ        Divide each by subset LCMs, abs, ceil
       c2      nC2 of each
         ḋ     Dot product of each row with subset LCMs
          I    Increments (2nd - 1st)

```

# Answer
> 8 votes
# APL (Dyalog Extended), 31 bytes

```
-/+/(⎕+⍳2)(⊢×2!⌈⍤|⍤÷)\∊(⊢,∧)\-⎕

```

Try it online!

Full program which takes the list of divisors, and then the `(start,end)` pair. Uses a modified trick to generate all nonempty subsequences. Also abuses the definition of LCM which is `LCM(a,b) = a * b / GCD(a,b)` and GCD is always positive, so LCM follows the sign of `a * b`.

### How it works

```
-/+/(⎕+⍳2)(⊢×2!⌈⍤|⍤÷)\∊(⊢,∧)\-⎕    Input 1: divisors; input 2: range (start,end)
                      ∊(⊢,∧)\-⎕    LCMs of all nonempty subsets of divisors,
                                   negative if the subset has odd size
    (⎕+⍳2)                Add 1 to the right end of the range
          (         )\    Outer product:
               ⌈⍤|⍤÷      ceil(abs(left ÷ right))
           ⊢×2!           nC2 to each of above, times right
                          For each pair of (a,b), this evaluates the sum of
                          numbers in [1..a] divisible by b, following sign of b
-/+/    Sum of 1st row - sum of 2nd row
        (each value was negated because odd subsets should be added, not subtracted;
         the difference order fixes the negation)

```

# Answer
> 5 votes
# Python 3, 229 bytes

```
lambda d,s,e:sum(-(-1)**len(k)*(t(e//l(*k))-t(~-s//l(*k)))*l(*k)for k in p(d)[1:])
t=lambda x:x*-~x//2
p=lambda k:k and[j+a for j in[[],k[:1]]for a in p(k[1:])]or[[]]
l=lambda a,*b:b and a*l(*b)//math.gcd(a,l(*b))or a
import math

```

Try it online!

-5 bytes thanks to ovs

There's probably a less direct approach. I haven't properly golfed in Python in too long.

# Answer
> 5 votes
# Vyxal `s`, 32 bytes

```
$ṗḢƛ:λ₌*ġḭ;R:¹‹÷›"$ḭ:›*2ḭ¯unLe**

```

Try it Online!

# Answer
> 4 votes
# 05AB1E, 25 bytes

```
æ¦ε.¿DIāÉ-s÷D>*2÷Æ®ygmP}O

```

Try it online!

```
æ¦ε                     }  # map over each non-empty subset of the divisors
   .¿D                     #   take the LCM of the subset
      IāÉ-                 #   push the range with the lower bound decreased
          s÷               #   integer divide modified range by LCM
            D>*2÷          #   for both resulting integers, compute the nth triangular number
                 Æ         #   reduce by subtraction (results in negative values)
                   ®ygm*   #   multiply with LCM and (-1)**len(subset)
                         O # sum the resulting list

```

# Answer
> 3 votes
# Jelly,  ~~30~~  29 bytes

-1 thanks to caird coinheringaahing!

```
’1¦:×‘HIƲḢ×ʋⱮⱮœcⱮJæl/€€Ɗ}§Ṛḅ-

```

**Try it online!**

### How?

```
’1¦:×‘HIƲḢ×ʋⱮⱮœcⱮJæl/€€Ɗ}§Ṛḅ- - Link: [start, stop]; divisors
 1¦                           - apply to index 1 (of [start, stop]):
’                             -   decrement -> [start-1, stop]
                        }     - using right (divisors):
                       Ɗ      -   last three links as a monad - f(divisors):
                 J            -     range of length -> [1,2,...,#divisors]
                Ɱ             -     map with (for n in that):
              œc              -       all ways to choose n of the divisors
                      €       -     for each (list of choices of length n):
                     €        -       for each (way to choose):
                    /         -         reduce by:
                  æl          -           least common multiple
             Ɱ                - map across (for each list of LCMs):
            Ɱ                 -   map across (for each LCM):
           ʋ                  -     last four links as a dyad - f([start-1, stop],LCM):
   :                          -       integer divide -> [(start-1)//LCM, stop//LCM]
                                             call this "[A,B]"
        Ʋ                     -       last four links as a monad - f([A,B]):
     ‘                        -         increment -> [A+1,B+1]
    ×                         -         multiply -> [A(A+1),B(B+1)]
      H                       -         halve -> [A(A+1)/2,B(B+1)/2]
       I                      -         differences -> [B(B+1)/2-A(A+1)/2]
         Ḣ                    -       head -> B(B+1)/2-A(A+1)/2
          ×                   -       multiply -> LCM(B(B+1)/2-A(A+1)/2)
                         §    - sums -> [sum of single-choices, sum of two-choices, ...]
                          Ṛ   - reverse
                           ḅ- - convert from base -1 -> 1×(sum of single-choices)+-1×(sum of two-choices)+...

```

---

With fewer loops using the same approach, also 30 bytes:

```
Ḣ’;Ɗ:×‘HIƲḢ×ʋæl/}¥ⱮⱮœcⱮJ$}§Ṛḅ-

```

---

With no constraint on computational complexity, 7 bytes (-1 thanks to caird again!):

```
r/ọẸ¥ƇS

```

# Answer
> 3 votes
# , 72 69 bytes

```
1#.(_1*_1^1#.g)*(_1 0+[)(]*[:-~/(2!>:)@<.@%/)]*./@#~g=.1}.2#:@i.@^#@]

```

Try it online!

-3 thanks to nC2 trick from Bubbler's answer

There's some more golf's I believe I can port from Bubbler's APL answer. Will try tomorrow.

# Answer
> 3 votes
# Vyxal, 37 bytes

```
$ṗḢƛ:λ₌*ġḭ;R:¹÷$‹$"$ḭ:²+½$*÷-$Lu$e*;∑

```

Try it Online!

This is extremely messy. In case it wasn't clear, I am terrible with stack-based languages.

# Answer
> 2 votes
# Python 3, 146 bytes

```
lambda d,s,e:(e*e+e-s*s+s+g(d,e)-g(d,s-1))//2
g=lambda d,n,m=1:g(d[1:],n,m)-g(d[1:],n,m*d[0]//math.gcd(m,d[0]))if d else~n//m*(n//m)*m
import math

```

Try it online!

Some tricks explained: `~n//m` is a shorter way to write `-(n//m+1)`, and `e*e+e-s*s+s` is twice the sum of integers in the interval.

---

## Python 3.9, 138 bytes

```
lambda d,s,e:(e*e+e-s*s+s+g(d,e)-g(d,s-1))//2
g=lambda d,n,m=1:g(d[1:],n,m)-g(d[1:],n,math.lcm(m,d[0]))if d else~n//m*(n//m)*m
import math

```

Uses the new `math.lcm` in Python 3.9. No TIO link because Python 3.9 is not available there yet.

# Answer
> 0 votes
# Charcoal, 41 bytes

```
≔ΠθεＩΣＥＥε⁺×÷⁻⟦⊖ηζ⟧ιεει∧⊙θ¬﹪κλ÷×↨ι±¹⁺Σιε⊗ε

```

Try it online! Link is to verbose version of code. Explanation:

```
≔Πθε

```

Calculate the product of the divisors, as it gets used enough times that it saves a byte.

```
Ｅε⁺×÷⁻⟦⊖ηζ⟧ιεει

```

Map over the product, generating an adjusted half-open range of (first multiple below, last multiple not above\] for each possible remainder.

```
÷×↨ι±¹⁺Σιε⊗ε

```

Calculating the sum of the integers within the range with that remainder as (last - first) * (last + first + product) / (2 * product).

```
ＩΣＥ...∧⊙θ¬﹪κλ...

```

Map over the list of ranges, calculating the sums for those which are divisible by one of the divisors, and output the overall sum.

---
Tags: code-golf, number, number-theory, restricted-complexity
---


title: Distribute the additions!

text:
# Question
Title: Distribute the additions!
**Challenge**: Given an expressions made of additions and multiplications, output an expression that is a sum of products. The output must be equivalent to the input modulo the law of distribution. For example, \\$1 + ((2 + 5\times 6) \times(3+4))\\$ becomes \\$1 + 2 \times 3 + 2 \times 4 + 5\times6\times3 + 5 \times 6 \times 4 \\$. This is .

This task is useful in automatic theorem proving, since the conversion to *disjunctive normal forms* is exactly the same task. (Oops, that gives away a Mathematica builtin!)

**Clarifications**:

* You can assume the numbers are whatever you want, integers, floats, or even just strings of symbols, as long as it's convenient.
* You can use the law of distribution, commutativity and associativity of addition and multiplication. But you cannot use any other property of addition or multiplication. So e.g. \\$3 \times (1 + 3) \to 3 + 3 \times 3\\$ is not acceptable.
* This means that answers are not unique, the test cases are just a reference.
* Parentheses are optional, you won't need them anyway.
* You can assume any reasonable input form.

**Test cases**:

```
2 -> 2 (Corner case, you can ignore this.)
1+3 -> 1+3
1+(3*4) -> 1+3*4
1+3*4 -> 1+3*4
(1+3)*4 -> 1*4+3*4
(1+2+3)*(4+5+6) -> 1*4+2*4+3*4+1*5+2*5+3*5+1*6+2*6+3*6
(1+2*(3+4))*((5+6)*7)+8 -> 1*5*7+1*6*7+2*3*5*7+2*3*6*7+2*4*5*7+2*4*6*7+8

```

# Answer
# Haskell, 139 bytes

```
data M=I Int|M:*M|M:+M deriving(Show,Read)
f(x:*y)|z:+w<-f y=f(x:*z):+f(x:*w)|z:+w<-f x=f(z:*y):+f(w:*y)
f(x:+y)=f x:+f y
f x=x
show.f.read

```

Try it online!

## IO Format

Here our IO format uses the functions `:+` for addition and `:*` for multiplication. We also require that numbers themselves are prefixed with `I` , and that all parentheses be explicit.

So for example

```
2 * (3 * (1 + 2))

```

is

```
I 2 :* (I 3 :* (I 1 :+ I 2))

```

We uses this format because we are parsing into a native haskell data type defined on the first line. If I could operate on the data type directly the code would be a lot shorter:

# Haskell, 107 bytes

```
data M=I Int|M:*M|M:+M
f(x:*y)|z:+w<-f y=f(x:*z):+f(x:*w)|z:+w<-f x=f(z:*y):+f(w:*y)
f(x:+y)=f x:+f y
f x=x

```

Try it online!

Since this gets rid of all the parsing bits and just includes the manipulations.
> 3 votes

# Answer
# Python 3, 157 bytes

```
lambda e:"+".join(eval(re.sub("\d","A('\g<0>')",e)))
import re
class A(list):__mul__=lambda s,x:A(i+"*"+j for i in s for j in x);__add__=lambda s,x:A([*s]+x)

```

## How it works :

We define a new object named `A` with the wanted properties for addition and multiplication.

* each digit is stored as a list of string
* an expression like `1+2` is converted into `['1', '2']`
* an expression like `1*2` is converted into `['1*2']`
* the sum is equivalent to the python list addition
* the product is a double iteration over the 2 lists

Then we let python do the multiplication over addition priority

* `re.sub("\d","A('\g<0>')",e)` we convert all the digits in our expression into instances of this object
* `"+".join(eval(...))` we evaluate and formate the result

Try it online!
> 3 votes

# Answer
# Retina 0.8.2, 118 bytes

```
{`\(([\d*]+)\)
$1
\(([\d*]+)\+([^()]+\))(\*([\d*]+|\([^()]+\)))
$1$3+($2$3
([\d*]+\*)\(([\d*]+)\+([^()]+\))
$1$2+$1($3

```

Try it online! Link includes test cases. Explanation:

```
{`

```

Perform all possible reductions.

```
\(([\d*]+)\)
$1

```

`(a*b*...)` becomes `a*b*...`.

```
\(([\d*]+)\+([^()]+\))(\*([\d*]+|\([^()]+\)))
$1$3+($2$3

```

`(a*b*...+c*d*...+...)*f*g*...` becomes `a*b*...*f*g*...+(c*d*...+...)*f*g*`, where `f*g*...` could instead be `(f*g*...+h*i*...+...)`.

```
([\d*]+\*)\(([\d*]+)\+([^()]+\))
$1$2+$1($3

```

`a*b*...*(c*d*...+e*f*...+...)` becomes `a*b*...*c*d*...+a*b*...(e*f*...+...)`.
> 1 votes

---
Tags: code-golf, arithmetic, parsing
---