title: Print all 2 letter Scrabble Words

text:
# Question
Title: Print all 2 letter Scrabble Words
# The Challenge:

Print every 2 letter word acceptable in Scrabble using as few bytes as possible. I have created a text file list here. See also below. There are 101 words. No word starts with C or V. Creative, even if nonoptimal, solutions are encouraged.

```
AA
AB
AD
...
ZA

```

# Rules:

* The outputted words must be separated somehow.
* Case does not matter, but should be consistent.
* Trailing spaces and newlines are allowed. No other characters should be outputted.
* The program should not take any input. External resources (dictionaries) cannot be used.
* No standard loopholes.

Wordlist:

```
AA AB AD AE AG AH AI AL AM AN AR AS AT AW AX AY
BA BE BI BO BY
DE DO
ED EF EH EL EM EN ER ES ET EX
FA FE
GO
HA HE HI HM HO
ID IF IN IS IT
JO
KA KI
LA LI LO
MA ME MI MM MO MU MY
NA NE NO NU
OD OE OF OH OI OM ON OP OR OS OW OX OY
PA PE PI
QI
RE
SH SI SO
TA TI TO
UH UM UN UP US UT
WE WO
XI XU
YA YE YO
ZA

```

# Answer
# Python 3, ~~194~~ 188 bytes

```
s="BI ODEXIF BAAX ASOHER LOXUMOPAGOR KI US AMY BOITONOSI MMEMINANEHI UPI AYAHOYOWOMUNUHAID PEFARED QIS BEN JOFETAE KAT ABYESHMALI UTI ZADOELAWE "
while s:" "in s[:2]or print(s[:2]);s=s[1:]

```

Almost definitely not the shortest method, but I thought this would be a good start. Try to pack each pair into paths by overlapping as much as possible (e.g. `"ODEX..."` = `["OD", "DE", "EX", ...]`). Spaces are used to separate paths, and any pairs with a space in it is removed (the trailing space is to prevent a single `E` from being printed at the end).

I also tried regex golfing this but it was longer.
> 40 votes

# Answer
# CJam, ~~96~~ 94 bytes

```
0000000: 31 30 31 2c 22 5a 0a d0 fd 64 f6 07 a3 81 30 f2  101,"Z...d....0.
0000010: c2 a5 60 0c 59 0f 14 3c 01 dd d1 69 7d 66 47 6e  ..`.Y..<...i}fGn
0000020: db 54 e5 8f 85 97 de b9 79 11 35 34 21 cb 26 c3  .T......y.54!.&.
0000030: f0 36 41 2b b4 51 fb 98 48 fc cb 52 75 1f 1d b1  .6A+.Q..H..Ru...
0000040: 6b c3 0c d9 0f 22 32 36 30 62 33 36 62 66 7b 3c  k...."260b36bf{<
0000050: 31 62 32 35 6d 64 2d 35 35 7d 27 41 66 2b        1b25md-55}'Af+

```

The above is a hexdump, which can be reversed with `xxd -r -c 16 -g 1`.

Try it online in the CJam interpreter.

Depending on what exactly counts as *separated somehow*, the byte count could be lowered to **93** or even **92**:

* If we replace `-55` with `59`, the words will be separated by non-breaking spaces (0xA0).
* If we replace `-55` with `W`, the words will be separated by at-signs (0x40).

### Idea

We can encode each pair of letters **xy** as **(ord(x) - 65) × 25 + (ord(y) - 65)**.1

Instead of storing the resulting integers, we'll store the differences of all pairs that correspond to two adjacent words (sorted alphabetically).

The highest difference is **35**, so we consider them digits of a base **36** integer and convert that integer into a a byte string.

### Code

```
101,   e# Push [0 ... 100].
"…"    e# Push the string that encodes the differences/increments.
260b   e# Convert from base 260 to integer.
36b    e# Convert from integer to base 36 (array).
f{     e# For each I in [0 ... 100]:
       e#   Push the base 36 array.
  <    e#   Keep it's first I elements.
  1b   e#   Compute their sum.
  25md e#   Push quotient and residue of the sum's division by 25.
  -55  e#   Push -55 = '\n' - 'A'.
}      e#
'Af+   e# Add 'A' to all resulting integers. This casts to Character.

```

1 Since the second letter is never a **Z**, using **25** instead of **26** is enough.
> 28 votes

# Answer
## PHP 224, 218, 210 206

```
foreach(explode(",","I19SR,9ZY8H,,CNK,5JRU0,H,CN4,G0H,H160,CN4,75,CU9,AMIHD,MTQP,HQOXK,7L,74,G,CXS,CU9,HTOG,,CNK,MHA8,CNL,1")as$a){$b++;for($c=0;$c<26;$c++)echo base_convert($a,36,10)&pow(2,$c)?chr(96+$b).chr(97+$c)." ":"";}

```

```
aa ab ad ae ag ah ai al am an ar as at aw ax ay ba be bi bo by de do ed ef eh el em en er es et ex fa fe go ha he hi hm ho id if in is it jo ka ki la li lo ma me mi mm mo mu my na ne no nu od oe of oh oi om on op or os ow ox oy pa pe pi qi re sh si so ta ti to uh um un up us ut we wo xi xu ya ye yo za

```

---

Definitely not a great score, but I liked the challenge.

I create a table of the options, created a bitwise system to flag which options are valid.

Then I base-36 encoded those options to get the string:

```
"I19SR,9ZY8H,,CNK,5JRU0,H,CN4,G0H,H160,CN4,75,CU9,AMIHD,MTQP,HQOXK,7L,74,G,CXS,CU9,HTOG,,CNK,MHA8,CNL,1"

```

Note the 3rd entry in that string array doesn't have a value, because C has no options.

To print the values, I just convert the valid options to chars.

There might be something I could do to reduce recognising that there are no words ending in C, J, K, Q, V or Z, but I can't think of a method to reduce it atm.

---

By transposing the table, there are more empty elements and the data encodes a little more compactly which shaved off a few bytes. The array is now printed in a different order:

```
foreach(explode(",","UB1YB,1,,CUP,CLMEJ,CUO,1,SG0H,5J9MR,,,H,MX01,MTXT,CYO5M,MTQ8,,CNL,MTXT,MHAP,50268,,CN5,CNL,FSZ,,")as$a){$b++;for($c=0;$c<26;$c++)echo base_convert($a,36,10)&pow(2,$c)?chr(97+$c).chr(96+$b)." ":"";}

```

```
aa ba fa ha ka la ma na pa ta ya za ab ad ed id od ae be de fe he me ne oe pe re we ye ef if of ag ah eh oh sh uh ai bi hi ki li mi oi pi qi si ti xi al el am em hm mm om um an en in on un bo do go ho jo lo mo no so to wo yo op up ar er or as es is os us at et it ut mu nu xu aw ow ax ex ox ay by my oy

```

Thanks to Ismael for the explode and for loop hints.

```
foreach(explode(3,UB1YB3133CUP3CLMEJ3CUO313SG0H35J9MR333H3MX013MTXT3CYO5M3MTQ833CNL3MTXT3MHAP35026833CN53CNL3FSZ)as$d)for($e++,$f=0;$f<26;$f++)echo base_convert($d,36,10)&pow(2,$f)?chr(97+$f).chr(96+$e)." ":"";

```

---

With an update to php5.6, `pow(,)` can be replaced by `**` saving another 4 bytes.

```
foreach(explode(3,UB1YB3133CUP3CLMEJ3CUO313SG0H35J9MR333H3MX013MTXT3CYO5M3MTQ833CNL3MTXT3MHAP35026833CN53CNL3FSZ)as$d)for($e++,$f=0;$f<26;$f++)echo base_convert($d,36,10)&2**$f?chr(97+$f).chr(96+$e)." ":"";

```
> 16 votes

# Answer
# Ruby, 166 bytes

Borrowing sp3000's neat method for encoding the words into a compact string. The kicker here is the short method for decoding it back into the two-letter words: Using a lookahead in the regex passed to String's scan method in order to extract overlapping matches, not containg space:

```
puts "BI ODEXIF BAAX ASOHER LOXUMOPAGOR KI US AMY BOITONOSI MMEMINANEHI UPI AYAHOYOWOMUNUHAID PEFARED QIS BEN JOFETAE KAT ABYESHMALI UTI ZADOELAWE".scan /(?=(\w\w))/

```

# Ruby, 179 bytes

My own approach: Generate all two-letter words between `AA` and `ZA`, and select the valid ones using a base 36 encoded bitmask:

```
i=-1
puts ("AA".."ZA").select{|w|"djmsjr5pfw2omzrfgydo01w2cykswsrjaiwj9f2moklc7okcn4u2uxyjenr7o3ub90fk7ipdq16dyttg8qdxajdthd6i0dk8zlmn5cmdkczrg0xxk6lzie1i45mod7".to_i(36)[i+=1]>0}

```
> 9 votes

# Answer
# Perl, 167 164 157 bytes

```
"AMAEDOXUHALAXISHENUNUPABEFAHIDEMYESOHOSITAAGOYAYAWOWETOINODOREX KIFEHMMER BYONELI BOEMUS PELOMI UMOFAD BATAR KANAS JOPI UTI ZAI BI QI"=~/$_/&&say for AA..ZZ

```

Wrote a separate script to group the letters together as compact as possible into a string that contained all the valid 2 letter words. This then iterates over all of the two letter words and prints the valid ones, one per line. Run with `perl -M5.10.1 script.pl`.
> 9 votes

# Answer
# C,155 bytes

**Golfed version**

```
i,v;main(){for(;++i-408;" >b  Ùc :oÒ¹ i ;¹ w so@)ia ¥g¨¸ ´k¦ase    Ù{§k {"[i/8]>>i%8&1||printf("%c%c%c ",i/8%2*v,i/16+65,!(i/8%2)*v))v="YUOIEMHA"[i%8];}

```

**Output**

```
YA HA AA BY BO BI BE BA AB DO DE OD ID ED AD YE OE HE AE FE FA OF IF EF GO AG UH OH EH AH OI HI AI JO KI KA LO LI LA EL AL MY MU MO MI ME MM MA UM OM EM HM AM NU NO NE NA UN ON IN EN AN YO HO PI PE PA UP OP QI RE OR ER AR SO SI SH US OS IS ES AS TO TI TA UT IT ET AT WO WE OW AW XU XI OX EX AX OY AY ZA

```

**Ungolfed version**

The 51-byte magic string in the golfed version contains many characters beyond ASCII 126, which have almost certainly been mangled into Unicode equivalents. The ungolfed version uses hex instead, and as a constant rather than a literal. Also, the ungolfed version separates the words with a newline, which makes it easier to copy and paste into Excel, order the list and compare with the required one.

```
char a[]=
{0xFF,0x3E ,0x62,0x7F ,0xFF,0xFF ,0xEB,0x63 ,0xFF,0x3A ,0x6F,0xE3 ,0xFB,0x7F ,0xFF,0x69 ,0xFF,0x3B
,0xFB,0xFF ,0x77,0xFF ,0x73,0x6F ,0x40,0x29 ,0x69,0x61 ,0xFF,0xBE ,0x67,0xF9 ,0xF7,0xFF ,0xEF,0x6B
,0xB3,0x61 ,0x73,0x65 ,0xFF,0xFF ,0xFF,0xFF ,0xEB,0x7B ,0xF5,0x6B ,0xFF,0x7B ,0x7F};

//iterate through i = 16*letter + 8*order + vowel
i,v;main(){for(;i++-408;a[i/8]>>i%8&1||printf("%c%c%c\n",i/8%2*v,i/16+65,!(i/8%2)*v))v="YUOIEMHA"[i%8];}

```

**Explanation**

If we expand the definition of vowel to include the 8 letters AHMEIOUY, we observe that all words consist of one vowel and one other letter (which may or may not be a vowel.) Therefore, for all the words ending in a vowel, we need a table of 26 bytes, one for each first letter, with the individual bits corresponding to the vowel. We need a similar table for the words starting with a vowel, except that this time we only need 25 bytes, as there is no word ending in Z. The two tables are riffled together to create the final table.

In order to avoid any ASCII codes in the region 0..31, the two least common "vowels" M and H are assigned to the 6th and 7th bit, and the encoding considers 1 for an invalid word and 0 for a valid word. Since there is no consonant which pairs with both M and H it is possible to ensure at least one of these bits is a 1.

The 8th bit is assigned to A, which is the most common vowel, to try to limit the non-ASCII characters (still there are rather a lot of them.)

The tables used are below. For words containing 2 vowels, I gave priority to the first letter as being considered the "vowel" and the second letter as the "letter." An exception to this is words starting with M, as this avoids a clash between MM and HM.

Hex encoding of words starting with a vowel

```
3E 7F FF 63 3A E3 7F 69 3B FF FF 6F 29 61 BE F9 FF 6B 61 65 FF FF 7B 6B 7B

AA AB    AD AE    AG AH AI       AL AM AN          AR AS AT       AW AX AY
HA          HE          HI          HM    HO

         ED    EF    EH          EL EM EN          ER ES ET          EX
         ID    IF                      IN             IS IT
         OD OE OF    OH OI          OM ON     OP   OR OS          OW OX OY
                     UH             UM UN     UP       US UT
YA          YE                            YO

```

Hex encoding of words ending with a vowel

```
 A  H  M  E  I  O  U  Y
                         FF
BA       BE BI BO    BY  62
                         FF
         DE    DO        EB
                         FF
FA       FE              6F
               GO        FB
                         FF
                         FF
               JO        FB
KA          KI           77
LA          LI LO        73
MA    MM ME MI MO MU MY  40
NA       NE    NO NU     69
                         FF
PA       PE PI           67
            QI           F7
         RE              EF
    SH      SI  SO       B3
TA          TI  TO       73
                         FF
                         FF
         WE     WO       EB
            XI     XU    F5
                         FF
ZA                       7F

```
> 8 votes

# Answer
# Java, 484 448 407 391 389 bytes

My first try

```
public static void main(String[]a){int[]x={57569742,35784706,0,2099200,5534148,35651584,2048,35792896,5247168,2048,33685504,33687552,35794978,35653664,7746958,35782656,131072,2097152,395264,33687552,551296,0,2099200,131104,35653632,33554432};for(Integer i=0;i<26;i++){for(int z=0;z<26;z++){if("".format("%26s",i.toString(x[i],2)).charAt(z)=='1'){System.out.format("%c%c ",'A'+i,'A'+z);}}}}

```

Formatted:

```
public static void main(String[] a) {
    int[] x = { 57569742, 35784706, 0, 2099200, 5534148, 35651584, 2048, 35792896, 5247168, 2048, 33685504, 33687552, 35794978, 35653664,
            7746958, 35782656, 131072, 2097152, 395264, 33687552, 551296, 0, 2099200, 131104, 35653632, 33554432 };
    for (Integer i = 0; i < 26; i++) {
        for (int z = 0; z < 26; z++) {
            if ("".format("%26s", i.toString(x[i], 2)).charAt(z) == '1') {
                System.out.format("%c%c ", 'A' + i, 'A' + z);
            }
        }
    }
}

```

Try it online
> 7 votes

# Answer
# Malbolge, 2118 bytes

```
D'``_#>nI||38h6/vdtO*)_^mI7)"XWfB#z@Q=`<)\xwvuWm32ponmfN+ibJfe^$\[`Y}@VUySXQPUNSLpJINMLEiC+G@EDCB;_?>=}|492765.R210p(-,+*#G'&feB"baw=u]sxq7Xnsrkjoh.fNdchgf_%]\a`Y^W{>=YXWPOsSRQ3OHMLKJIBfF('C<`#"8=<;:3W1w5.R2+q/('&J$)"'~D$#"baw=utsxq7Xnsrkjoh.fNdchgf_%c\D`_X|\>=YXWPOsSRQ3OHMLKJIBfFEDC%$@9]=6|:32V6/.3210)M-m+$)"'&%|Bcb~w|u;yxwvuWm3kpinmfe+ihgfH%cb[ZY}]?UZYRWVOs65KPIHGkKJIH*)?c&BA@?8\6|:32V6/.3210)M-,lk)"F&feBzbxw=uzyrwpon4Ukpi/mfkdc)g`ed]#DZ_^]VzZ<;QPt7MLQPOHlFEJIHAe(>C<;_?>765:981Uv.32+*)Mnm%$)(!Efe{zy?}|{zyxqpo5mrkpoh.fNdihg`ed]#DZ_^]Vz=YRQuUTMqQ32NMLEDhHG@(>C<;_?>76;:3W76v43,+O/.nm+*)"Fgf${z@a}v{zyr8vo5Vrqj0nmfN+Lhg`_%cbDCY}@VUySRWPt76Lp3ONMLEDhHG@(>C<;_"8\6|:32V0v.Rs10/.'&+$H('&feB"!x>|^]srwvun4Ukpi/gfe+Lbaf_%cE[`Y}@?[TxRWPUNMLKo2NGFjD,BAeED&<A:^>=6|:32V6v.R21*/(L,+*#"!E}|{z@xw|{t:[qpotsrk1Rhmlkd*Kgfe^$bDZ_^]VzZ<;QuUTMqKJOHGkEJCBA@dD=<;:^>=6|:32V654t,+O).',+*#G'&feBzbx>|^]yr8vXnsrkjoh.fkdcbg`&^Fba`Y^WVzZ<XWPUTMqQ3INMFjD,BAe?>=B;_9>7<54X8765u-Q10)o'&J$)"!~%${A!x}v<]\xwpun4rTpoh.leMchgf_d]#DZ_^]VzZYR:Pt7SLKPOHlFEJIHAeED&<`@"87<5Y98165.3,P*/(-&+$H(!~}C#c!x}|u;\[wvun4lTjih.fN+Lbgfe^c\"CY}@VUyYXWPOsSRKJIHlLE-IBAeE'&<`@"87<5Y98165.3,Pq/.-,+*#G'&fe#"!x>|{zyr8Yotml2ponPlkdcb(fH%]\[`Y^W{zZ<XWPUTMq4JIHMLEi,BA@d>=B;:9]7};:3W7wv.3,+O)o'&J*)('g%${Ay~}v{zyrq7otmrqpoh.fejiha'eG]\[ZY}@VUy<;WVOsSRQPImM/KJIBAe(>=aA:^>=6|:32V65u-Qr0/.'K+$j"'~De#zy~wv<]yrqpo5srkjohg-kdib(feG]b[Z~^]\UTYRvP8TSRKJIHlLKD,BAe?>=B;_?>7<;:981U54t,+O)o'&Jkj('&}C#"bx>_{tyr8vuWVl2pihgle+ihgfH%cEDZ~XWVUy<XWPUTMqQP2NGLEiCBGF?>b%A@?87[;:zy1U54t210/.'K+$j"'~De#zy~wv<zyxwp6Wmlqpohg-kdib(feG]ba`Y^W{>=YXWPOs65KJIHl/KJIBA@dDCB;:9]=<;:zy1Uvu3,P0)o'&J$#(!~D|#"y?}v{zyr8vXnml2ponPledc)gfH%c\D`_^]VzZ<;QVOTSLpPIHGkKJCBG@dD=<;:^>=6|:32Vw543,+*N.nm+*)"F&feB"y~}|{ts9qvonsl2ponmfN+Lha`e^$\[Z_X|\UTYRQVOsM5KJOHGFjD,BA@d>=B;:9]=};4X81w5.R210)o'&J$j"'~%|{"y?w_u;y[wpun4Ukponmfe+Lha'eGc\[!B^WV[TxXQ9ONrRQ32NMLEDh+AeE'&<`#"8=<;:3W7wv.3,+O/.'m+*)(!EfeBcbx>_{tsxwvun4Ukpi/POkdcha'_d]#DZ_^]VzZ<RQPUNMqQ3ONGkE-IBAeED=BA:9]=<|43870/St,+O/.-ml*)(!Ef|Bcb~w|u;y[Zvun4rTpoh.fN+cKgf_%cE[!BXWV[ZSwWP8TSLpJIHMLEJIBf)d'=aA@">=<5Y98165.3,Pq)('K%*#"!EfeBcyxwvu;yxwvuWm3~

```

Try it online!
> 7 votes

# Answer
## Matlab, 177 bytes

Generate a binary matrix defining all allowed pairs of letters, reshape it and base-64 encode it. The base-64 encoded string (`'CR+ ... % '`) is used as data in the program. The program reverses operations to unpack the matrix, and then reads the allowed pairs:

```
x=de2bi('CR+"''        1$$ L*\"%$!! !   $!04P@<W(        0$   1"%$$100@RZP4  $$    0$ ! 1$$$$1 0  P (    $ 0 0$ ! # %  '-32)';[i,j]=find(reshape(x(1:650),26,[])');char([j i]+64)

```
> 6 votes

# Answer
*(Warning, this answer is not programmatically interesting)*

Since all words are two characters long, we can smash them all together and then rip them apart again using a simple regular expression.

Any regex-friendly language can do this, some more efficiently than others:

# Grep (via Bash), 215 bytes

```
grep -o ..<<<AAABADAEAGAHAIALAMANARASATAWAXAYBABEBIBOBYDEDOEDEFEHELEMENERESETEXFAFEGOHAHEHIHMHOIDIFINISITJOKAKILALILOMAMEMIMMMOMUMYNANENONUODOEOFOHOIOMONOPOROSOWOXOYPAPEPIQIRESHSISOTATIT

```

# Javascript, 224 bytes

```
alert("AAABADAEAGAHAIALAMANARASATAWAXAYBABEBIBOBYDEDOEDEFEHELEMENERESETEXFAFEGOHAHEHIHMHOIDIFINISITJOKAKILALILOMAMEMIMMMOMUMYNANENONUODOEOFOHOIOMONOPOROSOWOXOYPAPEPIQIRESHSISOTATITOUHUMUNUPUSUTWEWOXIXUYAYEYOZA".match(/../g))

```

# Perl, 225 bytes

```
 $_="AAABADAEAGAHAIALAMANARASATAWAXAYBABEBIBOBYDEDOEDEFEHELEMENERESETEXFAFEGOHAHEHIHMHOIDIFINISITJOKAKILALILOMAMEMIMMMOMUMYNANENONUODOEOFOHOIOMONOPOROSOWOXOYPAPEPIQIRESHSISOTATITOUHUMUNUPUSUTWEWOXIXUYAYEYOZA";s/../$&\n/g;print

```

# Python, 245 bytes

```
import re
print re.sub(r'..','\g<0>\n',"AAABADAEAGAHAIALAMANARASATAWAXAYBABEBIBOBYDEDOEDEFEHELEMENERESETEXFAFEGOHAHEHIHMHOIDIFINISITJOKAKILALILOMAMEMIMMMOMUMYNANENONUODOEOFOHOIOMONOPOROSOWOXOYPAPEPIQIRESHSISOTATITOUHUMUNUPUSUTWEWOXIXUYAYEYOZA")

```

---

As a note, some of the answers here are longer than `echo`, which I'd consider a baseline:

# POSIX shell, 307 bytes

```
echo AA AB AD AE AG AH AI AL AM AN AR AS AT AW AX AY BA BE BI BO BY DE DO ED EF EH EL EM EN ER ES ET EX FA FE GO HA HE HI HM HO ID IF IN IS IT JO KA KI LA LI LO MA ME MI MM MO MU MY NA NE NO NU OD OE OF OH OI OM ON OP OR OS OW OX OY PA PE PI QI RE SH SI SO TA TI TO UH UM UN UP US UT WE WO XI XU YA YE YO ZA

```
> 6 votes

# Answer
# Bash, 179 bytes

```
echo U`sed -r 's/./& &/g'<<<HAABADEDOEFAEHELAGOFEMAHINAISHMENERESITALOHOMMONOPAMUMYAWETOSOWOYOXUNUPEXI`F `grep -o ..<<<ANARASATAXAYBEBIBOBYJOKAKILIMIOIDOIDORPIQITIUSUTYEZA`

```
* Saved 7 bytes thanks to Adam Katz comment

It uses `sed` to do regex replacement. First regex input is based on Sp3000 idea while second regex uses common input without spaces.

Explanation:

```
echo              print to standard output the following
U                 boundary U character
sed -r [etc]      the result of replacing regex
    .             select a character
    & &           replace it for: matched char, space, matched char
    g             do it globaly for every character
    <<<HAAB[etc]  string input based on Sp3000 idea => HA AA AB ...
F                 boundary F character
sed -r [etc]      the result of replacing regex
    ..            every two characters
    <space>&      for space+matched character
    g             do it globally
    <<<ANAR       normal input => AN AR ...

```
> 5 votes

# Answer
# CJam, ~~100~~ 98 bytes

```
'A'@" ©Ô&ñ±ð¨9_AÚá¼thÁätÑû¨HÙH&J3p¼ÛèVçckùá%´}xà41"260bGb{_{+N2$2$}{;;)'@}?}%-3<

```

(permalink)

* Saved two bytes via preinitialized variables (thanks Dennis!)

This is my first CJam entry, so there is probably the potential for some more golfing. However, I came up with a way to compress the list of characters down to 63 bytes which, hopefully, someone else will find helpful.

## Compression Method

So far most methods that I saw encoded both letters of each word. However, when we put the words in alphabetical order, the first letter doesn't change very often, so it seems wasteful to encode it explicitly.

I encode only the last character of each word, and include a special item whenever the first character should increment. The characters are encoded as the first character, then a list of differences. Since there are no duplicate words, the differences must all be at least `1`. Thus I can use `0` as a separator item. (Note that I must then store the first letter of each subsequence as one-indexed, otherwise there would be confusion between 'rollover first character `0`' and 'start with A `0`'.)

Since the differences in this case are never greater than 15, we can use base-16 and pack two (4-bit) items into each (8-bit) byte. (In the actual code I converted from base-260 instead of base-256 to avoid issues with unprintable characters.)
> 4 votes

# Answer
# Zsh `--braceccl`, 163 bytes

```
s=(ABDEGHILMNRSTWXY AEIOY EO DFHLMNRSTX AE O AEIMO DFNST O AI AIO AEIMOUY AEOU DEFHIMNPRSWXY AEI I E HIO AIO HMNPST EO IU AEO A)
for c ({ABD-UW-Z})echo $c{$s[++i]}

```

Try it Online!

Previously: ~~169 bytes~~ , ~~175 bytes~~ , ~~182 bytes~~
> 4 votes

# Answer
# Python 3, 148 bytes

```
a=97
for n in b"!B$E'Hil-Nr3TWx9aEio9eodfHl-Nr3TxaEOaEi-odfN3TOaiaioaEi-ou9aEoudEfHi-N0r3Wx9aEiI%(ioaio(-N03TeoIuaEoa":a+=n%3;print("%c%c"%(a,n|96))

```

Try it online!

Prints lowercase.

The idea is to encode, for each of the 101 two-letter Scrabble words in order:

* Whether the first letter is 0, 1, or 2 positions higher than the previous word's (3 options)
* The second letter (26 options)

The 78 potential values fit easily in one byte per each entry `n`, and moreover within printable 7-bit ASCII.

The second letter is encoded in the last five bits, which lets the expression `96|n` set the first two bits to ones to get its lowercase ASCII value. The first letter delta (0, 1, or 2) could be encoded in the first two bits, but it's golfier to extract it as `n%3` by setting those two bits to whichever of `01`, `10`, or `11` gives the right value. Avoiding `00` let us avoid hitting unprintable characters in the range 0 to 31.

This answer uses 101 bytes for the hardcode data string and the other 47 bytes for extraction logic, so it's over 2/3 data. The data can surely be compressed further, but of course at a tradeoff to extraction.

Thanks to mousetail for posting a Python answer whose incremental-delta technique inspired this one.
> 4 votes

# Answer
# C#, 348 bytes

I had a go:

```
using System;class A{static void Main(){var a=new System.Collections.BitArray(Convert.FromBase64String("tnOciwgCCAAAAAggAFBxHIkAAAAACICIKABQQBgAAAIgIACAgCAAIqIgigCCADfWuIgAAAACAIAAAAAwCICAIAAAYRkAAAAAAggAgAAIIoAACA=="));int c, d;for(var i=0;i<652;i++){if(a[i]){c=Math.DivRem(i,26,out d);Console.Write("{0}{1} ",(char)('A' + c),(char)('@' + d));}}}}

```

Ungolfed:

```
using System;

class A
{
    static void Main()
    {
        var a = new System.Collections.BitArray(Convert.FromBase64String(
            "tnOciwgCCAAAAAggAFBxHIkAAAAACICIKABQQBgAAAIgIACAgCAAIqIgigCCADfWuIgAAAACAI" +
            "AAAAAwCICAIAAAYRkAAAAAAggAgAAIIoAACA=="));
        int c, d;
        for(var i = 0; i < 652; i++)
        {
            if(a[i])
            {
                c = Math.DivRem(i, 26, out d);
                Console.Write("{0}{1} ", (char)('A' + c), (char)('@' + d));
            }
        }
    }
}

```
> 3 votes

# Answer
# C - ~~228~~ 217 Bytes - GCC

```
 _;main(){char *z,*i="AABDEGHILMNRSTWXY AEIOY  EO DFHLMNRSTX AE O AEIMO DFNST O AI AIO AEIMOUY AEOU DEFHIMNPRSWXY AEI I E HIO AIO HMNPST  EOU IEO A A ";for(z=i;_++^26;)for(;*++z^32;putchar(_+64),putchar(*z),puts(""));}

```

Will update if I can get it smaller, just compile with gcc -w, ./a.out outputs perfectly. If there's any interest in an ungolfed, let me know.

I can't think of any way to shorten it off the top of my head, (you can technically remove the quotes in puts and you'll still get a correct answer, the output just looks like garbage) so please let me know of anyways to shorten it
> 3 votes

# Answer
# Pyth, 140 bytes

```
K"aeiou"=H+-G+K\zKL.[`Z25.Bib32jdSfTs.e.e?nZ`0+@Gk@HY""byMc"ljjns 1u  a 6jji0 o 2 100u 60hg0 2 k m 101v r 6hr7c s 4 8 g006 m hpg0  a 5 q g"d

```

Try it online!

Compression method: Since there's no `Z` in the second position of any word, use the reordered alphabet `bcdfghjklmnpqrstvwxyaeiou` to encode the validity of each of those letters as a second letter for each first letter (first letters are in alphabetical order).
This is 25 bits per letter, or exactly 5 Base-32 digits. Since most consonants only take vowels as the second letter, I put vowels at the end to get mostly 1-digit numbers for them. I'm sure it could overall be improved by further analysis and reordering of the alphabet, although then the definition of the reordered alphabet would take up more bytes.

## Explanation

```
K"aeiou"=H+-G+K\zK # Define the reordered alphabet
K"aeiou"           # K := "aeiou"
        =H         # H :=
           -G      #      G.removeAll(
             +K\z  #                   K + "z"
          +      K #                           ) + K

L.[`Z25.Bib32      # Define a lambda function for decompression
L                  # y = lambda b:
         ib32      # convert b to int using Base 32
       .B          # convert to binary string
 .[`Z25            # pad to the left with "0" to the nearest multiple of 25 in length

                           c"..."d # split the compressed string on " "
                         yM        # Apply y (above lambda) to each element
                                   #   Intermediate result: List of binary strings
                                   #   with 1s for allowed combinations
      .e                           # map over ^ lambda b (current element), k (current index):
        .e              b          # map over b: lambda Z (cur. elem.), Y (cur. ind.):
               +@Gk@HY             # G[k] + H[Y] (G is the regular alphabet)
          ?nZ`0       ""           #     if Z != "0" else ""
     s                             # combine into one large list
   fT                              # remove all falsy values (empty strings)
  S                                # sort (if any order is possible, remove this)
jd                                 # join on spaces (if a normal list with the words is
                                   #   allowed, remove this)

```
> 3 votes

# Answer
# Python, ~~174~~ 158 bytes

-16 bytes thanks to @xnor

```
a=0
for x in b"BCBCBBDBBEBBDBBDEEGKcKQCCEBBEBBEEEfNEEECQCIFBWNITIGNEEECGEDEKGKBBCBEBCCBEBBDEE\X_BGNIGUFBCDBhKVMHEKN_":print('%c%c'%(a//27+65,a%27+65));a+=x-65

```

Attempt This Online!

String encodes the difference between each successive word. To find the word we need to sum all the letters then divmod 27. I beleive this is the shortest python answer so far.
> 3 votes

# Answer
# Python 3, 169 bytes

```
p,a="z",96
for i in "abdeghilmnrstwxyaeioy!!eodfhlmnrstxae!oaeimodfnstoaiaioaeimouyaeoudefhimnprswxyaeiie!hioaiohmnpst!!eoiuaeoa":print((chr(a:=a+(i<=p))+i)*(i>"_"));p=i

```

My first code golf. Uses a list of the second letter for each combination alphabetically, and changes the first letter if the next character is smaller than the previous (new set of words). Exclamation points are added to break up sections where the next character would be larger than the previous and to skip C and V.
> 3 votes

# Answer
# Python 3, 224 bytes

```
s='';i=int("AQHU9HU1X0313T1J9OMYMZZSRFWLCYT3POSE06UGHXDZN6H5SQSZIFCE6VEB",36)
for c in range(26):
 b=i%6;i//=6;k=(1<<b)-1;j=i%(1<<k);i>>=k
 for d in 'AOIEHMUSTMNDFPYBCGJKLQRVWXZ':
  if j&1:s+=chr(c+65)+d+' '
  j>>=1
print s

```

Uses bit masks of variable length to encode which second letters exist for each possible first letter. The bit masks can be 0,1,3,7,15 or 31 bits long. Bits are mapped to letters with `for d in 'AOIEHMUSTMNDFPYBCGJKLQRVWXZ':`, earlier bits are used for more common letters so that the bit masks can be short in most cases (usually 3 or 7 bits since most consonants are only followed by one of 5 vowels or Y M or H). Unfortunately the code to decode it negates the savings compared to more simple methods (the original list is only 303 bytes).
> 2 votes

# Answer
**PHP: ~~211~~ ~~209~~ 204**

You have to turn warnings off, otherwise one will print in regards to the implicit creation of `$b`

```
for($a=65;$b<strlen($c="ABDEGHILMNRSTWXY!AEIOY!EO!DFHLMNRSTX!AE!O!AEIMO!DFNST!O!AI!AIO!AEIMOUY!AEOU!DEFHIMNPRSWXY!AEI!I!E!HIO!AIO!HMNPST!EO!IU!AEO!A");$b++)if($c[$b]!='!')echo chr($a).$c[$b].' ';else$a++;

```

Very fun. Early attempts were in the 250 range, but this is my slimmest yet.
> 2 votes

# Answer
## CJam (99 bytes)

This includes a few special characters, so it's safest to give a hexdump. (In particular, the character with value `0xa0`, corresponding to a non-breaking space, caused me quite a bit of trouble in setting up the online demo).

```
00000000  36 37 36 22 c4 b2 2d 51  3f 04 93 5c 64 6c 8d 6e  |676"..-Q?..\dl.n|
00000010  d7 f9 7d 97 29 aa 43 ef  04 41 12 e1 aa ce 12 4d  |..}.).C..A.....M|
00000020  05 f3 1c 2b 73 43 a0 f0  41 c0 a7 33 24 06 37 a3  |...+sC..A..3$.7.|
00000030  83 96 57 69 9b 91 c4 09  c3 93 e1 ed 05 3b 84 55  |..Wi.........;.U|
00000040  d9 26 fd 47 68 22 32 35  36 62 33 38 62 7b 31 24  |.&.Gh"256b38b{1$|
00000050  2b 7d 2f 5d 7b 32 36 62  28 3b 36 35 66 2b 3a 63  |+}/]{26b(;65f+:c|
00000060  4e 7d 2f                                          |N}/|
00000063

```

Online demo.

The approach is difference-encoding in base-26.
> 2 votes

# Answer
# Stax, 91 bytes

```
âG→æ£ilæα¿:√▒▓uøD¶[│█æä║¢v┼T↨σªΩ■&*φòb¡CÆ?ì▀┬6ù═╦±qBF!╘π╓╙'♣*ù&↕!£ä3±r⌡W-╓D╬☺╝ï╜²á5Æ÷§═ôφF;

```

Run and debug it

The only neat trick this answer uses is using the "," token to show a change in the first letter, rather than storing it for every word.

Thanks to recursive for the idea of using the m operator
> 2 votes

# Answer
# brainfuck, 1371 bytes

Quite golfable, but I didn't put too much effort into it.

```
>+[+[<]>>+<+]>[-<<+<+>>>]-[-[-<]>>+<]>-[-<<<<+>>>>]<<<<<<..>>.<<.>+.>.<<.>++.>.<
<.>+.>.<<.>++.>.<<.>+.>.<<.>+.>.<<.>+++.>.<<.>+.>.<<.>+.>.<<.>++++.>.<<.>+.>.<<.
>+.>.<<.>+++.>.<<.>+.>.<<.>+.>.<------------------------<+.>.>.<<.>++++.>.<<.>++
++.>.<<.>++++++.>.<<.>++++++++++.>.<--------------------<++.>.>.<<.>++++++++++.>
.<-----------<+.>.>.<<.>++.>.<<.>++.>.<<.>++++.>.<<.>+.>.<<.>+.>.<<.>++++.>.<<.>
+.>.<<.>+.>.<<.>++++.>.<-----------------------<+.>.>.<<.>++++.>.<<+.>++++++++++
.>.<--------------<+.>.>.<<.>++++.>.<<.>++++.>.<<.>++++.>.<<.>++.>.<-----------<
+.>.>.<<.>++.>.<<.>++++++++.>.<<.>+++++.>.<<.>+.>.<-----<+.>.>.<--------------<+
.>.>.<<.>++++++++.>.<--------<+.>.>.<<.>++++++++.>.<<.>+.>.<---------<+.>.>.<<.>
++++.>.<<.>++++.>.<<.>++++.>.<<.>++.>.<<.>++++++.>.<<.>++++.>.<-----------------
-------<+.>.>.<<.>++++.>.<<.>++++++++++.>.<<.>++++++.>.<-----------------<+.>.>.
<<.>+.>.<<.>+.>.<<.>++.>.<<.>+.>.<<.>++++.>.<<.>+.>.<<.>++.>.<<.>++.>.<<.>+.>.<<
.>++++.>.<<.>+.>.<<.>+.>.<------------------------<+.>.>.<<.>++++.>.<<.>++++.>.<
<+.>.>.<----<+.>.>.<<+.>+++.>.<<.>+.>.<<.>++++++.>.<--------------<+.>.>.<<.>+++
+++++.>.<<.>++++++.>.<-------<+.>.>.<<.>+++++.>.<<.>+.>.<<.>++.>.<<.>+++.>.<<.>+
.>.<---------------<++.>.>.<<.>++++++++++.>.<------<+.>.>.<<.>++++++++++++.>.<--
------------------<+.>.>.<<.>++++.>.<<.>++++++++++.>.<--------------<+.>.>.

```

Try it online!
> 2 votes

# Answer
# Vyxal, 78 bytes

```
kaf»⌐±ẋ∆ṡẊ⊍¬5=↔ε{→₇-¥Kkṡw¹ǔ„L²Fŀwɖ"≠₌Ǎ›ꜝ%ǐ[Q∑)fĠλ=WτṪṫ¨≤‹r≬|{gǔs⁼∵2»16τ0€v¦øA+

```

Try it Online!

This uses a strategy similar to the CJam answer of storing differences between the second letters and signalling a new first letter with a 0.

```
   »...»           # Large integer
        16τ        # Convert from base 16
           0€      # Split on zeroes
             v¦    # Take the cumulative sums of each list of numbers
               øA  # For each each number, get the nth letter
                 + # Prepend each of corresponding items of...
kaf                # The lowercase alphabet, as a list of characters

```
> 2 votes

# Answer
# Regenerate `-a`, 148 bytes

```
A[BDGHLMNRSTWXY]|E[DFHLMNRSTX]|I[DFNST]|O[DFHIMNPRSWXY]|U[HMNPST]|[ABFHK-NPTYZ]A|[ABDFHM-PRWY]E|[ABHKLMPQSTX]I|[BDGHJLMNSTWY]O|[BM]Y|[HM]M|[MNX]U|SH

```

Attempt This Online!

Or

```
BY|HM|SH|NU|XU|A[BDGHLMNRSTWXY]|E[DFHLMNRSTX]|I[DFNST]|M[MUY]|O[DFHIMNPRSWXY]|U[HMNPST]|[ABFHK-NPTYZ]A|[ABDFHM-PRWY]E|[ABHKLMPQSTX]I|[BDGHJLMNSTWY]O

```

Attempt This Online!

I'm under the impression this is close to optimal, but I plan on writing a program to verify / discover the shortest solution which uses only this strategy. What I have here is as far as I could manage by hand.

Not a full code breakdown but everything here is basically just

```
XY|X[YZ]|[XY]Z

XY             // print XY
  |            // then
   X[YZ]       // print XY and XZ
        |      // then
         [XY]Z // print XZ and YZ

```
> 2 votes

# Answer
# , ~~199~~ 198 bytes

*In 2018 six new two-letter words were added to the Official Scrabble Players' Dictionary: **DA, EW, GI, OK, PO, and TE**. This answer would have had 192 bytes in 2015 but I wanted to include the new words!*

```
`/`=strsplit;cat(unlist(Map(paste0,LETTERS[-22][-3],el('ABDEGHILMNRSTWXY,AEIOY,AEO,DFHLMNRSTWX,AE,IO,AEIMO,DFNST,O,AI,AIO,AEIMOUY,AEOU,DEFHIKMNPRSWXY,AEIO,I,E,HIO,AEIO,HMNPST,EOI,U,AEO,A'/',')/'')))

```

This answer is adapted from my answer at this related challenge about element names. First we overload the `/` operator with the `strsplit()` function. Then for the first letters of the words, we use the builtin `LETTERS` to get a vector of uppercase letters, removing elements 3 and 22 (C and V). For the second letters, we split a string by the `,` character to get a list of the second letters going with each first letter. Then we split it again by an empty string to get a list of vectors of individual characters. `Map()` is used to apply `paste0()` to the first elements of the first-letters vector and the second-letters list, then the second elements, etc. `unlist()` flattens and `cat()` prints without any quotes.

Attempt this online!
> 2 votes

# Answer
# Haskell, ~~333~~ ~~308~~ 298 bytes

Just for fun!

Evaluating `s` will print all of the words in a weird order - I used the fact that most combinations are vowel-consonant or vice versa, could probably optimize even more with custom character "classes", shortening the encoded matrix (here, `w` and `k`).

Does anybody know a shorter way to print strings without quotes and brackets than my monadic one? Type classes are even longer as far as I can tell.

Also, there might also be a shorter way of doing `p`'s job...

```
v="AEIOU"
c="BCDFGHJKLMNPQRSTVWXYZ"
w=[976693,321324,50188,945708,52768]
k=[15,0,10,3,8,15,8,5,13,31,27,7,4,2,12,13,0,10,20,11,1]
z a b x=[[c:[e]|(e,f)<-b#p d,f]|(c,d)<-a#x]
(#)=zip
p 0=[]
p n=((n`mod`2)>0):p(n`div`2)
s=mapM_ putStrLn$concat$z v c w++z c v k++[words"AA AE AI BY HM MM MY OE OI SH"]

```
> 1 votes

# Answer
# Haskell, 192 bytes

```
putStr$(\(a:b)->((a:).(:" "))=<<b)=<<words"AABDEGHILMNRSTWXY BAEIOY DEO EDFHLMNRSTX FAE GO HAEIMO IDFNST JO KAI LAIO MAEIMOUY NAEOU ODEFHIMNPRSWXY PAEI QI RE SHIO TAIO UHMNPST WEO XIU YAEO ZA"

```

For every space separated word in the string put the first letter in front of all other letters and add a space, e.g `SHIO` -\> `SH SI SO`.
> 1 votes

# Answer
## Java, 334 bytes

```
public class C{public static void main(String[]a){for(int i=0;i<26;i++){for(int j=0;j<26;j++){if(java.util.BitSet.valueOf(java.util.Base64.getDecoder().decode("2znORQQBBAAAAAQQAKg4jkQAAAAABEBEFAAoIAwAAAEQEABAQBAAEVEQRQBBgBtrXEQAAAABAEAAAAAYBEBAEACAsAwAAAAAAQQAQAAEEUAABA==")).get(i*26+j)){System.out.format("%c%c\n",'a'+i,'a'+j);}}}}}

```

Formatted:

```
public class Code {
    public static void main(String[] a) {
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                if (java.util.BitSet.valueOf(
                        java.util.Base64.getDecoder()
                            .decode("2znORQQBBAAAAAQQAKg4jkQAAAAABEBEFAAoIAwAAAEQEABAQBAAEVEQRQBBgBtrXEQAAAABAEAAAAAYBEBAEACAsAwAAAAAAQQAQAAEEUAABA=="))
                        .get(i * 26 + j)) {
                    System.out.format("%c%c\n", 'a' + i, 'a' + j);
                }
            }
        }
    }
}

```

Separately, I encoded the word list into a length 26x26=676 BitSet, converted it to a byte array, and then finally to Base 64. That string is hard-coded in this program, and the reverse procedure is used to reproduce the BitSet, and ultimately print out the list of words
> 1 votes

# Answer
## Java, 356 bytes

Uses the random number generator to get the words:

```
import java.util.Random;class X{public static void main(String[]a){int j,n,m=9,x;for(String u:"rgzza 2u2hh r2rxs qs5f fwiag 26i33y 2xqmje 5h94v 16ld2a 17buv 4zvdi 1elb3y 2t108q 5wne9 1mrbfe 1ih89 fh9ts r0gh".split(" ")){x=Integer.parseInt(u,36);Random r=new Random(x/2);j=m-=x%2;while(j-->0){n=r.nextInt(676);System.out.format(" %c%c",65+n/26,65+n%26);}}}}

```

Ungolfed:

```
import java.util.Random;
class X{
    public static void main(String[]a){
        int j,n,m=9,x;
        for(String u:"rgzza 2u2hh r2rxs qs5f fwiag 26i33y 2xqmje 5h94v 16ld2a 17buv 4zvdi 1elb3y 2t108q 5wne9 1mrbfe 1ih89 fh9ts r0gh".split(" ")){
            x=Integer.parseInt(u,36);
            Random r=new Random(x/2);
            j=m-=x%2;
            while(j-->0){
                n=r.nextInt(676);
                System.out.format(" %c%c",65+n/26,65+n%26);
            }
        }
    }
}

```

You can try it here: http://ideone.com/Qni32q
> 1 votes

# Answer
## Perl, 248 bytes

```
@v=split(//,"AEIOU");@s=split(' ',"ADEGIRSWX LSTX DFN EFIPRX HPST BHLMNTY DFHMNR ST DHMNSWY MN ZFKP WYPB KQXLHPMB LGJTB X");for(0..14){foreach $c(split(//,@s[$_])){$_<10?print @v[$_%5].$c." ":a;$_>4?print $c.@v[$_%5]." ":a;}}print "MM MY BY HM SH";

```

First time using perl (and first time golfing), so there's definitely room for improvement. Factored out the vowels and grouped the remaining letters based on how the resulting word was created - adding the vowel first, last, or both vowel first and last create a word on the list.
> 1 votes

# Answer
# Javascript (ES6), 214

Perhaps not the shortest way to do it, but definitely interesting.

```
_=>(i=0,[...'ABDEFGHILMNOPRSTUWXY'].map(z=>[...`ABFHKLMNPTYZ
A
AEIO
ABDFHMNOPRWY
EIO
A
AEOSU
ABHKLMOPQSTX
AE
AEHMOU
AEIOU
BDGHJLMNSTWY
OU
AEO
AEIOU
AEIU
MNX
AO
AEO
ABMO`.split`
`[i++]].map(g=>g+z).join` `).join`
`)

```

Loops through each letter in the first string, adding it onto each letter in the corresponding line of the second. This returns the words in order of their last letter, like so:

```
AA BA FA HA KA LA MA NA PA TA YA ZA
AB
AD ED ID OD
AE BE DE FE HE ME NE OE PE RE WE YE
EF IF OF
AG
AH EH OH SH UH
AI BI HI KI LI MI OI PI QI SI TI XI
AL EL
AM EM HM MM OM UM
AN EN IN ON UN
BO DO GO HO JO LO MO NO SO TO WO YO
OP UP
AR ER OR
AS ES IS OS US
AT ET IT UT
MU NU XU
AW OW
AX EX OX
AY BY MY OY

```

Suggestions welcome!
> 1 votes

# Answer
# Java, ~~255~~ 254 bytes

Found a way to squeeze one more byte out of it.

```
class C{public static void main(String[]a){char c='A';for(char l:"ABDEGHILMNRSTWXY AEIOY  EO DFHLMNRSTX AE O AEIMO DFNST O AI AIO AEIMOUY AEOU DEFHIMNPRSWXY AEI I E HIO AIO HMNPST  EO IU AEO A".toCharArray())if(l<'A')c++;else System.out.print(" "+c+l);}}

```

Or (though not much clearer):

```
class C {
    public static void main(String[] a) {
        char c = 'A';
        for (char l : "ABDEGHILMNRSTWXY AEIOY  EO DFHLMNRSTX AE O AEIMO DFNST O AI AIO AEIMOUY AEOU DEFHIMNPRSWXY AEI I E HIO AIO HMNPST  EO IU AEO A"
                .toCharArray())
            if (l < 'A')
                c++;
            else
                System.out.print(" " + c + l);
    }
}

```
> 1 votes

# Answer
# 05AB1E, 143 bytes

```
•ZÐFý8ù6„=4ÅœÿWì±7Ë5Œ¾`ó/îAnµ%Ñ¥Ëø±/ÀéNzÖ„Ñ§IJ¶D—ÙVEStvÖò…¸¾6F³#EXŠm¯CÄµ±ÓoÊ°}^€Ftåß€ðŒ=«j;F-Â1;xX3i&QZÒ'Ü”>lwìlOs>íÙVÇI)~î‰Hç²?Öd0È^ÝQ°•36B2ô»

```

Try it online!
> 1 votes

# Answer
# PHP, 170 bytes

shortest approach I could find so far ...

```
for(;$c=ABFHKLMNPTYZ1A2AEIO1ABDFHMNOPRWY1EIO1A1AEOSU1ABHKJMOPQSTX3AE1AEHMOU1AEIOU1BDGHJLMNSTWY1OU11AEO1AEIOU1AEIU1MNX2AO1AEO1ABMO[$i++];)$c<1?print$c.chr($k+65)._:$k+=$c;

```

**breakdown**

```
for(;$c=CHARACTERS[$i++];)  // loop $c through map
    $c<1                            // if $c is a letter (integer value < 1)
        ?print$c.chr($k+65)._           // print first letter, second letter, delimiter
        :$k+=$c                         // else increase second letter
    ;

```

---

**Note** The shortest bit-mapping version with printable ascii costs 190 bytes (113 bytes data+77 bytes decoding) using 6 bits=base 64, 174 bytes (97 data, 77 decoding) using 7 bits (base 128); possibly some more for escaping.

```
for(;$p<676;)                   // loop through combinations
    ord("MAPPING"[$p/6])-32>>$p%6&1     // test bit
        ?                                       // if set, do nothing
        :print chr($p/26+65).chr($p++%26+65)._; // if not, print combination+delimiter

```

Base 224 (using ascii 32..255) takes 87 bytes data (+ escaping); but I guess the decoding will cost more than 10 bytes extra.
Excluding C and V from the map would save 16/14/13 bytes on the data but cost a lot in decoding.
> 1 votes

# Answer
# Python 2, ~~202~~ 200 bytes

```
for s in'AABALIFEN KITOELOPE LAYAINUNEREMI AMANAHI MOHMYEX UPI UTAGOFAWOWETI BY OR BI ZAXI PAS BE AD AEDEHAT QI UMMUS JOIDONOSHOYOD BOMESISOXUHEF KAR'.split():
 for i in range(len(s)-1):print s[i:i+2]

```

Try it online!

Try to join up overlapping pairs; i.e. `ZAXI` encodes `ZA, AX, XI`. Looks like 140 bytes of encoded text is about the best possible with this approach.
> 1 votes

# Answer
# Python 3, 182 bytes

```
[print(f+l)for*F,l in'ABFHKLMNPTYZA AB AEIOD ABDFHMNOPRWYE EIOF AG AEOSUH ABHKLMOPQSTXI AEL AEHMOUM AEIOUN BDGHJLMNSTWYO OUP AEOR AEIOUS AEIUT MNXU AOW AEOX ABMOY'.split()for f in F]

```

Try it online!

This was briefly the shortest Python 3 solution :)

Each section of the magic string, e.g. `AEIOD`, encodes e.g. `AD ED ID OD`. (The last letter of the section should be combined with each other letter.)

Equivalent to:

```
for *FIRSTS, last in (
    'ABFHKLMNPTYZA AB AEIOD ABDFHMNOPRWYE EIOF AG AEOSUH ABHKLMOPQSTXI AEL AEHMOUM AEIOUN BDGHJLMNSTWYO OUP AEOR AEIOUS AEIUT MNXU AOW AEOX ABMOY'
    .split()
):
    for first in FIRSTS:
        print(first+last)

```
> 1 votes

# Answer
# F#, 205 bytes

```
Seq.iteri(fun i s->Seq.iter(printf"%c%c "((char)i+'A'))s;printfn"")("ABDEGHILMNRSTWXY AEIOY  EO DFHLMNRSTX AE O AEIMO DFNST O AI AIO AEIMOUY AEOU DEFHIMNPRSWXY AEI I E HIO AIO HMNPST  EO IU AEO A".Split())

```

Live version.
> 0 votes

# Answer
**scala, 223 bytes**

```
print(("AABDEGHILMNRSTWXY BAEIOY DEO EDFHLMNRSTX FAE GO HAEIMO IDFNST JO KAI LAIO MAEIMOUY NAEOU ODEFHIMNPRSWXY PAEI QI RE SHIO TAIO UHMNPST WEO XIU YAEO ZA".split(" ").flatMap(a=>a.tail.map(a(0).toString+_))).mkString(" "))

```

Not especially compact, but vaguely idiomatic .. eval with

```
scala -e '...'

```
> 0 votes

# Answer
# Python 239 bytes

```
import re;f=lambdax:''.join(re.findall('..',x));a,b='ABAHALAMANATAYDEDOEFEHEMENERHOISITMOMUNONUOSOWOY','AAADAEAGAIARASAWAXBEBIBOBYELESETEXFAGOHIHMIDIFINJOKAKILILOMIMMMYOEOFOIOPOROXPAPEPIQISHTOUHUPUSUTWEXIXUYEZA';print f(a),f(a[::-1]),f(b)

```

This is a bit long, but I've given it a try. I've counted all the patterns that also have the reversed counterparts. Ex) 'AB'/'BA' and so on.
> 0 votes

# Answer
# Java, 288

```
class E{public static void main(String[]a){a="ABDEGHILMNRSTWXY,AEIOY,,EO,DFHLMNRSTX,AE,O,AEIMO,DFNST,O,AI,AIO,AEIMOUY,AEOU,DEFHIMNPRSWXY,AEI,I,E,HIO,AIO,HMNPST,,EO,IU,AEO,A".split(",");for(int i=26,j;i-->0;)for(j=0;j<a[i].length();)System.out.println((char)('A'+i)+""+a[i].charAt(j++));}}

```

By just stringing together the second letters of each word (plus a delimiter), you just loop through while keeping track of the first. Not as fancy as the base-encoded versions, but much simpler and a good score for Java. Prints in order by descending-first-letter (`ZA YA YE YO XI XU`), one word per line.

With line breaks:

```
class E{
    public static void main(String[]a){
        a="ABDEGHILMNRSTWXY,AEIOY,,EO,DFHLMNRSTX,AE,O,AEIMO,DFNST,O,AI,AIO,AEIMOUY,AEOU,DEFHIMNPRSWXY,AEI,I,E,HIO,AIO,HMNPST,,EO,IU,AEO,A".split(",");
        for(int i=26,j;i-->0;)
            for(j=0;j<a[i].length();)
                System.out.println((char)('A'+i)+""+a[i].charAt(j++));
    }
}

```
> 0 votes

# Answer
## Python 3, 248 bytes

```
e=enumerate
[print(*(chr(x+65)+chr(j+65)+" "for j,i in e(bin(k)[2:])if int(i)))for x,k in e([30292443,16793873,0,16400,9320616,17,16384,20753,794664,16384,257,16641,17846545,1064977,29798840,273,256,16,16768,16641, 831616,0,16400,1048832,16401,1])]

```

The numbers were generated by an additional script
I'm sure that it can be optimized further
> 0 votes

# Answer
# Retina, 167 bytes

```

¶AABDEGHIcWXY¶BbOY¶DEaEDFHcX¶FAE¶GaHbMaIDFNST¶JaKAI¶LAIaMbMOUY¶NAEOU¶ODEFHIMNPRSWXY¶Pb¶QI¶RE¶SHIaTAIaUHMNPST¶WEaXIU¶YAEaZA
c
LMNRST
b
AEI
a
O¶
+`(¶(.)\S+)(\S)
$1 $2$3

```

Try it online!
> 0 votes

# Answer
# C# (Visual C# Interactive Compiler), 208 bytes

```
()=>"ABDEGHILMNRSTWXY,AEIOY,EO,DFHLMNRSTX,AE,O,AEIMO,DFNST,O,AI,AIO,AEIMOUY,AEOU,DEFHIMNPRSWXY,AEI,I,E,HIO,AIO,HMNPST,EO,IU,AEO,A".Split(',').SelectMany((x,y)=>x.Select(z=>""+"ABDEFGHIJKLMNOPQRSTUWXYZ"[y]+z))

```

Try it online!
> 0 votes

# Answer
# PHP, 187 bytes

```
for($n=A,$l=ABDEGHILMNRSTWXYAEIOY1EODFHLMNRSTXAEGOAEIMODFNS2TOAIAIOAEIMOUYAEOUDEFFHIMNPRSWXYAEI3IE4HIOAIOHMNPST5EOIUAEOA;$q=$l[$x++];){if($q<A)$n++;else{if($q<$p)$n++;$p=$q;echo"$n$q
";}}

```

Try it online!

Basically, the list is mostly just the second letters in the word list - I noticed in almost all cases, when incrementing the first letter, the second letter is before the one before it. For example going from AY to BA, A is before Y in the alphabet, and going from QI to RE, E is before I in the alphabet. In the very few cases where the second letter was the same or after the previous one, or to skip C and V, I put a number in the string so it knows to increment the first letter.
> 0 votes

# Answer
# C#, 161 bytes

```
w=>"aBFHKLMNPTYZeBDFHMNOPRWYiBHKLMOPQSTXmEHMOUhEOSUnEIOUsEIOUdEIOtEIUyBMOrEOxEOlEwObgoBDGHJLMNSTWYfEIOuMNXpOU".Select((x,i)=>x>90&&w!=(w=""+x)?i>80?"":"a"+w:x+w)

```

---

The string is every possible second letter (lowercase) followed by each of its valid first letters (uppercase).

Every time a lowercase letter is reached, var `w` is updated to store that letter, and return `""`. Each time an uppercase letter is reached, return that letter + `w`.

Additionally, `"a" + w` is automatically added every time a new lowercase letter is reached, unless that letter is one of f, o, p or u (this is achieved by putting these 4 at the end of the string and conditionally adding `"a"+w` based on index).

Try it online!
> 0 votes

# Answer
# JavaScript (V8), 182 bytes

```
"A ABFHKLMNPTYZB AD AEIOE ABDFHMNOPRWYG AH AEOSUI ABHKLMOPQSTXL AEM AEHMOUN AEIOUR AEOS AEIOUT AEIUW AOX AEOY ABMOO BDGHJLMNSTWYF EIOU MNXP OU".replace(/. ?/g,c=>c[1]?a=c:print(c+a))

```

Try it online!

Not that bad
> 0 votes

# Answer
# Python 2, 23+176 = 199 bytes

```
print('...'.decode('zip'))

```

Try it online!

Hexdump of the string in place of `...`:

```
['0x78', '0x9c', '0x0d', '0xc7', '0xd1', '0x8d', '0xc3', '0x30', '0x0c', '0x44',
 '0xc1', '0x56', '0x5e', '0x2b', '0x6b', '0x88', '0x8e', '0x78', '0x31', '0x45',
 '0x9f', '0x25', '0xc1', '0x56', '0xfa', '0x2f', '0x24', '0xf9', '0x19', '0x60',
 '0x24', '0xb4', '0xa1', '0x82', '0x0c', '0xbd', '0x50', '0x45', '0x8e', '0x0e',
 '0x14', '0xa8', '0xa1', '0x0b', '0x75', '0x34', '0xd0', '0x8d', '0x1e', '0xb4',
 '0xd8', '0xc4', '0x66', '0x6c', '0xce', '0x96', '0x6c', '0x8b', '0x62', '0x94',
 '0xc4', '0x0a', '0xb6', '0x63', '0x15', '0x3b', '0xb0', '0xc0', '0x1a', '0x76',
 '0x61', '0x1d', '0x1b', '0xd8', '0xc3', '0x2e', '0x76', '0xe3', '0x95', '0x54',
 '0x51', '0x8d', '0xea', '0xd4', '0xa0', '0x26', '0x5e', '0xf0', '0x1d', '0x6f',
 '0x78', '0xc7', '0x07', '0x7f', '0xc9', '0x5b', '0xbc', '0x9d', '0x43', '0x1c',
 '0x3f', '0x93', '0x10', '0x61', '0x84', '0x13', '0x41', '0xfc', '0x3a', '0x89',
 '0x45', '0x13', '0xcd', '0x68', '0x49', '0x9b', '0x64', '0x21', '0x8d', '0xdc',
 '0xc9', '0x4a', '0x3a', '0x19', '0x64', '0x23', '0x4f', '0xf2', '0x22', '0x3b',
 '0x79', '0x93', '0x0f', '0xb9', '0x38', '0xc5', '0x69', '0x9c', '0xce', '0xbf',
 '0x73', '0x19', '0xbd', '0xd2', '0x9d', '0x9e', '0x0c', '0x31', '0x9c', '0x91',
 '0xcc', '0xca', '0x0c', '0x66', '0x63', '0x9e', '0xcc', '0xce', '0x1c', '0xdc',
 '0xc6', '0x9d', '0x3c', '0xce', '0x33', '0x59', '0x62', '0x19', '0x2b', '0xf9',
 '0xe8', '0x0b', '0x93', '0x2f', '0x47', '0xe5']

```
> 0 votes

---
Tags: code-golf, kolmogorov-complexity, scrabble
---


title: Spell date in Japanese

text:
# Question
Title: Spell date in Japanese
# Objective

Given a date, spell it out in Romanized Japanese.

# I/O Format

The input format is flexible. The output format is `<month spelling> <day spelling>`; note the space. You can freely mix cases in output. You may output trailing newline.

# Mapping

## Months

| Month | Spelling |
| --- | --- |
| January | `Ichigatsu` |
| February | `Nigatsu` |
| March | `Sangatsu` |
| April | `Shigatsu` or `Yongatsu` |
| May | `Gogatsu` |
| June | `Rokugatsu` |
| July | `Shichigatsu` or `Nanagatsu` |
| August | `Hachigatsu` |
| September | `Kugatsu` or `Kyuugatsu` |
| October | `Juugatsu` |
| November | `Juuichigatsu` |
| December | `Juunigatsu` |

## Days

Irregular ones are marked \*.

| Day | Spelling |
| --- | --- |
| 1st | `Tsuitachi`* |
| 2nd | `Futsuka`* |
| 3rd | `Mikka`* |
| 4th | `Yokka`* |
| 5th | `Itsuka`* |
| 6th | `Muika`* |
| 7th | `Nanoka`* |
| 8th | `Youka`* |
| 9th | `Kokonoka`* |
| 10th | `Tooka`* |
| 11th | `Juuichinichi` |
| 12th | `Juuninichi` |
| 13th | `Juusannichi` |
| 14th | `Juuyokka`* |
| 15th | `Juugonichi` |
| 16th | `Juurokunichi` |
| 17th | `Juunananichi` |
| 18th | `Juuhachinichi` |
| 19th | `Juukyuunichi` |
| 20th | `Hatsuka`* |
| 21st | `Nijuuichinichi` |
| 22nd | `Nijuuninichi` |
| 23rd | `Nijuusannichi` |
| 24th | `Nijuuyokka`* |
| 25th | `Nijuugonichi` |
| 26th | `Nijuurokunichi` |
| 27th | `Nijuunananichi` |
| 28th | `Nijuuhachinichi` |
| 29th | `Nijuukyuunichi` |
| 30th | `Sanjuunichi` |
| 31st | `Sanjuuichinichi` |

# Examples

* May 5th → `Gogatsu Itsuka`
* September 29th → `Kugatsu Nijuukyuunichi` or `Kyuugatsu Nijuukyuunichi`
* October 9th → `Juugatsu Kokonoka`

# Answer
# Charcoal, 148 bytes

```
≔⪪”↶±UH fＸ>¡yüεω!Ln⎇$φＬ¹Kσ⎚FV” ζＮθＦ÷θχjuu§ζθgatsu Ｎη¿››ηχ⁼η²⁰«Ｆ÷η²⁰§ζ÷ηχjuu¿⁼⁴﹪ηχyokka⁺§ζηnichi»«§⪪”↶±‽″÷iπλº⊗wÞαα↓✳C⍘↔ω‖σ?Ｈê⦃¡ＢUQ(Ｕ}⊞▶↔⊙” ﹪η²⁰¿⊖ηka

```

Try it online! Link is to verbose version of code. Outputs in lower case. Explanation:

```
≔⪪”...” ζ

```

Get a list of the base names.

```
Ｎθ

```

Input the month number.

```
Ｆ÷θχjuu

```

Print "juu" if it is at least `10`.

```
§ζθgatsu

```

Output the rest of the month name.

```
Ｎη

```

Input the day number.

```
¿››ηχ⁼η²⁰«

```

If it's greater than `10` but not `20`...

```
Ｆ÷η²⁰§ζ÷ηχjuu

```

Output the tens part of the day.

```
¿⁼⁴﹪ηχyokka

```

Print "yokka" if the day ends in `4`, otherwise...

```
⁺§ζηnichi

```

... print the units part of the day.

```
»«§⪪”...” ﹪η²⁰¿⊖ηka

```

Otherwise, look up the root day and append "ka" unless the day is `1`.
> 3 votes

# Answer
# JavaScript (ES6), 236 bytes

Expects `(month)(day)` as integers in \\$\[1,12\]\\$ and \\$\[1,31\]\\$ respectively.

```
m=>d=>(a="/ichi/ni/san/shi/go/roku/nana/hachi/kyuu/futsu/mik/yok/itsu/mui/nano/you/kokono/too".split`/`,m>9?"juu":"")+a[m%10]+"gatsu "+(d<11?d-1?a[d+8]+"ka":"tsuitachi":d-20?a[d/10^d<20]+"juu"+(d%10-4?a[d%10]+"nichi":"yokka"):"hatsuka")

```

Try it online!

### Commented

```
m => d =>                  // m = month, d = day
(                          //
  a = (                    // a[] is a lookup array containing:
    "/ichi/ni/.../kyuu/" + //     0-9: regular prefixes for 0 to 9
    "futsu/mik/.../too"    //   10-18: irregular prefixes for 2nd to 10th
  ).split`/`,              //
  m > 9 ? "juu" : ""       // start with "juu" if m > 9
) +                        //
a[m % 10] +                // append the regular prefix for m
"gatsu " +                 // followed by "gatsu "
(                          //
  d < 11 ?                 // if d is less than 11:
    d - 1 ?                //   if d is not equal to 1:
      a[d + 8] +           //     append the irregular prefix for d
      "ka"                 //     followed by "ka"
    :                      //   else (d = 1):
      "tsuitachi"          //     "1st" is "tsuitachi"
  :                        // else (d > 10):
    d - 20 ?               //   if d is not equal to 20:
      a[d / 10 ^ d < 20] + //     according to the tens digit of d,
                           //     append either "" or "ni" or "san"
      "juu" +              //     followed by "juu"
      (                    //     followed by:
        d % 10 - 4 ?       //       if d mod 10 is not 4:
          a[d % 10] +      //         use the regular prefix for d
          "nichi"          //         followed by "nichi"
        :                  //       else:
          "yokka"          //         use the irregular "yokka"
      )                    //
    :                      //   else (d = 20):
      "hatsuka"            //     "20th" is "hatsuka"
)                          //

```
> 3 votes

# Answer
# Python 2, 238 bytes

Takes a month \\$ m \in \[1, 12\] \\$ and a day \\$ d \in \[1, 31\] \\$ as input, and outputs the Romaji in lowercase.

```
lambda m,d:m/10*'juu'+O[m%10]+'gatsu '+[O[~d%-20]+1%d*'ka',d/20*O[d/10]+'juu'+[O[d%10]+'nichi','yokka'][d%10==4]][20!=d>10]
O=',ichi,ni,san,shi,go,roku,nana,hachi,kyuu,too,kokono,you,nano,mui,itsu,yok,mik,futsu,tsuitachi,hatsu'.split(',')

```

Try it online!
> 3 votes

# Answer
# K (ngn/k), 273 bytes

```
g:m:$``ICHI`NI`SAN`SHI`GO`ROKU`SHICHI`HACHI`KU
d:($``TSUITACHI),($`FUTSU`MIK`YOK`ITSU`MUI`NANO`YOU`KOKONO`TOU`HATSU),\:$`KA
g:g,\:n:$`NICHI
g[4 7]:d[4 7]
g[7]:(-3_g[7]),"A",n
k:(-1_d),1_,/m[-1 2 3],/:\:"JYUU",/:g
k[20]:*|d
j:(,/($``JYUU),/:\:m;k)
f:"gatsu "/{(*x),_1_x}'j@'

```

Try it online!

I booted earlier versions. Thanks to @ngn for saving 5 bytes.
> 3 votes

# Answer
# Ruby, ~~255~~ 235 bytes

`%W()` declares a space-separated array of strings, which is useful for saving bytes over a `split` solution. An empty string interpolation `#{}` is needed to make the first element an empty string.

-3 bytes by incorporating dingledooper's array scheme for storing the special day cases.

```
->m,d{n=%W(#{} ichi ni san yon go roku nana hachi kyuu too kokono you nano mui itsu yok mik futsu tsuitachi hatsu)
'juu'*(m/10)+n[m%10]+"gatsu "+(d==20||d<11?n[~d%-20]+'ka'*(1%d):n[d/10]*(d/20)+'juu'+(d%10==4?'yokka':n[d%10]+'nichi'))}

```

Attempt This Online!
> 1 votes

# Answer
# ///, 293 bytes

```
/[1-/1@/
/[1/_1/
/[7/sh1/
/[4/shi/
/[9/ku/
/[//
/@/-/
/-/gatsu _/

/_1]/tsuitachi/
/_2]/futsuK/
/_3]/mikK/
/_4]/yokK/
/_5]/itsuK/
/_6]/muiK/
/_7]/nanoK/
/_8]/youK/
/_9]/kokonoK/
/_10]/tooK/
/_20]/hatsuK/

/_1/juu/
/_2/2_1/
/_3/3_1/

/4]/yokK/
/K/ka/
/]/n1/

/0//
/1/ichi/
/2/ni/
/3/san/
/5/go/
/6/roku/
/7/nana/
/8/hachi/
/9/kyuu/

```

Attempt This Online!

Newlines are added just for clarity and stripped before execution. Input is expected in `[M-D]` format and is appended at the end of the program since the language does not support any form of input.
> 1 votes

---
Tags: code-golf, date, natural-language
---


# Question
Title: Find the smallest positive integer which ends in n, is divisible by n and whose digits sum to n
# It's all in the title...

Take as input a positive integer `n>=12` and... do what the title says.

Yes, this is on OEIS A187924.

**Some test cases**

```
12 -> 912
13 -> 11713
14 -> 6314
15 -> 915
16 -> 3616
17 -> 15317
18 -> 918
19 -> 17119
20 -> 9920
40 -> 1999840
100-> 99999999999100

```

This is . Shortest code in bytes wins!

# Answer
> 20 votes
# Befunge, 81 bytes

```
&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

```

Try it online!

Can handle up to *n* = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of *n* greater than 99, which means we can more easily test if the value ends in *n* with by simply comparing the value modulo 100 with *n*.

Below is more detailed breakdown of the code.

Read *n* from stdin and save in memory.
Initialize the test value *v* to 0 and start the main loop, incrementing *v* up front.
Test if `v%n == 0`, and if not return to the start of the main loop.
Test if `v%100 == n`, and if not return to the start of the main loop.
Sum the digits in *v* by repeatedly adding *v* modulo 10 and dividing *v* by 10.
Test if the sum is equal to *n*, and if not return to the start of the main loop.
Otherwise output *v* and exit.

# Answer
> 13 votes
## JavaScript (ES6), ~~55~~ 54 bytes

```
f=(s,p=0,a=p+s)=>a%s|eval([...a].join`+`)-s?f(s,p+1):a
```

```
<input type=number min=12 oninput=o.textContent=f(this.value)><pre id=o>
```

Takes input as a string. Needs a browser with tail recursion support for the larger results. Edit: Saved 1 byte thanks to @Arnauld.

# Answer
> 12 votes
# 05AB1E, 14 bytes

```
[NI«ÐIÖsSOIQ*#

```

Try it online!

**Explanation**

Solutions requiring large prefixes will time out on TIO

```
[                # start a loop
 NI«             # append input to current iteration number
    Ð            # triplicate
     IÖ          # is the first copy evenly divisible by input?
       sSOIQ     # is the digit sum of the second copy equal to the input?
            *    # multiply
             #   # if true, break loop
                 # output the third copy

```

# Answer
> 8 votes
# Brachylog v2, ~~12~~ 10 bytes

```
a₁.;A×?≜ẹ+

```

Try it online!

This is a function submission that takes input via `.` and produces output via `?` (the opposite of the normal convention; all Brachylog functions have exactly two arguments, which can be input or output arguments, but the language doesn't enforce any particular argument usage). We don't normally consider conventions for argument usage to be relevant at PPCG.

## Explanation

A previous version of this solution had a special case (`Ḋ|`, i.e. "return digits literally") for single digits, but the question apparently states that you don't have to check for that (thanks @DLosc for catching this), so I removed it. (The solution as written won't work on single digits as Brachylog won't consider 1 as a possibility for an unknown in a multiplication, to prevent infinite loops; its multiplications are arbitrary-arity.)

So this answer now goes for a pretty much direct translation of the specification. Starting with `?` (the output / number we're trying to find; a Brachylog predicate always implicitly starts with `?`) we use `a₁.` to assert that it has `.` (the input) as a suffix. Then `;A×?` means that we can multiply (`×`) the result by something (`;A`) to produce `?` (the output). Finally, `ẹ+` sums (`+`) the digits () of `?`, and there's by default an implicit assertion at the end of every Brachylog program that the final result produces `.`. So in other words, this program is "`.` is a suffix of `?`, `.` multiplied by something is `?`, `.` is the digit sum of `?`", which is very close to a literal translation of the original program.

The  is necessary for the digit sum requirement to be enforced. I assume something about  doesn't like unknowns, so the  tells Brachylog to use a brute-force approach for that part of the program rather than algebra.

# Answer
> 6 votes
## Alice, 35 bytes

```
/o
\i@/!w?+.?~\ & /-$K..?\ L z $ /K

```

Try it online!

### Explanation

This program has a really nice mix and interaction between Cardinal (integer-processing) and Ordinal (string-processing) mode.

The usual framework for challenges with decimal I/O which operate largely in Cardinal mode:

```
/o
\i@/...

```

And the actual program:

```
!     Store the input N on the tape.
      We'll use an implicit zero on top of the stack as our iterator variable X,
      which searches for the first valid result.
w     Store the current IP position on the return address stack. This marks
      the beginning of the main search loop. We can avoid the divisibility
      test by going up in increments of N. To check the other two
      conditions, we'll use individual conditional loop ends that skip to
      the next iteration. Only if both checks pass and all loop ends are
      skipped will the search terminate.

  ?+    Increment the iterator X by N.
  .     Duplicate X.
  ?~    Put a copy of N underneath.
  \     Switch to Ordinal mode.
  &     Implicitly convert X to a string, then fold the next command over its
        characters, i.e. its digits. Here, "fold" means that each character
        is pushed to the stack in turn, followed by one execution of that
        next command.
  /     Switch back to Cardinal mode (this is not a command).
  -     Fold subtraction over the digits. This implicitly converts each
        digit back to its numerical value and subtracts it from N. If the
        digit sum of X is equal to N, this will result in 0.
  $K    Jump back to the w if the digit sum of X isn't N.
  ..    Duplicate X twice.
  ?     Get a copy of N.
  \     Switch to Ordinal mode.
  L     Shortest common superstring. Implicitly converts X and N to strings
        and gives the shortest string that starts with X and ends with N.
        This will be equal to X iff X already ends with N. Call this Y.
  z     Drop. If X contains Y, this deletes everything up to and including
        Y from X. This can only happen if they are equal, i.e. if X ended
        with N. Otherwise X remains unchanged.
  $     Skip the next command if the string is empty, i.e. if X ended with N.
  /     Switch back to Cardinal mode.
  K     Jump back to w if X didn't end with N.

```

# Answer
> 6 votes
# Haskell, 72 bytes

```
f n=[x|x<-[n,n+lcm n(10^length(show n))..],sum[read[j]|j<-show x]==n]!!0

```

Try it online!

Note that the found number minus n must be a multiple of both n and 10^length(n).

Inspired by Laikoni and totallyhuman

# Answer
> 5 votes
# Java (OpenJDK 8), ~~136~~ ~~110~~ ~~103~~ 92 bytes

*-26 thanks to JollyJoker*

*-7 again thanks to JollyJoker*

*-11 thanks to Oliver Grégoire*

```
a->{for(int i=a;!(""+a).endsWith(""+i)|i!=(""+a).chars().map(x->x-48).sum();a+=i);return a;}

```

Try it online!

Gotta love Java! It could well be that I am using an inefficient approach, but not having a built in checksum function and the double conversion to String to check for the end of the number costs bytes...

Ungolfed:

```
  a->{                                                       //input n (as integer)
      for (int i = a;                                        //initiate loop
           !("" + a).endsWith("" + i)                        //check if the calculated number ends with the input
           | i != ("" + a).chars().map(x -> x - 48).sum();   //check if the checksum is equal to the input
           a += i)                                           //for every iteration, increase i by the input to save checking for divisibility
        ;                                                    //empty loop body, as everything is calculated in the header
    return a;                                                //return number
}

```

# Answer
> 4 votes
# Mathematica, 72 bytes

```
(t=#;While[Mod[t,10^IntegerLength@#]!=#||Tr@IntegerDigits@t!=#,t+=#];t)&

```

*-18 bytes from @MartinEnder*

Try it online!

Here is another version from Martin Ender
This approach can go up to `n=40` (41 exceeds the default iteration limit)

# Mathematica, 65 bytes

```
#//.t_/;Mod[t,10^IntegerLength@#]!=#||Tr@IntegerDigits@t!=#:>t+#&

```

Try it online!

# Answer
> 4 votes
# Husk, ~~20 19~~ 17 bytes

```
ḟȯ=⁰Σdfȯ€d⁰ṫdm*⁰N

```

Thanks @Zgarb for -2 bytes!

Try it online!

# Answer
> 3 votes
# C (gcc) ~~71~~ 69 bytes , fails on 100

I tried with long and %1000 but times out

-2 bytes thanks to steadybox

```
s,i,j;f(n){for(j=0;s^n|j%100!=n;)for(s=0,i=j+=n;i;i/=10)s+=i%10;j=j;}

```

Try it online

# Answer
> 3 votes
# Python 2, 74 bytes

This solution assumes that `n <= sys.maxint`.

```
n=x=input()
while sum(map(int,str(x)))-n*str(x).endswith(`n`):x+=n
print x

```

**Try it online!**

# Answer
> 2 votes
# C# (.NET Core), 90 84 83 + 18 = 101 bytes

```
using System.Linq;
n=>{for(int i=n;!(""+n).EndsWith(""+i)|n%i>0|(""+n).Sum(c=>c-48)!=i;n++);return n;}

```

Try it online!

* 6 bytes saved thanks to Emigna and my uncanny ability to write `(""+n)` in some places and `n.ToString()` in others.

# Answer
> 2 votes
# Ohm v2, 16 bytes

```
£^›u³↔ξ³¥s}Σ³E*‽

```

Try it online!

# Answer
> 2 votes
# JavaScript REPL (ES5), ~~60~~ 59 bytes

```
for(n=prompt(i=0);eval([].join.call(t=++i+n,'+'))-n|t%n;);t

```

# Answer
> 2 votes
# Thunno 2, 12 bytes

```
ƘS=n$Ḋn$ø>&&

```

Try it online!

#### Explanation

```
ƘS=n$Ḋn$ø>&&  # Implicit input
Ƙ             # First positive integer where:
 S=           #  Digit sum equals input
   n$      &  #   AND
     Ḋ        #  Divisible by input
      n$  &   #   AND
        ø>    #  Ends with input
              # Implicit output

```

# Answer
> 1 votes
# Ruby, ~~65 63 54~~ 53 bytes

```
->n{a=n;a+=n until/#{n}$/=~a.to_s&&a.digits.sum==n;a}

```

Try it online!

# Answer
> 1 votes
# Julia, 70 bytes

```
f(x)=(n=x;while(sum(digits(n))!=x||x!=n%(10^length("$x")));n+=x;end;n)

```

# Answer
> 1 votes
# Pip, 18 bytes

```
T!y%a&$+y=aY++i.ay

```

Algorithm inspired by Emigna's answer. Try it online!

### How it works

```
                    a is 1st cmdline arg, i is 0, y is "" (implicit)
T                   Loop until
 !y%a&              y%a is 0 and
      $+y=a         sum of y is a:
            ++i      Increment i
           Y   .a    and yank (i concat a) into y
                 y  After the loop exits, autoprint y

```

# Answer
> 1 votes
## Scala, 120 bytes

```
def a(n:Int)={val b=math.pow(10,math.ceil(math.log10(n))).##;var c=b+n;while(c%n!=0||(0/:c.toString)(_+_-'0')!=n)c+=b;c}

```

This works until `n = 70`, after which integers overflow. For one extra character, the `Int` can change to a `Long` and allow values for `n > 100` to be computed.

Here is the slightly longer ungolfed version:

```
def golfSourceLong(n: Long): Long = {
  val delta = math.pow(10, math.ceil(math.log10(n))).toInt
  var current = delta + n
  while (current % n != 0 || current.toString.foldLeft(0)(_ + _ - '0') != n) {
    current += delta
  }
  current
}

```

# Answer
> 1 votes
# Python 2, 70 bytes

```
f=lambda n,x=0:x*(x%n<sum(map(int,`x`))==n==x%10**len(`n`))or f(n,x+n)

```

Try it online!

# Answer
> 1 votes
# Stax, 16 bytes

```
è}╘⌐ƒw┴L≤⌂IÑ═eαü

```

Run and debug it

# Answer
> 0 votes
# Haskell, 75 bytes

```
f n=[x|x<-[0,n..],sum[read[d]|d<-show x]==n,mod x(10^length(show n))==n]!!0

```

Try it online!

**Explanation:**

```
f n=[x|                                      ]!!0 -- Given input n, take the first x
       x<-[0,n..],                                -- which is a multiple of n,
                  sum[read[d]|d<-show x]==n,      -- has a digital sum of n
                  mod x(10^length(show n))==n     -- and ends in n.

```

I wonder whether the "ends in `n`" part can be shortened. I also tried `show n`elem`scanr(:)""(show x)`, but it's longer.

# Answer
> 0 votes
# Haskell, 75 bytes

```
f n=[i|i<-[n,n+10^length(show$n)..],i`mod`n<1,sum[read[j]|j<-show$i]==n]!!0

```

Try it online!

# Answer
> 0 votes
# Pyth,  ~~22~~  21 bytes

```
fq2-/,%T^;l`QsjT;Q%TQ

```

**Try it here!**

# Answer
> 0 votes
# Perl 5, ~~46~~ 44 + 1 ( -p ) = 45 bytes

2 bytes saved thanks to Xcali, couldn't find better

```
($\=++$t.$_)%$_|$_-eval$\=~s//+/gr.0&&redo}{

```

first answer

```
$\=++$x.$_;eval$\=~s//+/gr."-$_"|$\%$_&&redo}{

```

Try it online

# Answer
> 0 votes
# PowerShell, 84 bytes

```
for($n=$i=$args[0];$i%$n-or$i-notmatch"$n$"-or([char[]]"$i"-join'+'|iex)-$n){$i++}$i

```

Try it online!

Simple construction but lengthy commands. Times out on TIO for `n=100`, but if we explicitly set `i` to be close, it outputs correctly.

This is just a simple `for` loop that keeps going so long as any one of the conditions is true. The three conditions are 1) `$i%$n`, i.e., we have a remainder; 2) `$i-notmatch"$n$"`, i.e., it doesn't regex match the last couple of digits; and 3) `([char[]]"$i"-join'+'|iex)-$n`, i.e., the digits summed together is not equal to `$n` (here checked by simple subtraction, since nonzero values are truthy). Inside the loop we're simply incrementing `$i`.

Thus, if we don't have a remainder, the regex matches, and the numbers are equal, all three conditions are `$false` and we exit the loop. As a result, we just can leave `$i` on the pipeline, and output is implicit.

# Answer
> 0 votes
# PHP, 73+1 bytes

```
while(array_sum(str_split($i+=$n=$argn))-$n|$i%10**strlen($n)-$n);echo$i;

```

Run as pipe with `-R`.

loops `$i` through multiples of `<input>` until `sum_of_digits-<input>` and `tail_of_i-$n` are falsy; then prints `i`.

# Answer
> 0 votes
# m4, 210 bytes

```
define(d,define)d(i,ifelse)d(s,`i($1,,0,`eval(substr($1,0,1)+s(substr($1,1)))')')d(k,`r($1,eval($2+1))')d(r,`i(s($2),$1,i(regexp($2,$1$),-1,`k($1,$2)',i(eval($2%$1),0,$2,`k($1,$2)')),`k($1,$2)')')d(f,`r($1,1)')

```

Defines a macro `f` which computes the answer. It's a bit slow—unusably so—but I promise it works.

I thought m4 would be nice because it treats integers as strings by default, but this is pretty bad.

# Answer
> 0 votes
# , 115 bytes

```
function(n,d=nchar(n):1){while(sum(D<-F%/%10^((k=nchar(F)):1-1)%%10)-n|any(D[k-d+1]-n%/%10^(d-1)%%10)|F%%n)F=F+n
F}

```

Try it online!

Terrible R function. Increments `F` (starts at `0`) by `n` until a value is found that satisfies the required properties, which it then returns. The use of `any` on a `double` expression sends out a warning for each iteration of the loop, but does not affect the correctness.

Times out on TIO for large enough inputs (n=55 or higher) but should correctly compute the solution given enough time/space.

# Answer
> 0 votes
# Jelly, ~~22~~ 21 bytes

```
DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#

```

Try it online!

Edit: compressed to a single line

**Explanation**

```
DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#
                  ø1#  Evaluate the condition before this and increment a counter until it is met then output the counter
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

```

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the `¤` and I just couldn't get it to work. Looking at \[this\]\[1\] well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

# Answer
> 0 votes
Javascript, 224 bytes `function getNumber(x){if(x<12){return!1};const sumDigits=(x)=>x.toString().split('').map(Number).reduce((a,b)=>a+b,0);for(let i=2;i<9999;i++){if((x*i-x)%(Math.pow(10,x.toString().length))==0&&sumDigits(x*i)==x){return x*i}}}` Un-golf:

```
function getNumber(x){
 if (x<12) {return false};
 const sumDigits = (x) => x.toString().split('').map(Number).reduce((a,b)=>a+b, 0);
 for (let i=2; i<9999; i++){
  if((x*i-x)%(Math.pow(10, x.toString().length))==0 && sumDigits(x*i)==x){
   return x*i;
}
}
}
```

Usage: 1. getNumber(12) 2. getNumber(13) 3. ....

# Answer
> 0 votes
# , ~~37~~ 33 bytes

```
+^:(((=1#."."0)*:(e.".\.))":)^:_~

```

Try it online!

```
                                ~    A = N
+^:                          ^:_     while(...)A+=N; return A
   (                      ":)        A to string
   (((    "."0)          )  )        digits of A
   ((( 1#.    )          )  )        sum
   (((=       )          )  )        equals N
   ((            (e.".\.))  )        N is one of the suffixes of A-string
   ((          *:        )  )        not AND

```

Prepending the iteration counter is ~5 times faster but 5 bytes longer:

```
(]+[((=1#.,.&.":)<:|),~&.":)^:_&1,&":]

```

Try it online!

Incrementing by 100, **27 bytes**:

```
(]+100*(=1#.,.&.":)<:|)^:_~

```

Try it online!

# Answer
> 0 votes
# Vyxal, 89 bitsv2, 11.125 bytes

```
Þ∞vp:Ṡ?=*ꜝ‡?Ḋc

```

Try it Online!

## Explained

```
Þ∞vp:Ṡ?=*ꜝ‡?Ḋc
Þ∞vp            # Append the input to each and every positive integer.
    :Ṡ          # and push a copy of that with each number summed
      ?=        # does each copy equal the input
        *ꜝ      # Multiply the two lists and keep only truthy items
          ‡?Ḋc  # Find the first of that where the number is divisible by the input.

```

Created with the help of Luminespire.

---
Tags: code-golf, integer
---