# Question
Title: Display the result of doing 8 perfect shuffles of a deck of cards
## Explanation

A perfect shuffle is where a deck of cards is split exactly in half and the cards from each pile are alternately interleaved. The original bottom cards and the original top card must be preserved after a perfect shuffle.

After 8 perfect shuffles, a standard 52 card deck returns to its original order.

## Challenge

Write a program that displays the state of a deck of cards as it goes through 8 consecutive perfect shuffles. You may use any human-readable representation of a deck, provided that it displays the number and suit of each card in the deck in sequential order. It must display a representation of all of the cards, for all nine states.

This is **code golf**, so the shortest solution wins.

## Example Output

Here is an example output produced by this example implementation in Javascript

```
AS,AC,AD,AH,2S,2C,2D,2H,3S,3C,3D,3H,4S,4C,4D,4H,5S,5C,5D,5H,6S,6C,6D,6H,7S,7C,7D,7H,8S,8C,8D,8H,9S,9C,9D,9H,10S,10C,10D,10H,JS,JC,JD,JH,QS,QC,QD,QH,KS,KC,KD,KH
AS,7D,AC,7H,AD,8S,AH,8C,2S,8D,2C,8H,2D,9S,2H,9C,3S,9D,3C,9H,3D,10S,3H,10C,4S,10D,4C,10H,4D,JS,4H,JC,5S,JD,5C,JH,5D,QS,5H,QC,6S,QD,6C,QH,6D,KS,6H,KC,7S,KD,7C,KH
AS,4C,7D,10H,AC,4D,7H,JS,AD,4H,8S,JC,AH,5S,8C,JD,2S,5C,8D,JH,2C,5D,8H,QS,2D,5H,9S,QC,2H,6S,9C,QD,3S,6C,9D,QH,3C,6D,9H,KS,3D,6H,10S,KC,3H,7S,10C,KD,4S,7C,10D,KH
AS,9S,4C,QC,7D,2H,10H,6S,AC,9C,4D,QD,7H,3S,JS,6C,AD,9D,4H,QH,8S,3C,JC,6D,AH,9H,5S,KS,8C,3D,JD,6H,2S,10S,5C,KC,8D,3H,JH,7S,2C,10C,5D,KD,8H,4S,QS,7C,2D,10D,5H,KH
AS,5S,9S,KS,4C,8C,QC,3D,7D,JD,2H,6H,10H,2S,6S,10S,AC,5C,9C,KC,4D,8D,QD,3H,7H,JH,3S,7S,JS,2C,6C,10C,AD,5D,9D,KD,4H,8H,QH,4S,8S,QS,3C,7C,JC,2D,6D,10D,AH,5H,9H,KH
AS,3S,5S,7S,9S,JS,KS,2C,4C,6C,8C,10C,QC,AD,3D,5D,7D,9D,JD,KD,2H,4H,6H,8H,10H,QH,2S,4S,6S,8S,10S,QS,AC,3C,5C,7C,9C,JC,KC,2D,4D,6D,8D,10D,QD,AH,3H,5H,7H,9H,JH,KH
AS,2S,3S,4S,5S,6S,7S,8S,9S,10S,JS,QS,KS,AC,2C,3C,4C,5C,6C,7C,8C,9C,10C,JC,QC,KC,AD,2D,3D,4D,5D,6D,7D,8D,9D,10D,JD,QD,KD,AH,2H,3H,4H,5H,6H,7H,8H,9H,10H,JH,QH,KH
AS,AD,2S,2D,3S,3D,4S,4D,5S,5D,6S,6D,7S,7D,8S,8D,9S,9D,10S,10D,JS,JD,QS,QD,KS,KD,AC,AH,2C,2H,3C,3H,4C,4H,5C,5H,6C,6H,7C,7H,8C,8H,9C,9H,10C,10H,JC,JH,QC,QH,KC,KH
AS,AC,AD,AH,2S,2C,2D,2H,3S,3C,3D,3H,4S,4C,4D,4H,5S,5C,5D,5H,6S,6C,6D,6H,7S,7C,7D,7H,8S,8C,8D,8H,9S,9C,9D,9H,10S,10C,10D,10H,JS,JC,JD,JH,QS,QC,QD,QH,KS,KC,KD,KH

```

# Answer
## J, 66 65 54 52 50 47 43 characters

```
26({.,@,.}.)^:(i.9),{'A23456789TJQK';'SCDH'

```

Output:

```
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│AS│AC│AD│AH│2S│2C│2D│2H│3S│3C│3D│3H│4S│4C│4D│4H│5S│5C│5D│5H│6S│6C│6D│6H│7S│7C│7D│7H│8S│8C│8D│8H│9S│9C│9D│9H│TS│TC│TD│TH│JS│JC│JD│JH│QS│QC│QD│QH│KS│KC│KD│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│7D│AC│7H│AD│8S│AH│8C│2S│8D│2C│8H│2D│9S│2H│9C│3S│9D│3C│9H│3D│TS│3H│TC│4S│TD│4C│TH│4D│JS│4H│JC│5S│JD│5C│JH│5D│QS│5H│QC│6S│QD│6C│QH│6D│KS│6H│KC│7S│KD│7C│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│4C│7D│TH│AC│4D│7H│JS│AD│4H│8S│JC│AH│5S│8C│JD│2S│5C│8D│JH│2C│5D│8H│QS│2D│5H│9S│QC│2H│6S│9C│QD│3S│6C│9D│QH│3C│6D│9H│KS│3D│6H│TS│KC│3H│7S│TC│KD│4S│7C│TD│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│9S│4C│QC│7D│2H│TH│6S│AC│9C│4D│QD│7H│3S│JS│6C│AD│9D│4H│QH│8S│3C│JC│6D│AH│9H│5S│KS│8C│3D│JD│6H│2S│TS│5C│KC│8D│3H│JH│7S│2C│TC│5D│KD│8H│4S│QS│7C│2D│TD│5H│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│5S│9S│KS│4C│8C│QC│3D│7D│JD│2H│6H│TH│2S│6S│TS│AC│5C│9C│KC│4D│8D│QD│3H│7H│JH│3S│7S│JS│2C│6C│TC│AD│5D│9D│KD│4H│8H│QH│4S│8S│QS│3C│7C│JC│2D│6D│TD│AH│5H│9H│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│3S│5S│7S│9S│JS│KS│2C│4C│6C│8C│TC│QC│AD│3D│5D│7D│9D│JD│KD│2H│4H│6H│8H│TH│QH│2S│4S│6S│8S│TS│QS│AC│3C│5C│7C│9C│JC│KC│2D│4D│6D│8D│TD│QD│AH│3H│5H│7H│9H│JH│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│2S│3S│4S│5S│6S│7S│8S│9S│TS│JS│QS│KS│AC│2C│3C│4C│5C│6C│7C│8C│9C│TC│JC│QC│KC│AD│2D│3D│4D│5D│6D│7D│8D│9D│TD│JD│QD│KD│AH│2H│3H│4H│5H│6H│7H│8H│9H│TH│JH│QH│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│AD│2S│2D│3S│3D│4S│4D│5S│5D│6S│6D│7S│7D│8S│8D│9S│9D│TS│TD│JS│JD│QS│QD│KS│KD│AC│AH│2C│2H│3C│3H│4C│4H│5C│5H│6C│6H│7C│7H│8C│8H│9C│9H│TC│TH│JC│JH│QC│QH│KC│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│AC│AD│AH│2S│2C│2D│2H│3S│3C│3D│3H│4S│4C│4D│4H│5S│5C│5D│5H│6S│6C│6D│6H│7S│7C│7D│7H│8S│8C│8D│8H│9S│9C│9D│9H│TS│TC│TD│TH│JS│JC│JD│JH│QS│QC│QD│QH│KS│KC│KD│KH│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘

```

I'm being forced further and further into J's tutorials and reference manuals to stay ahead here. :-S
> 15 votes

# Answer
## Haskell, 103

```
m(a:s,b:t)=a:b:m(s,t);m _=[]
main=mapM_ putStrLn.take 9.iterate(m.splitAt 26)$take 13.enumFrom=<<""

```

Output:

```

```

---

Don't know if there are any UTF-8 problems around here, shouldn't... this is a hex dump of the program
```
0000000 286d 3a61 2c73 3a62 2974 613d 623a 6d3a
0000010 7328 742c 3b29 206d 3d5f 5d5b 6d0a 6961
0000020 3d6e 616d 4d70 205f 7570 5374 7274 6e4c
0000030 742e 6b61 2065 2e39 7469 7265 7461 2865
0000040 2e6d 7073 696c 4174 2074 3632 2429 6174
0000050 656b 3120 2e33 6e65 6d75 7246 6d6f 3c3d
0000060 223c 9ff0 a182 9ff0 9183 9ff0 8183 9ff0
0000070 b182 0a22
0000074

```

and of the first output line

```
0000000 9ff0 a182 9ff0 a282 9ff0 a382 9ff0 a482
0000010 9ff0 a582 9ff0 a682 9ff0 a782 9ff0 a882
0000020 9ff0 a982 9ff0 aa82 9ff0 ab82 9ff0 ac82
0000030 9ff0 ad82 9ff0 9183 9ff0 9283 9ff0 9383
0000040 9ff0 9483 9ff0 9583 9ff0 9683 9ff0 9783
0000050 9ff0 9883 9ff0 9983 9ff0 9a83 9ff0 9b83
0000060 9ff0 9c83 9ff0 9d83 9ff0 8183 9ff0 8283
0000070 9ff0 8383 9ff0 8483 9ff0 8583 9ff0 8683
0000080 9ff0 8783 9ff0 8883 9ff0 8983 9ff0 8a83
0000090 9ff0 8b83 9ff0 8c83 9ff0 8d83 9ff0 b182
00000a0 9ff0 b282 9ff0 b382 9ff0 b482 9ff0 b582
00000b0 9ff0 b682 9ff0 b782 9ff0 b882 9ff0 b982
00000c0 9ff0 ba82 9ff0 bb82 9ff0 bc82 9ff0 bd82
00000d0 000a
00000d1

```

(the unicode playing cards)
> 9 votes

# Answer
## Python 2, 79 chars

```
d=zip("23456789TJQKA"*4,"CDHS"*13)
exec'print d;d[::2],d[1::2]=d[:26],d[26:];'*9

```

The output is a bit ugly but I believe it should count.

```
[('2', 'C'), ('3', 'D'), ('4', 'H'), ('5', 'S'), ('6', 'C'), ('7', 'D'), ('8', 'H'), ('9', 'S'), ('T', 'C'), ('J', 'D'), ('Q', 'H'), ('K', 'S'), ('A', 'C'), ('2', 'D'), ('3', 'H'), ('4', 'S'), ('5', 'C'), ('6', 'D'), ('7', 'H'), ('8', 'S'), ('9', 'C'), ('T', 'D'), ('J', 'H'), ('Q', 'S'), ('K', 'C'), ('A', 'D'), ('2', 'H'), ('3', 'S'), ('4', 'C'), ('5', 'D'), ('6', 'H'), ('7', 'S'), ('8', 'C'), ('9', 'D'), ('T', 'H'), ('J', 'S'), ('Q', 'C'), ('K', 'D'), ('A', 'H'), ('2', 'S'), ('3', 'C'), ('4', 'D'), ('5', 'H'), ('6', 'S'), ('7', 'C'), ('8', 'D'), ('9', 'H'), ('T', 'S'), ('J', 'C'), ('Q', 'D'), ('K', 'H'), ('A', 'S')]
[('2', 'C'), ('2', 'H'), ('3', 'D'), ('3', 'S'), ('4', 'H'), ('4', 'C'), ('5', 'S'), ('5', 'D'), ('6', 'C'), ('6', 'H'), ('7', 'D'), ('7', 'S'), ('8', 'H'), ('8', 'C'), ('9', 'S'), ('9', 'D'), ('T', 'C'), ('T', 'H'), ('J', 'D'), ('J', 'S'), ('Q', 'H'), ('Q', 'C'), ('K', 'S'), ('K', 'D'), ('A', 'C'), ('A', 'H'), ('2', 'D'), ('2', 'S'), ('3', 'H'), ('3', 'C'), ('4', 'S'), ('4', 'D'), ('5', 'C'), ('5', 'H'), ('6', 'D'), ('6', 'S'), ('7', 'H'), ('7', 'C'), ('8', 'S'), ('8', 'D'), ('9', 'C'), ('9', 'H'), ('T', 'D'), ('T', 'S'), ('J', 'H'), ('J', 'C'), ('Q', 'S'), ('Q', 'D'), ('K', 'C'), ('K', 'H'), ('A', 'D'), ('A', 'S')]
[('2', 'C'), ('2', 'D'), ('2', 'H'), ('2', 'S'), ('3', 'D'), ('3', 'H'), ('3', 'S'), ('3', 'C'), ('4', 'H'), ('4', 'S'), ('4', 'C'), ('4', 'D'), ('5', 'S'), ('5', 'C'), ('5', 'D'), ('5', 'H'), ('6', 'C'), ('6', 'D'), ('6', 'H'), ('6', 'S'), ('7', 'D'), ('7', 'H'), ('7', 'S'), ('7', 'C'), ('8', 'H'), ('8', 'S'), ('8', 'C'), ('8', 'D'), ('9', 'S'), ('9', 'C'), ('9', 'D'), ('9', 'H'), ('T', 'C'), ('T', 'D'), ('T', 'H'), ('T', 'S'), ('J', 'D'), ('J', 'H'), ('J', 'S'), ('J', 'C'), ('Q', 'H'), ('Q', 'S'), ('Q', 'C'), ('Q', 'D'), ('K', 'S'), ('K', 'C'), ('K', 'D'), ('K', 'H'), ('A', 'C'), ('A', 'D'), ('A', 'H'), ('A', 'S')]
[('2', 'C'), ('8', 'C'), ('2', 'D'), ('8', 'D'), ('2', 'H'), ('9', 'S'), ('2', 'S'), ('9', 'C'), ('3', 'D'), ('9', 'D'), ('3', 'H'), ('9', 'H'), ('3', 'S'), ('T', 'C'), ('3', 'C'), ('T', 'D'), ('4', 'H'), ('T', 'H'), ('4', 'S'), ('T', 'S'), ('4', 'C'), ('J', 'D'), ('4', 'D'), ('J', 'H'), ('5', 'S'), ('J', 'S'), ('5', 'C'), ('J', 'C'), ('5', 'D'), ('Q', 'H'), ('5', 'H'), ('Q', 'S'), ('6', 'C'), ('Q', 'C'), ('6', 'D'), ('Q', 'D'), ('6', 'H'), ('K', 'S'), ('6', 'S'), ('K', 'C'), ('7', 'D'), ('K', 'D'), ('7', 'H'), ('K', 'H'), ('7', 'S'), ('A', 'C'), ('7', 'C'), ('A', 'D'), ('8', 'H'), ('A', 'H'), ('8', 'S'), ('A', 'S')]
[('2', 'C'), ('5', 'C'), ('8', 'C'), ('J', 'C'), ('2', 'D'), ('5', 'D'), ('8', 'D'), ('Q', 'H'), ('2', 'H'), ('5', 'H'), ('9', 'S'), ('Q', 'S'), ('2', 'S'), ('6', 'C'), ('9', 'C'), ('Q', 'C'), ('3', 'D'), ('6', 'D'), ('9', 'D'), ('Q', 'D'), ('3', 'H'), ('6', 'H'), ('9', 'H'), ('K', 'S'), ('3', 'S'), ('6', 'S'), ('T', 'C'), ('K', 'C'), ('3', 'C'), ('7', 'D'), ('T', 'D'), ('K', 'D'), ('4', 'H'), ('7', 'H'), ('T', 'H'), ('K', 'H'), ('4', 'S'), ('7', 'S'), ('T', 'S'), ('A', 'C'), ('4', 'C'), ('7', 'C'), ('J', 'D'), ('A', 'D'), ('4', 'D'), ('8', 'H'), ('J', 'H'), ('A', 'H'), ('5', 'S'), ('8', 'S'), ('J', 'S'), ('A', 'S')]
[('2', 'C'), ('T', 'C'), ('5', 'C'), ('K', 'C'), ('8', 'C'), ('3', 'C'), ('J', 'C'), ('7', 'D'), ('2', 'D'), ('T', 'D'), ('5', 'D'), ('K', 'D'), ('8', 'D'), ('4', 'H'), ('Q', 'H'), ('7', 'H'), ('2', 'H'), ('T', 'H'), ('5', 'H'), ('K', 'H'), ('9', 'S'), ('4', 'S'), ('Q', 'S'), ('7', 'S'), ('2', 'S'), ('T', 'S'), ('6', 'C'), ('A', 'C'), ('9', 'C'), ('4', 'C'), ('Q', 'C'), ('7', 'C'), ('3', 'D'), ('J', 'D'), ('6', 'D'), ('A', 'D'), ('9', 'D'), ('4', 'D'), ('Q', 'D'), ('8', 'H'), ('3', 'H'), ('J', 'H'), ('6', 'H'), ('A', 'H'), ('9', 'H'), ('5', 'S'), ('K', 'S'), ('8', 'S'), ('3', 'S'), ('J', 'S'), ('6', 'S'), ('A', 'S')]
[('2', 'C'), ('6', 'C'), ('T', 'C'), ('A', 'C'), ('5', 'C'), ('9', 'C'), ('K', 'C'), ('4', 'C'), ('8', 'C'), ('Q', 'C'), ('3', 'C'), ('7', 'C'), ('J', 'C'), ('3', 'D'), ('7', 'D'), ('J', 'D'), ('2', 'D'), ('6', 'D'), ('T', 'D'), ('A', 'D'), ('5', 'D'), ('9', 'D'), ('K', 'D'), ('4', 'D'), ('8', 'D'), ('Q', 'D'), ('4', 'H'), ('8', 'H'), ('Q', 'H'), ('3', 'H'), ('7', 'H'), ('J', 'H'), ('2', 'H'), ('6', 'H'), ('T', 'H'), ('A', 'H'), ('5', 'H'), ('9', 'H'), ('K', 'H'), ('5', 'S'), ('9', 'S'), ('K', 'S'), ('4', 'S'), ('8', 'S'), ('Q', 'S'), ('3', 'S'), ('7', 'S'), ('J', 'S'), ('2', 'S'), ('6', 'S'), ('T', 'S'), ('A', 'S')]
[('2', 'C'), ('4', 'H'), ('6', 'C'), ('8', 'H'), ('T', 'C'), ('Q', 'H'), ('A', 'C'), ('3', 'H'), ('5', 'C'), ('7', 'H'), ('9', 'C'), ('J', 'H'), ('K', 'C'), ('2', 'H'), ('4', 'C'), ('6', 'H'), ('8', 'C'), ('T', 'H'), ('Q', 'C'), ('A', 'H'), ('3', 'C'), ('5', 'H'), ('7', 'C'), ('9', 'H'), ('J', 'C'), ('K', 'H'), ('3', 'D'), ('5', 'S'), ('7', 'D'), ('9', 'S'), ('J', 'D'), ('K', 'S'), ('2', 'D'), ('4', 'S'), ('6', 'D'), ('8', 'S'), ('T', 'D'), ('Q', 'S'), ('A', 'D'), ('3', 'S'), ('5', 'D'), ('7', 'S'), ('9', 'D'), ('J', 'S'), ('K', 'D'), ('2', 'S'), ('4', 'D'), ('6', 'S'), ('8', 'D'), ('T', 'S'), ('Q', 'D'), ('A', 'S')]
[('2', 'C'), ('3', 'D'), ('4', 'H'), ('5', 'S'), ('6', 'C'), ('7', 'D'), ('8', 'H'), ('9', 'S'), ('T', 'C'), ('J', 'D'), ('Q', 'H'), ('K', 'S'), ('A', 'C'), ('2', 'D'), ('3', 'H'), ('4', 'S'), ('5', 'C'), ('6', 'D'), ('7', 'H'), ('8', 'S'), ('9', 'C'), ('T', 'D'), ('J', 'H'), ('Q', 'S'), ('K', 'C'), ('A', 'D'), ('2', 'H'), ('3', 'S'), ('4', 'C'), ('5', 'D'), ('6', 'H'), ('7', 'S'), ('8', 'C'), ('9', 'D'), ('T', 'H'), ('J', 'S'), ('Q', 'C'), ('K', 'D'), ('A', 'H'), ('2', 'S'), ('3', 'C'), ('4', 'D'), ('5', 'H'), ('6', 'S'), ('7', 'C'), ('8', 'D'), ('9', 'H'), ('T', 'S'), ('J', 'C'), ('Q', 'D'), ('K', 'H'), ('A', 'S')]

```
> 8 votes

# Answer
## Python2, 104

This is similar to Ev\_Genus's solution. I put suit before rank because it enables me to save a character.

```
d=[s+[r,`10`][r>"Q"]for r in'A23456789ZJQK'for s in"SCDH"]
exec'print d;d=sum(zip(d[:26],d[26:]),());'*9

```

**Output**

```
['SA', 'CA', 'DA', 'HA', 'S2', 'C2', 'D2', 'H2', 'S3', 'C3', 'D3', 'H3', 'S4', 'C4', 'D4', 'H4', 'S5', 'C5', 'D5', 'H5', 'S6', 'C6', 'D6', 'H6', 'S7', 'C7', 'D7', 'H7', 'S8', 'C8', 'D8', 'H8', 'S9', 'C9', 'D9', 'H9', 'S10', 'C10', 'D10', 'H10', 'SJ', 'CJ', 'DJ', 'HJ', 'SQ', 'CQ', 'DQ', 'HQ', 'SK', 'CK', 'DK', 'HK']
('SA', 'D7', 'CA', 'H7', 'DA', 'S8', 'HA', 'C8', 'S2', 'D8', 'C2', 'H8', 'D2', 'S9', 'H2', 'C9', 'S3', 'D9', 'C3', 'H9', 'D3', 'S10', 'H3', 'C10', 'S4', 'D10', 'C4', 'H10', 'D4', 'SJ', 'H4', 'CJ', 'S5', 'DJ', 'C5', 'HJ', 'D5', 'SQ', 'H5', 'CQ', 'S6', 'DQ', 'C6', 'HQ', 'D6', 'SK', 'H6', 'CK', 'S7', 'DK', 'C7', 'HK')
('SA', 'C4', 'D7', 'H10', 'CA', 'D4', 'H7', 'SJ', 'DA', 'H4', 'S8', 'CJ', 'HA', 'S5', 'C8', 'DJ', 'S2', 'C5', 'D8', 'HJ', 'C2', 'D5', 'H8', 'SQ', 'D2', 'H5', 'S9', 'CQ', 'H2', 'S6', 'C9', 'DQ', 'S3', 'C6', 'D9', 'HQ', 'C3', 'D6', 'H9', 'SK', 'D3', 'H6', 'S10', 'CK', 'H3', 'S7', 'C10', 'DK', 'S4', 'C7', 'D10', 'HK')
('SA', 'S9', 'C4', 'CQ', 'D7', 'H2', 'H10', 'S6', 'CA', 'C9', 'D4', 'DQ', 'H7', 'S3', 'SJ', 'C6', 'DA', 'D9', 'H4', 'HQ', 'S8', 'C3', 'CJ', 'D6', 'HA', 'H9', 'S5', 'SK', 'C8', 'D3', 'DJ', 'H6', 'S2', 'S10', 'C5', 'CK', 'D8', 'H3', 'HJ', 'S7', 'C2', 'C10', 'D5', 'DK', 'H8', 'S4', 'SQ', 'C7', 'D2', 'D10', 'H5', 'HK')
('SA', 'S5', 'S9', 'SK', 'C4', 'C8', 'CQ', 'D3', 'D7', 'DJ', 'H2', 'H6', 'H10', 'S2', 'S6', 'S10', 'CA', 'C5', 'C9', 'CK', 'D4', 'D8', 'DQ', 'H3', 'H7', 'HJ', 'S3', 'S7', 'SJ', 'C2', 'C6', 'C10', 'DA', 'D5', 'D9', 'DK', 'H4', 'H8', 'HQ', 'S4', 'S8', 'SQ', 'C3', 'C7', 'CJ', 'D2', 'D6', 'D10', 'HA', 'H5', 'H9', 'HK')
('SA', 'S3', 'S5', 'S7', 'S9', 'SJ', 'SK', 'C2', 'C4', 'C6', 'C8', 'C10', 'CQ', 'DA', 'D3', 'D5', 'D7', 'D9', 'DJ', 'DK', 'H2', 'H4', 'H6', 'H8', 'H10', 'HQ', 'S2', 'S4', 'S6', 'S8', 'S10', 'SQ', 'CA', 'C3', 'C5', 'C7', 'C9', 'CJ', 'CK', 'D2', 'D4', 'D6', 'D8', 'D10', 'DQ', 'HA', 'H3', 'H5', 'H7', 'H9', 'HJ', 'HK')
('SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'SJ', 'SQ', 'SK', 'CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'CJ', 'CQ', 'CK', 'DA', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'DJ', 'DQ', 'DK', 'HA', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'HJ', 'HQ', 'HK')
('SA', 'DA', 'S2', 'D2', 'S3', 'D3', 'S4', 'D4', 'S5', 'D5', 'S6', 'D6', 'S7', 'D7', 'S8', 'D8', 'S9', 'D9', 'S10', 'D10', 'SJ', 'DJ', 'SQ', 'DQ', 'SK', 'DK', 'CA', 'HA', 'C2', 'H2', 'C3', 'H3', 'C4', 'H4', 'C5', 'H5', 'C6', 'H6', 'C7', 'H7', 'C8', 'H8', 'C9', 'H9', 'C10', 'H10', 'CJ', 'HJ', 'CQ', 'HQ', 'CK', 'HK')
('SA', 'CA', 'DA', 'HA', 'S2', 'C2', 'D2', 'H2', 'S3', 'C3', 'D3', 'H3', 'S4', 'C4', 'D4', 'H4', 'S5', 'C5', 'D5', 'H5', 'S6', 'C6', 'D6', 'H6', 'S7', 'C7', 'D7', 'H7', 'S8', 'C8', 'D8', 'H8', 'S9', 'C9', 'D9', 'H9', 'S10', 'C10', 'D10', 'H10', 'SJ', 'CJ', 'DJ', 'HJ', 'SQ', 'CQ', 'DQ', 'HQ', 'SK', 'CK', 'DK', 'HK')

```
> 6 votes

# Answer
## APL (42)

```
{↑{⍉2 26⍴⍵}⍣⍵,'A23456789TJQK'∘.,'SCDH'}¨⍳9

```

Output is top-down instead of left-right (but it's still human readable so I guess it's not against the rules).

Output:

```
 AS  AS  AS  AS  AS  AS  AS  AS  AS
 7D  4C  9S  5S  3S  2S  AD  AC  7D

 AC  7D  4C  9S  5S  3S  2S  AD  AC
 7H  TH  QC  KS  7S  4S  2D  AH  7H

 AD  AC  7D  4C  9S  5S  3S  2S  AD
 8S  4D  2H  8C  JS  6S  3D  2C  8S

 AH  7H  TH  QC  KS  7S  4S  2D  AH
 8C  JS  6S  3D  2C  8S  4D  2H  8C

 2S  AD  AC  7D  4C  9S  5S  3S  2S
 8D  4H  9C  JD  6C  TS  5D  3C  8D

 2C  8S  4D  2H  8C  JS  6S  3D  2C
 8H  JC  QD  6H  TC  QS  6D  3H  8H

 2D  AH  7H  TH  QC  KS  7S  4S  2D
 9S  5S  3S  2S  AD  AC  7D  4C  9S

 2H  8C  JS  6S  3D  2C  8S  4D  2H
 9C  JD  6C  TS  5D  3C  8D  4H  9C

 3S  2S  AD  AC  7D  4C  9S  5S  3S
 9D  5C  9D  5C  9D  5C  9D  5C  9D

 3C  8D  4H  9C  JD  6C  TS  5D  3C
 9H  JH  QH  KC  KD  7C  TD  5H  9H

 3D  2C  8S  4D  2H  8C  JS  6S  3D
 TS  5D  3C  8D  4H  9C  JD  6C  TS

 3H  8H  JC  QD  6H  TC  QS  6D  3H
 TC  QS  6D  3H  8H  JC  QD  6H  TC

 4S  2D  AH  7H  TH  QC  KS  7S  4S
 TD  5H  9H  JH  QH  KC  KD  7C  TD

 4C  9S  5S  3S  2S  AD  AC  7D  4C
 TH  QC  KS  7S  4S  2D  AH  7H  TH

 4D  2H  8C  JS  6S  3D  2C  8S  4D
 JS  6S  3D  2C  8S  4D  2H  8C  JS

 4H  9C  JD  6C  TS  5D  3C  8D  4H
 JC  QD  6H  TC  QS  6D  3H  8H  JC

 5S  3S  2S  AD  AC  7D  4C  9S  5S
 JD  6C  TS  5D  3C  8D  4H  9C  JD

 5C  9D  5C  9D  5C  9D  5C  9D  5C
 JH  QH  KC  KD  7C  TD  5H  9H  JH

 5D  3C  8D  4H  9C  JD  6C  TS  5D
 QS  6D  3H  8H  JC  QD  6H  TC  QS

 5H  9H  JH  QH  KC  KD  7C  TD  5H
 QC  KS  7S  4S  2D  AH  7H  TH  QC

 6S  3D  2C  8S  4D  2H  8C  JS  6S
 QD  6H  TC  QS  6D  3H  8H  JC  QD

 6C  TS  5D  3C  8D  4H  9C  JD  6C
 QH  KC  KD  7C  TD  5H  9H  JH  QH

 6D  3H  8H  JC  QD  6H  TC  QS  6D
 KS  7S  4S  2D  AH  7H  TH  QC  KS

 6H  TC  QS  6D  3H  8H  JC  QD  6H
 KC  KD  7C  TD  5H  9H  JH  QH  KC

 7S  4S  2D  AH  7H  TH  QC  KS  7S
 KD  7C  TD  5H  9H  JH  QH  KC  KD

 7C  TD  5H  9H  JH  QH  KC  KD  7C
 KH  KH  KH  KH  KH  KH  KH  KH  KH

```
> 6 votes

# Answer
# K, 55 53 51

```
{$,/(,').`$2 26#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]

```

Shaved 2 chars by changing from symbol representation to string

output

```
k){$,/(,').`$(2 26)#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]
"AS" "AC" "AD" "AH" "2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH"
"AS" "7D" "AC" "7H" "AD" "8S" "AH" "8C" "2S" "8D" "2C" "8H" "2D" "9S" "2H" "9C" "3S" "9D" "3C" "9H" "3D" "TS" "3H" "TC" "4S" "TD" "4C" "TH" "4D" "JS" "4H" "JC" "5S" "JD" "5C" "JH" "5D" "QS" "5H" "QC" "6S" "QD" "6C" "QH" "6D" "KS" "6H" "KC" "7S" "KD" "7C" "KH"
"AS" "4C" "7D" "TH" "AC" "4D" "7H" "JS" "AD" "4H" "8S" "JC" "AH" "5S" "8C" "JD" "2S" "5C" "8D" "JH" "2C" "5D" "8H" "QS" "2D" "5H" "9S" "QC" "2H" "6S" "9C" "QD" "3S" "6C" "9D" "QH" "3C" "6D" "9H" "KS" "3D" "6H" "TS" "KC" "3H" "7S" "TC" "KD" "4S" "7C" "TD" "KH"
"AS" "9S" "4C" "QC" "7D" "2H" "TH" "6S" "AC" "9C" "4D" "QD" "7H" "3S" "JS" "6C" "AD" "9D" "4H" "QH" "8S" "3C" "JC" "6D" "AH" "9H" "5S" "KS" "8C" "3D" "JD" "6H" "2S" "TS" "5C" "KC" "8D" "3H" "JH" "7S" "2C" "TC" "5D" "KD" "8H" "4S" "QS" "7C" "2D" "TD" "5H" "KH"
"AS" "5S" "9S" "KS" "4C" "8C" "QC" "3D" "7D" "JD" "2H" "6H" "TH" "2S" "6S" "TS" "AC" "5C" "9C" "KC" "4D" "8D" "QD" "3H" "7H" "JH" "3S" "7S" "JS" "2C" "6C" "TC" "AD" "5D" "9D" "KD" "4H" "8H" "QH" "4S" "8S" "QS" "3C" "7C" "JC" "2D" "6D" "TD" "AH" "5H" "9H" "KH"
"AS" "3S" "5S" "7S" "9S" "JS" "KS" "2C" "4C" "6C" "8C" "TC" "QC" "AD" "3D" "5D" "7D" "9D" "JD" "KD" "2H" "4H" "6H" "8H" "TH" "QH" "2S" "4S" "6S" "8S" "TS" "QS" "AC" "3C" "5C" "7C" "9C" "JC" "KC" "2D" "4D" "6D" "8D" "TD" "QD" "AH" "3H" "5H" "7H" "9H" "JH" "KH"
"AS" "2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "TS" "JS" "QS" "KS" "AC" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "TC" "JC" "QC" "KC" "AD" "2D" "3D" "4D" "5D" "6D" "7D" "8D" "9D" "TD" "JD" "QD" "KD" "AH" "2H" "3H" "4H" "5H" "6H" "7H" "8H" "9H" "TH" "JH" "QH" "KH"
"AS" "AD" "2S" "2D" "3S" "3D" "4S" "4D" "5S" "5D" "6S" "6D" "7S" "7D" "8S" "8D" "9S" "9D" "TS" "TD" "JS" "JD" "QS" "QD" "KS" "KD" "AC" "AH" "2C" "2H" "3C" "3H" "4C" "4H" "5C" "5H" "6C" "6H" "7C" "7H" "8C" "8H" "9C" "9H" "TC" "TH" "JC" "JH" "QC" "QH" "KC" "KH"
"AS" "AC" "AD" "AH" "2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH"

k)@[a;0]~@[;8]a:{$,/(,').`$(2 26)#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]  /8th iteration identical to the first?
1b

```
> 5 votes

# Answer
## Ruby 1.9 (~~95~~ ~~93~~ 87)

```
a=(0..51).map{|i|:A23456789TJQK[i/4]+:SCDH[i%4]}
9.times{p a;a=a.zip(a.pop 26).flatten}

```

Output:

```
["AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH"]
["AS", "7D", "AC", "7H", "AD", "8S", "AH", "8C", "2S", "8D", "2C", "8H", "2D", "9S", "2H", "9C", "3S", "9D", "3C", "9H", "3D", "TS", "3H", "TC", "4S", "TD", "4C", "TH", "4D", "JS", "4H", "JC", "5S", "JD", "5C", "JH", "5D", "QS", "5H", "QC", "6S", "QD", "6C", "QH", "6D", "KS", "6H", "KC", "7S", "KD", "7C", "KH"]
["AS", "4C", "7D", "TH", "AC", "4D", "7H", "JS", "AD", "4H", "8S", "JC", "AH", "5S", "8C", "JD", "2S", "5C", "8D", "JH", "2C", "5D", "8H", "QS", "2D", "5H", "9S", "QC", "2H", "6S", "9C", "QD", "3S", "6C", "9D", "QH", "3C", "6D", "9H", "KS", "3D", "6H", "TS", "KC", "3H", "7S", "TC", "KD", "4S", "7C", "TD", "KH"]
["AS", "9S", "4C", "QC", "7D", "2H", "TH", "6S", "AC", "9C", "4D", "QD", "7H", "3S", "JS", "6C", "AD", "9D", "4H", "QH", "8S", "3C", "JC", "6D", "AH", "9H", "5S", "KS", "8C", "3D", "JD", "6H", "2S", "TS", "5C", "KC", "8D", "3H", "JH", "7S", "2C", "TC", "5D", "KD", "8H", "4S", "QS", "7C", "2D", "TD", "5H", "KH"]
["AS", "5S", "9S", "KS", "4C", "8C", "QC", "3D", "7D", "JD", "2H", "6H", "TH", "2S", "6S", "TS", "AC", "5C", "9C", "KC", "4D", "8D", "QD", "3H", "7H", "JH", "3S", "7S", "JS", "2C", "6C", "TC", "AD", "5D", "9D", "KD", "4H", "8H", "QH", "4S", "8S", "QS", "3C", "7C", "JC", "2D", "6D", "TD", "AH", "5H", "9H", "KH"]
["AS", "3S", "5S", "7S", "9S", "JS", "KS", "2C", "4C", "6C", "8C", "TC", "QC", "AD", "3D", "5D", "7D", "9D", "JD", "KD", "2H", "4H", "6H", "8H", "TH", "QH", "2S", "4S", "6S", "8S", "TS", "QS", "AC", "3C", "5C", "7C", "9C", "JC", "KC", "2D", "4D", "6D", "8D", "TD", "QD", "AH", "3H", "5H", "7H", "9H", "JH", "KH"]
["AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH"]
["AS", "AD", "2S", "2D", "3S", "3D", "4S", "4D", "5S", "5D", "6S", "6D", "7S", "7D", "8S", "8D", "9S", "9D", "TS", "TD", "JS", "JD", "QS", "QD", "KS", "KD", "AC", "AH", "2C", "2H", "3C", "3H", "4C", "4H", "5C", "5H", "6C", "6H", "7C", "7H", "8C", "8H", "9C", "9H", "TC", "TH", "JC", "JH", "QC", "QH", "KC", "KH"]
["AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH"]

```
> 4 votes

# Answer
### Python3, 180 179

```
from itertools import*;i=list(map("".join,product("A23456789XJQK","SCDH")));exec('print(",".join(i).replace("X","10"));i=list(chain(*zip(islice(i,0,26,1),islice(i,26,52,1))));'*8)

```

Outputs lines like in task.

### Native Format 151

```
from itertools import*;i=list(map("".join,product("A23456789TJQK","SCDH")));exec('print(i);i=list(chain(*zip(islice(i,0,26,1),islice(i,26,52,1))));'*8)

```

Output is like in Ruby version.
> 3 votes

# Answer
# Mathematica 131 129 120 114 100 86 chars

With help from Mr.Wizard:

```
NestList[Riffle @@ #~Partition~26 &, # <> "" & /@ Tuples@Characters@
{"A23456789TJQK", "HDCS"}, 8]

```

Output:
> 3 votes

# Answer
### GolfScript, 51 50 46 characters

```
"A23456789TJQK"4*"SCDH"13*]{zip""*2/.p 26/}9*;

```

This GolfScript code yields the following output (see here):

```
["AS" "2C" "3D" "4H" "5S" "6C" "7D" "8H" "9S" "TC" "JD" "QH" "KS" "AC" "2D" "3H" "4S" "5C" "6D" "7H" "8S" "9C" "TD" "JH" "QS" "KC" "AD" "2H" "3S" "4C" "5D" "6H" "7S" "8C" "9D" "TH" "JS" "QC" "KD" "AH" "2S" "3C" "4D" "5H" "6S" "7C" "8D" "9H" "TS" "JC" "QD" "KH"]
["AS" "AD" "2C" "2H" "3D" "3S" "4H" "4C" "5S" "5D" "6C" "6H" "7D" "7S" "8H" "8C" "9S" "9D" "TC" "TH" "JD" "JS" "QH" "QC" "KS" "KD" "AC" "AH" "2D" "2S" "3H" "3C" "4S" "4D" "5C" "5H" "6D" "6S" "7H" "7C" "8S" "8D" "9C" "9H" "TD" "TS" "JH" "JC" "QS" "QD" "KC" "KH"]
["AS" "AC" "AD" "AH" "2C" "2D" "2H" "2S" "3D" "3H" "3S" "3C" "4H" "4S" "4C" "4D" "5S" "5C" "5D" "5H" "6C" "6D" "6H" "6S" "7D" "7H" "7S" "7C" "8H" "8S" "8C" "8D" "9S" "9C" "9D" "9H" "TC" "TD" "TH" "TS" "JD" "JH" "JS" "JC" "QH" "QS" "QC" "QD" "KS" "KC" "KD" "KH"]
["AS" "7S" "AC" "7C" "AD" "8H" "AH" "8S" "2C" "8C" "2D" "8D" "2H" "9S" "2S" "9C" "3D" "9D" "3H" "9H" "3S" "TC" "3C" "TD" "4H" "TH" "4S" "TS" "4C" "JD" "4D" "JH" "5S" "JS" "5C" "JC" "5D" "QH" "5H" "QS" "6C" "QC" "6D" "QD" "6H" "KS" "6S" "KC" "7D" "KD" "7H" "KH"]
["AS" "4S" "7S" "TS" "AC" "4C" "7C" "JD" "AD" "4D" "8H" "JH" "AH" "5S" "8S" "JS" "2C" "5C" "8C" "JC" "2D" "5D" "8D" "QH" "2H" "5H" "9S" "QS" "2S" "6C" "9C" "QC" "3D" "6D" "9D" "QD" "3H" "6H" "9H" "KS" "3S" "6S" "TC" "KC" "3C" "7D" "TD" "KD" "4H" "7H" "TH" "KH"]
["AS" "9S" "4S" "QS" "7S" "2S" "TS" "6C" "AC" "9C" "4C" "QC" "7C" "3D" "JD" "6D" "AD" "9D" "4D" "QD" "8H" "3H" "JH" "6H" "AH" "9H" "5S" "KS" "8S" "3S" "JS" "6S" "2C" "TC" "5C" "KC" "8C" "3C" "JC" "7D" "2D" "TD" "5D" "KD" "8D" "4H" "QH" "7H" "2H" "TH" "5H" "KH"]
["AS" "5S" "9S" "KS" "4S" "8S" "QS" "3S" "7S" "JS" "2S" "6S" "TS" "2C" "6C" "TC" "AC" "5C" "9C" "KC" "4C" "8C" "QC" "3C" "7C" "JC" "3D" "7D" "JD" "2D" "6D" "TD" "AD" "5D" "9D" "KD" "4D" "8D" "QD" "4H" "8H" "QH" "3H" "7H" "JH" "2H" "6H" "TH" "AH" "5H" "9H" "KH"]
["AS" "3D" "5S" "7D" "9S" "JD" "KS" "2D" "4S" "6D" "8S" "TD" "QS" "AD" "3S" "5D" "7S" "9D" "JS" "KD" "2S" "4D" "6S" "8D" "TS" "QD" "2C" "4H" "6C" "8H" "TC" "QH" "AC" "3H" "5C" "7H" "9C" "JH" "KC" "2H" "4C" "6H" "8C" "TH" "QC" "AH" "3C" "5H" "7C" "9H" "JC" "KH"]
["AS" "2C" "3D" "4H" "5S" "6C" "7D" "8H" "9S" "TC" "JD" "QH" "KS" "AC" "2D" "3H" "4S" "5C" "6D" "7H" "8S" "9C" "TD" "JH" "QS" "KC" "AD" "2H" "3S" "4C" "5D" "6H" "7S" "8C" "9D" "TH" "JS" "QC" "KD" "AH" "2S" "3C" "4D" "5H" "6S" "7C" "8D" "9H" "TS" "JC" "QD" "KH"]

```
> 3 votes

# Answer
### Perl, 91 chars

Any suggestions on a more concise way of building the initial deck? My approach uses 2 substitutions to build `$_` and then a global match in list context to initialize `@_`.

The shuffling is then done by repeatedly `splice`ing `@_` onto `@a` and interleaving the two lists with `map` back into `@_`.

```
s//A23456789TJQK/,s/(.)/$1S$1C$1D$1H/g,@_=/../g;say@_=map{shift@_,$_}@a=splice@_,26for 0..8

```
> 3 votes

# Answer
# CJam, 34 bytes

CJam is newer than the question, so this answer doesn't compete for the green checkmark, but I thought this would be a nice problem to try in CJam.

```
A,2>s"TJQKA"+"SCDH"m*{_p26/z:~}8*p

```

Test it here.

It prints the output like

```
["2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH" "AS" "AC" "AD" "AH"]
["2S" "8D" "2C" "8H" "2D" "9S" "2H" "9C" "3S" "9D" "3C" "9H" "3D" "TS" "3H" "TC" "4S" "TD" "4C" "TH" "4D" "JS" "4H" "JC" "5S" "JD" "5C" "JH" "5D" "QS" "5H" "QC" "6S" "QD" "6C" "QH" "6D" "KS" "6H" "KC" "7S" "KD" "7C" "KH" "7D" "AS" "7H" "AC" "8S" "AD" "8C" "AH"]
["2S" "5C" "8D" "JH" "2C" "5D" "8H" "QS" "2D" "5H" "9S" "QC" "2H" "6S" "9C" "QD" "3S" "6C" "9D" "QH" "3C" "6D" "9H" "KS" "3D" "6H" "TS" "KC" "3H" "7S" "TC" "KD" "4S" "7C" "TD" "KH" "4C" "7D" "TH" "AS" "4D" "7H" "JS" "AC" "4H" "8S" "JC" "AD" "5S" "8C" "JD" "AH"]
["2S" "TS" "5C" "KC" "8D" "3H" "JH" "7S" "2C" "TC" "5D" "KD" "8H" "4S" "QS" "7C" "2D" "TD" "5H" "KH" "9S" "4C" "QC" "7D" "2H" "TH" "6S" "AS" "9C" "4D" "QD" "7H" "3S" "JS" "6C" "AC" "9D" "4H" "QH" "8S" "3C" "JC" "6D" "AD" "9H" "5S" "KS" "8C" "3D" "JD" "6H" "AH"]
["2S" "6S" "TS" "AS" "5C" "9C" "KC" "4D" "8D" "QD" "3H" "7H" "JH" "3S" "7S" "JS" "2C" "6C" "TC" "AC" "5D" "9D" "KD" "4H" "8H" "QH" "4S" "8S" "QS" "3C" "7C" "JC" "2D" "6D" "TD" "AD" "5H" "9H" "KH" "5S" "9S" "KS" "4C" "8C" "QC" "3D" "7D" "JD" "2H" "6H" "TH" "AH"]
["2S" "4S" "6S" "8S" "TS" "QS" "AS" "3C" "5C" "7C" "9C" "JC" "KC" "2D" "4D" "6D" "8D" "TD" "QD" "AD" "3H" "5H" "7H" "9H" "JH" "KH" "3S" "5S" "7S" "9S" "JS" "KS" "2C" "4C" "6C" "8C" "TC" "QC" "AC" "3D" "5D" "7D" "9D" "JD" "KD" "2H" "4H" "6H" "8H" "TH" "QH" "AH"]
["2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "TS" "JS" "QS" "KS" "AS" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "TC" "JC" "QC" "KC" "AC" "2D" "3D" "4D" "5D" "6D" "7D" "8D" "9D" "TD" "JD" "QD" "KD" "AD" "2H" "3H" "4H" "5H" "6H" "7H" "8H" "9H" "TH" "JH" "QH" "KH" "AH"]
["2S" "2D" "3S" "3D" "4S" "4D" "5S" "5D" "6S" "6D" "7S" "7D" "8S" "8D" "9S" "9D" "TS" "TD" "JS" "JD" "QS" "QD" "KS" "KD" "AS" "AD" "2C" "2H" "3C" "3H" "4C" "4H" "5C" "5H" "6C" "6H" "7C" "7H" "8C" "8H" "9C" "9H" "TC" "TH" "JC" "JH" "QC" "QH" "KC" "KH" "AC" "AH"]
["2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH" "AS" "AC" "AD" "AH"]

```

## Explanation

```
A,2>s"TJQKA"+"SCDH"m*{_p26/z:~}8*p
A,                                 "Get the range from 0 to 9.";
  2>                               "Slice off first two elements.";
    s                              "Convert to string '23456789'.";
     "TJQKA"+                      "Append this string.";
             "SCDH"                "Push the suits.";
                   m*              "Take the Cartesian product. This yields the first line.";
                     {        }8*  "Execute this block 8 times.";
                      _p           "Duplicate the last line and print it.";
                        26/        "Split the array into halves.";
                           z       "Zip, i.e. transpose the array.";
                            :~     "Flatten the array.";
                                 p "Print the final deck.";

```
> 2 votes

# Answer
# , 97 bytes

Saved a few bytes with a convenient out-of-order deck

```
d=paste(rep(c(2:10,"A","J","Q","K"),4),quote(S(C,D,H)))
for(i in 1:9)print(d<-c(t(matrix(d,26))))

```

Try it online!
> 1 votes

# Answer
# ///, 753 bytes

```
/*/\/\///}/S,*'/C,*"/D,*;/H,*b/A'*c/A"*d/A;*e/2}*f/2'*g/2"*h/2;*i/3}*j/3'*k/3"*l/3;*m/4}*n/4'*o/4"*p/4;*q/5}*r/5'*s/5"*t/5;*u/6}*v/6'*w/6"*x/6;*y/7}*z/7'*-/7"*B/7;*+/8}*!/8'*E/8"*F/8;*G/9}*@/9'*I/9"*_/9;*(/10}*L/10'*M/10"*N/10;*O/J}*P/J'*)/J"*R/J;*$/Q}*T/Q'*U/Q"*V/Q;*W/K}*X/K'*Y/K"*{/KH
A}/A}bcdefghijklmnopqrstuvwxyz-B+!EFG@I_(LMNOP)R$TUVWXY{-bBc+d!eEfFgGh@iIj_k(lLmMnNoOpPq)rRs$tTuUvVwWxXyYz{n-NboBOcp+Pdq!)erERfsF$gtGThu@UivIVjw_Wkx(XlyLYmzM{GnT-hNub@oUBiOvcIpV+jPwd_qW!k)xe(rXElRyfLsYFm$zgMt{qGWn!Tk-)hxNeu(br@XoEUlBRiyOfvLcsIYpFVm+$jzPgwMdt_{iqyGOWfnv!LTcks-I)YhpxFNVemu+($bjrz@PXgowEMUdltB_R{eimquy+G(O$Wbfjnrvz!@LPTXcgkosw-EIM)UYdhlptxBF_NRV{cegikmoqsuwy-+EGI(MO)$UWYbdfhjlnprtvxzB!F@_LNPRTVX{bcdefghijklmnopqrstuvwxyz-B+!EFG@I_(LMNOP)R$TUVWXYKH

```

Try it online!

Uses the example output (it's pretty fit for this purpose) without the trailing spaces.
> 0 votes

# Answer
# Japt, 31 bytes

```
9o åÈó c}"SCDH"ï"TJQKA"i2ò9 ¬¹w

```

Try it!

Although Japt has a reasonable "interleave two lists" function, it does not have a great "separate into halves" option. Instead I opted to *unshuffle* a deck and just display those steps in reverse.

Explanation:

```
9o                           ¹     Generate 9 rows, starting with...
         "SCDH"                      The suits
               ï                     Cartesian product with...
                "TJQKA"                The "special" card values
                       i               Concatenated with...
                        2ò9 ¬          Digits 2-9 as a string; i.e. "23456789"
   å    }                          And getting each subsequent row by "unshuffling":
    Èó                               Separate every-other card; e.g. [1,2,3,4,5,6] -> [[1,3,5],[2,4,6]]
       c                             and flatten the two lists; e.g. [[1,3,5],[2,4,6]] -> [1,3,5,2,4,6]
                              w    Display in reverse order

```

I could save 2 bytes if I could use 1 for aces instead of A, but none of the other answers did that
> 0 votes

# Answer
# 05AB1E, 24 bytes

```
2TŸ.•-Ÿ•S«.•ôì•âJ9F=2äζ˜

```

Uses lowercase cards to save 2 bytes with compression, since any human-readable output is allowed.
Starting/ending deck is:

```
['2c','2d','2h','2s','3c','3d','3h','3s','4c','4d','4h','4s','5c','5d','5h','5s','6c','6d','6h','6s','7c','7d','7h','7s','8c','8d','8h','8s','9c','9d','9h','9s','10c','10d','10h','10s','ac','ad','ah','as','jc','jd','jh','js','qc','qd','qh','qs','kc','kd','kh','ks']

```

Try it online (PS: Uses the legacy TIO because it is much faster.. All builtins that were used in this answer are the same in both the Python legacy and Elixir rewrite versions of 05AB1E however.)

**Explanation:**

```
2TŸ           # List in the range [2,10]: [2,3,4,5,6,7,8,9,10]
   .•-Ÿ•      # Compressed string "ajqk"
        S     # As a list of characters: ["a","j","q","k"]
         «    # Merge the lists together: [2,3,4,5,6,7,8,9,10,"a","j","q","k"]
.•ôì•         # Compressed string "cdhs"
     â        # Create each possible pair (cartesian product)
      J       # Join each pair together (now we have our deck of cards)
9F            # Loop 9 times:
  =           #  Print the deck with trailing newline, without popping the deck
   2ä         #  Split it in two equal parts
     ζ        #  Zip it (swap rows/columns)
      ˜       #  Flatten the list of lists

```

See this 05AB1E tip of mine (section *How to compress strings not part of the dictionary?*) to understand why `.•-Ÿ•` is `"ajqk"` and `.•ôì•` is `"cdhs"`.
> 0 votes

# Answer
# Perl 6, 69 bytes

```
([o] {.say;.[flat ^26 Z 26..*]}xx 9)(«A {2..10} J Q K»X~ <S C D H>)

```

Try it online!

* `{ .say; .[flat ^26 Z 26..*] }` is an anonymous function that prints its argument list, then returns a perfect shuffle of that list
* `xx 9` produces a list containing nine copies of that anonymous function
* `[o]` reduces that list with the function composition operator `o`, producing a function that calls the original anonymous function nine times, passing the shuffled list down each level
* Finally, the original unshuffled deck is passed to that composed function. `«A {2..10} J Q K»` is a list of the ranks, `<S C D H>` is a list of the suits, and `X~` produces the cross product of those lists with the string concatenation operator `~`.
> 0 votes

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


title: Solve the New York Times Spelling Bee

text:
# Question
Title: Solve the New York Times Spelling Bee
*The New York Times* periodically runs a puzzle they call the "Spelling Bee" in which they list six "allowed" letters plus one "mandatory" letter and challenge the reader to form as many five-letter-or-longer dictionary words as possible out of those letters. Each "allowed" letter can appear 0 or more times. The mandatory letter must appear at least once in each word. No other letters are allowed. Proper nouns are **not** acceptable answers.

For example, in last week's puzzle, the allowed letters were `{"A", "C", "D", "H", "I", and "R"}`, while the mandatory letter was `"N"`.

Allowed answers for this set of letters range from 5-letter words "ranch", "naiad", and "nadir", up to 9-letter words "cnidarian" and "circadian".

The more words you find, the higher the *Times* rates your intelligence. Your challenge: write a solver in the language of your choice.

Additional rules and tips:

1. If your programming environment or operating system provides a list of words, you may use it. If not, you must include code for loading a word list from disk or the internet; you can not assume it has been magically loaded into a variable outside your code.
2. The word list should be generic, not limited to only those words that contain the mandatory letter, and not limited to words that meet the length or other requirements here. In other words, all dictionary searches should be done by your code, not some pre-processor.
3. If a word is capitalized in the dictionary, treat it as a proper noun. If your dictionary does not distinguish proper nouns, find a different dictionary.
4. Different dictionaries will deliver different sets of answers, but given the test case above, you must return at least 20 qualifying answers, and the words "harridan", "niacin", and "circadian" must be on it. The words "Diana", "Adrian", and "India", as proper nouns, must not be.
5. Your code should take the form of a function or program that accepts two variables: a string or list of characters representing the allowed letters, and a character representing the required letter. It should return a list of allowed answers in any order.
6. Except to the extent my rules here dictate otherwise, standard loopholes are forbidden.
7. In the event my rule summary here deviates from the rules at the *New York Times*, follow the rules here.
8. Shortest byte count wins, though I plan to call out excellent solutions using novel algorithms or that are otherwise interesting to me, assuming any such are submitted.

# Answer
> 5 votes
# bash/dash/ash with grep and egrep, ~~31 30~~ 29 bytes

```
egrep ^[$1$2]\{5,}$ z|grep $2

```

This assumes you have a a word list in a file named `z`. The word list I used was kindly provided by briantist.

Example:

```
$ echo 'egrep ^[$1$2]\{5,}$ z|grep $2' > program; chmod +x program
$ ./program acdhir n | tr '\n' ' '
acarian acaridan acini ahind anana anarch anarchic arachnid arachnidan arcana arnica cairn canard cancan candid candida canid canna cannach caranna carina chain characin chicana china chinar chinch cinch circadian cnida cnidarian cranch crania dharna diarian dinar dinic drain handcar harridan inarch indican indicia indri iridian nadir naiad naira nanna niacin nicad rachidian radian ranarian ranch rancid randan ricin

```

# Answer
> 8 votes
# PowerShell, ~~50~~ ~~44~~ ~~41~~ ~~39~~ 43 bytes

```
param($a,$m)gc z|sls $m|sls "^[$a$m]{5,9}$"

```

## Notes

* Using a ~~scriptblock (unnamed function) because there's still a requirement for a function~~ full program.
* Takes the "allowed" letters as a single string.
* Using The English Open Word List which is provided as a series of lists (one for each letter). I've combined them all into a single file named `z`, ~~but I only included words that are between 5 and 9 letters, inclusive~~ due to the new rule, the wordlist and my gist have been updated to not exclude any of the original words (of any size). Here's the list, for anyone else to use.

## Explanation

Reads the wordlist file `z` as lines and does two regular expression matches (by way of `Select-String` with the `sls` alias). The first `sls` matches the mandatory letter, so the result is all the words that contain the letter, then that gets piped into the second `sls` which uses an expression that, in the case of the example input, looks like this: `^[acdhirn]{5,9}$` (so it matches only words that consist of those letters and no others, between 5 and 9 characters in length, inclusive).

## Invocation and Output

```
&{param($a,$m)gc z|sls $m|sls ^[$a$m]+$} 'acdhir' 'n'

```

Output (57 words):

```
acarian
acaridan
acini
ahind
anana
anarch
anarchic
arachnid
arcana
arnica
cairn
canard
cancan
candid
candida
canid
canna
cannach
caranna
carina
chain
characin
chicana
china
chinar
chinch
cinch
circadian        #
cnida
cnidarian
cranch
crania
dharna
diarian
dinar
dinic
drain
handcar
harridan         #
inarch
indican
indicia
indri
iridian
nadir
naiad
naira
nanna
niacin           #
nicad
rachidian
radian
ranarian
ranch
rancid
randan
ricin

```

# Answer
> 6 votes
# **Mathematica, ~~143~~ 130 bytes**

```
Join@@StringCases[Join@@StringCases[WordList[],RegularExpression["^["<>#2<>#<>"]{5,9}$"]],RegularExpression["\w+(?="<>#<>")\w+"]]&

```

## Invocation (with input)

```
Join@@StringCases[Join@@StringCases[WordList[],RegularExpression["^["<>#2<>#<>"]{5,9}$"]],RegularExpression["\w+(?="<>#<>")\w+"]]&["n","acdhir"]

```

## Output (20 words)

```
{"anarchic", "arachnid", "cairn", "canard", "cancan", "candid", "candida", "chain", "china", "cinch", "circadian", "cnidarian", "dinar", "drain", "handcar", "harridan", "niacin", "radian", "ranch", "rancid"}

```

### Explanation

```
Join@@    // Shortened version of Flatten; removes {} from StringCases lists
    StringCases[    // Find substrings in a string/list that match a regex pattern.
        Join@@
            StringCases[
                WordList[],    // Built-in function; returns a list of English words.
                RegularExpression[
                    "^["<>#2<>#<>"]{5,9}$"    // Take the WordList, and find 5-9 letter
                                              // words with any character in the
                                              // the first or second arguments.
                                              // In this case, "x" would be "achdir",
                                              // and "y" is the letter "n".
                                              // <> is for string concatenation.
                ]
            ],
        RegularExpression[
            "\w+(?="<>#<>")\w+"              // Take the result from the previous
                                              // StringCases function, and find words
                                              // that actually have the character(s) in
                                              // the second argument in them.
                                              // In this case, find words that actually
                                              // have the letter "n" in them.
        ]
    ]
&    // Define an anonymous function.
["n","acdhir"]    // Pass arguments to the function; "#" is "n", and "#2" is "acdhir".

```

# Answer
> 4 votes
# Python 3.6  ~~84~~  78 bytes

-6 bytes thanks to WuTheFWasThat (`splitlines` -\> `split` and `{c}and 4<len(w)<10` -\> `{c*(4<len(w)<10)}`)

```
lambda s,c:[w for w in open('z').read().split()if{*w}-{*s}=={c*(4<len(w)<10)}]

```

An unnamed function that takes a string and a character. Returns a list created by keeping those entries (`w`s) from a file where the set of remaining letters after removing any that are in the "can use" set (`{*s}`) is the set of the single "must use" character. The `*`s in `{*x}` unpack the strings to save bytes over `set(x)`. The word-length check is `4<len(w)<10` and string multiplication saves a byte (since `{*w}-{*s}` can never result in a set containing an empty string).

Requires a file in the current directory named simply **z** containing the list of words separated by newlines (or carriage returns or both).

Taking a list of words would be preferable at **58** bytes.

With `s='acdhri'` and `c='n'` and using a file containing all entries and suffixed entries from the Chambers Scrabble™ Words (CSW) dictionary A.K.A. SOWPODS (which explicitly excludes proper nouns) we get the following resulting list of **85** words:

```
['acarian', 'acaridan', 'acaridian', 'acinar', 'acini', 'acinic', 'acridin', 'adhan', 'ahind', 'anana', 'anarch', 'anarchic', 'anicca', 'aniridia', 'aniridic', 'arachnid', 'arcadian', 'arcan', 'arcana', 'arnica', 'cairn', 'canada', 'canard', 'cancan', 'cancha', 'candid', 'candida', 'canid', 'canna', 'cannach', 'caranna', 'cardan', 'carina', 'chain', 'chana', 'characin', 'chicana', 'china', 'chinar', 'chinch', 'cinch', 'circadian', 'cnida', 'cnidarian', 'cranachan', 'cranch', 'crani', 'crania', 'darrain', 'dharna', 'diarian', 'dinar', 'dinic', 'dinna', 'drain', 'hainch', 'hanch', 'handcar', 'hariana', 'harridan', 'hinahina', 'inarch', 'india', 'indican', 'indicia', 'indri', 'iridian', 'nadir', 'naiad', 'naira', 'nandin', 'nandina', 'nanna', 'naric', 'niacin', 'nicad', 'rachidian', 'radian', 'radicand', 'ranarian', 'ranch', 'rancid', 'randan', 'ranid', 'ricin']

```

The word "india", is listed by this dictionary even though, due to the rules of Scrabble™, it explicitly excludes proper nouns, as: "(In international radio communication) a code word for the letter i \[-S\]" ('-S' indicating "inidas" is also acceptable), of course we could use any other file listing the words, but do note that "india" is also listed in TWL, the equivalent dictionary used in official Scrabble™ tournaments in the U.S. and Canada.

# Answer
> 2 votes
# Perl 6, ~~48~~ 41 bytes

~~```
{grep /^@_*[$^a@_*]+$/,grep *.comb>4,1.IO.words}

```~~
```
{grep /^@_**5..*$/&/$(@_[0])/,1.IO.words}

```

Expects a whitespace-separated wordlist as a file called `1` in the current directory.
Expects the required character as the first argument, and a list of the additional allowed characters as the second argument (or as multiple arguments, it doesn't matter), all in lowercase.

### How it works

```
{                                       } # A lambda. (@_ is the flattened argument list.)
                              1.IO.words  # Read words from file as a lazy sequence.
 grep /          /&/        /             # Filter words which match *both* these regexes:
       ^@_**5..*$                         #   1) Consists of 5+ allowed chars.
                    $(@_[0])              #   2) Contains the required char.

```

# Answer
> 1 votes
**Perl, 43 + 1 (`-n` switch)**

```
/^[^\p{Lu}](?i)(?=.*n)[acdhirn]{5,9}$/&&say

```

**Run** on linux:

```
perl -nE '/^[^\p{Lu}](?i)(?=.*n)[acdhirn]{5,9}$/&&say' < /usr/share/dict/american-english

```

**Output:** 33 words without proper nouns

```
anarchic
arachnid
banana
bandana
bandanna
branch
canard
cancan
candid
circadian
crania
enrich
errand
farina
grandad
granddad
handcar
harridan
maharani
mandarin
maniac
marina
niacin
ocarina
ordain
picnic
piranha
rancid
saccharin
tannin
unhand
urchin
zinnia

```

# Answer
> 1 votes
# Powershell, 41 bytes

*Inspired by briantist's answer.*

briantist uses 3 cmdlets to make a solution. I would like to keep within one cmdlet.

```
param($a,$m)sls "^(?=.*$m)[$a$m]{5,9}$" z

```

As with the briantist's answer, I used The English Open Word List files combined into a single file named `z`.

As in other answers, the regex subpattern `^[$a$m]{5,9}$` asserts when a line contains allowed and required chars only.

The basic difference: `(?=.*$m)` asserts that the required character can be matched somewhere in a line, without consuming characters. See docs.

Unfortunately, `sls` provides additional information, not matches only. The rules don't forbid it `:-)`. To display only words, you need to get the value of the `Line` property (47 bytes) or call the cmdlet `gc` (43 or 44 bytes).

Test script:

```
$f = {

                                                    # the output contains words and extra info
 param($a,$m)sls "^(?=.*$m)[$a$m]{5,9}$" z          # 41 bytes, 1 command
#param($a,$m)sls $m z|sls "^[$a$m]{5,9}$"           # 40 bytes, 2 commands

                                                    # only words solutions:
#param($a,$m)sls "^(?=.*$m)[$a$m]{5,9}$" z|% l*e    # 47 bytes, 1 command + 1 property
#param($a,$m)gc z|sls "^(?=.*$m)[$a$m]{5,9}$"       # 44 bytes, 2 commands
#param($a,$m)gc z|sls $m|sls "^[$a$m]{5,9}$"        # 43 bytes, 3 commands, briantist's https://codegolf.stackexchange.com/a/111293/80745

}

&$f 'acdhir' 'n'

```

Output:

```
z:542:acarian
z:547:acaridan
z:854:acini
z:2134:ahind
z:3624:anana
z:3644:anarch
z:3647:anarchic
z:5042:arachnid
z:5117:arcana
z:5466:arnica
z:14834:cairn
z:15334:canard
z:15341:cancan
z:15363:candid
z:15364:candida
z:15414:canid
z:15435:canna
z:15440:cannach
z:15866:caranna
z:16065:carina
z:17442:chain
z:17721:characin
z:18241:chicana
z:18408:china
z:18411:chinar
z:18418:chinch
z:19142:cinch
z:19213:circadian
z:20286:cnida
z:20288:cnidarian
z:23975:cranch
z:23983:crania
z:28928:dharna
z:29121:diarian
z:29648:dinar
z:29687:dinic
z:32006:drain
z:48944:handcar
z:49311:harridan
z:54033:inarch
z:54380:indican
z:54393:indicia
z:54473:indri
z:56194:iridian
z:70546:nadir
z:70575:naiad
z:70595:naira
z:70655:nanna
z:71643:niacin
z:71659:nicad
z:87803:rachidian
z:87884:radian
z:88295:ranarian
z:88304:ranch
z:88321:rancid
z:88329:randan
z:92641:ricin

```

---
Tags: code-golf, word-puzzle
---


title: Find arrays with distinct subarray sums

text:
# Question
Title: Find arrays with distinct subarray sums
Consider an array `A` of length `n`. The array contains only integers in the range `1` to `s`. For example take `s = 6`, `n = 5` and `A = (2, 5, 6, 3, 1)`. Let us define `g(A)` as the collection of sums of all the non-empty contiguous subarrays of A. In this case `g(A) = [2,5,6,3,1,7,11,9,4,13,14,10,16,15,17]`. The steps to produce `g(A)` are as follows:

The subarrays of A are (2), (5), (6), (3), (1), (2,5), (5,6), (6,3), (3,1), (2,5,6), (5,6,3), (6,3,1),(2,5,6,3), (5,6,3,1), (2,5,6,3,1). Their respective sums are 2,5,6,3,1,7,11,9,4,13,14,10,16,15,17.

In this case all the sums are distinct.

However, if we looked at `g((1,2,3,4))` then the value 3 occurs twice as a sum and so the sums are not all distinct.

**Task**

For each `s` from 1 upwards, your code should output the largest `n` so that there exists an array A of length n with distinct subarray sums.

Your code should iterate up from `s = 1` giving the answer for each `s` in turn. I will time the entire run, killing it after one minute.

Your score is the highest `s` you get to in that time.

In the case of a tie, the first answer wins.

**Examples**

The answers for `s = 1..12` are `n=1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 8, 9`.

**Testing**

I will need to run your code on my ubuntu machine so please include as detailed instructions as possible for how to compile and run your code.

**Leaderboard**

* **s = 19** by Arnauld in **C**

# Answer
> 2 votes
# C (gcc), s = 19

This is basically a port of my Node.js answer. It goes one step further with the default compiler options and two steps further with `-O2` or `-O3`.

```
#include <stdio.h>
#include <string.h>
#include <stdint.h>

void search(uint8_t * arr, int n, uint8_t * sum, int * max, char * str, int depth) {
  int i, j, k, s;
  char tmp[16];

  // do we have a better array?
  if(depth > *max) {
    for(str[0] = '\0', i = 0; i < depth; i++) {
      sprintf(tmp, "%d ", arr[i]);
      strcat(str, tmp);
    }
    *max = depth;
  }

  // try to append i = 1 to n to the current array
  for(i = 1; i <= n; i++) {
    // provided that doing so does not produce a sum that was already encountered
    if(!sum[i]) {
      for(sum[s = i] = 1, j = depth; j && !sum[s += arr[j - 1]]; j--) {
        sum[s] = 1;
      }
      if(!j) {
        // this is valid: set the value in arr[] and do a recursive call
        arr[depth] = i;
        search(arr, n, sum, max, str, depth + 1);
      }
      // whether the recursive call was processed or not, we have to clear the flags
      // that have been set above
      for(sum[s = i] = 0, k = depth - 1; k >= j; k--) {
        sum[s += arr[k]] = 0;
      }
    }
  }
}

int solve(int n, char * str) {
  int     max = 0;              // best length so far
  int     hi = n * (n + 1) / 2; // highest possible sum for n
  uint8_t sum[hi + 1];          // encountered sums
  uint8_t arr[n];               // array

  memset(sum, 0, (hi + 1) * sizeof(uint8_t));
  search(arr, n, sum, &max, str, 0);

  return max;
}

/////////////////////////////////////////////////////////////////////////////////////

void main() {
  char str[128];
  int  n, res;

  for(n = 1; n <= 19; n++) {
    res = solve(n, str);
    printf("N = %d --> %d with [ %s]\n", n, res, str);
  }
}

```

Try it online!

# Answer
> 1 votes
# Node.js, s = 17

Just a simple recursive search to get the ball rolling. Returns both the length and a valid array.

```
solve = n => {
  var max = 0,  // best length so far
      best,     // best array so far
      sum = {}; // encountered sums

  (search = a => {
    var i, j, k, s;

    // do we have a better array?
    if(a.length > max) {
      max = a.length;
      best = [...a];
    }

    // try to prepend i = 1 to n to the current array
    for(i = 1; i <= n; i++) {
      // provided that doing so does not produce a sum that was already encountered
      if((sum[j = 0, s = i] ^= 1) && a.every(n => sum[j++, s += n] ^= 1)) {
        search([i, ...a]);
      }
      // reset the flags that have been toggled above
      for(sum[s = i] ^= 1, k = 0; k < j; k++) {
        sum[s += a[k]] ^= 1;
      }
    }
  })([]);

  return [ max, best ];
}

```

Try it online!

---
Tags: combinatorics, fastest-code
---


title: Let's play Hangman?

text:
# Question
Title: Let's play Hangman?
According to this page, the best strategy to guess English hangman words is to calculate the odds of each letter in a word list that meet our conditions. But, as I'm really lazy, I don't really want to compute every word in the dictionary by myself. But, as I know that you are always here to help me, I'm sure you will be able to make me some king of a code that will do that for me. And, because my hard disk is nearly full, I'd like the smallest possible code. It means that **this is code-golf, and the submission with the lowest amount of bytes will win, but also the most accurate one !**.

# Input/Output

A random word from this wordlist will be taken.

Your program should accept, in arguments, or by user input (popups, stdin, whatever),

* Length of the word
* Incorrect letter already found, or 0 if we just started the game, and you provided no incorrect letter.
* Letters already found AND their position in the word

Example : `./hangsolver 6 XBZ 1P 4P 2E 6E` Here, I picked the word "people". For clarity : P E _ P _ E (Wrong letters are X B and Z)

That means, in one game, I'll have to launch your script many times!

The output will be a single letter, your next try.

# Rules

* The one that will guess 10 words in less tries than the others will win.
* In case of a tie, shortest code in bytes win.
* If there is still a tie, the fastest program will win.
* You may assume that there are only these words in the English language
* I'll only try valid words from the wordlist.
* I've got a good computer, CPU power won't be a problem ( but try to answer as fast as you can !)
* You can't solve with an online solver, but you can download the wordlist, or have it passed as an argument. You can assume it will be named "wordlist.txt" and in the same directory as your script.
* Your code must be able to run on a common OS. It could be windows, mac, or ubuntu/debian/CentOS or Redhat.
* You can't use an external solver.
* You can however shorten the URL to the wordlist.
* This code-golf will end the first of September.
* You MUST use the method described above.

Good luck !

Wordlist found here on SE.

# Answer
# PowerShell, ~~248~~ ~~246~~ 241 bytes

```
$a=$args;$c=$a[0];$b=$a[2..$c];((gc wordlist.txt)-match"^$((1..$c|%{$e=,"[^$($a[1])]"*$c}{$e[$_-1]=(((@($b)-match"^$_\D")[0]-split$_)[-1],$e[$_-1]-ne'')[0]}{$e-join''}))$"-join''-split'\B'|?{!(@($b)-match$_).Count}|group|sort count)[-1].Name

```

## Ungolfed

Well, as much as I could without changing the way it works:

```
$a=$args
$c=$a[0]
$b=$a[2..$c]
(
    (gc wordlist.txt) -match "^$(
        (
            1..$c | ForEach-Object -Begin {
                $e = ,"[^$($a[1])]" * $c
            } -Process {
                $e[$_-1] = (
                    ( ( @($b) -match "^$_\D" )[0] -split $_ )[-1] , $e[$_-1] -ne ''
                )[0]
            } -End {
                $e-join''
            }
        )
    )$" -join '' -split'\B' |
    Where-Object {
        -not (@($b) -match $_).Count
    } |
    Group-Object |
    Sort-Object count
)[-1].Name

```

## Breakdown

The approach I took here was to first generate a regular expression to get possible words out of the word list. Since I know the length of the word, and the letters that didn't work, I can make a regex out of that fairly easily.

So in the PEOPLE example, 6 letters with XBZ not being part of the word, I would look to generate `^PE[^XBZ]P[^XBZ]E$`.

I'm exploiting the fact that `Get-Content` (`gc`) returns an array of lines, and the `-match` operator when used with an array on the left side, returns an array of matches instead of a bool, so I can quickly get a list of just words that are candidates, once I have the regex.

To generate the regex, I start with an array (`$e`) of the negative matching character class with `$c` elements (`$c` being the number of letters in the word). Iterating through the numbers 1 through `$c`, I check for a matched letter at that position, and if it exists, I replace the element in `$e` with that letter.

Once I've iterated through all of the positions, the final array is `-join`ed (with empty string) and we have our regex.

So now I've got an array of all the possible words it could be. A quick `-join` with empty string on that, gives me one big concatenated string of all the words, the I split on `\B` (not a word boundary, if I split on empty string I will get 2 extra blank elements), so now I have an array of every letter in every possible word.

Piping that into `Where-Object` lets me filter out the letters that have already been matched. This part was a real pain. It had to deal with the list of matched letters (which include the position) being 1 element, more than 1 element, or 0 elements, hence forcing `$b` into an array first so that `-match` can operate on all them, but that (unfortunately in this case) returns an array, so we have to check `.Count`. Using `!(thing).Count` is a bit smaller than using `(thing).Count-gt0`.

Moving on, now we've got an array of all the single characters (as `string`s not as `char`s) from all of the words it could possibly be, minus the letters that were already guessed correctly.

Piping that into `Group-Object` gives me an object with the counts of each letter, so a quick pipe into `Sort-Object count` makes it easy to get the highest count. Rather than do `(thing|sort count -des)[0]` we can use `(thing|sort count)[-1]`. In PowerShell `[-1]` gets the last element. At this point we're still dealing with the objects that came from `Group-Object` so we get the `.Name` property which is the letter that appears the most.

## Notes

* Should work with PowerShell v3+; almost certainly will choke on 2.
* Remember when you call a PowerShell script, pass arguments with spaces, not commas.
* Although I didn't see it in the rules, it looks like everyone is using the filename `wordlist.txt` otherwise that could shave a few bytes off.
* Speed shouldn't be a problem. This appears to run instantly for me. The slowest run I could get it to do (`.\hangman.ps1 7 0`) runs in about 350ms.
> 6 votes

# Answer
# Python3, 299 Bytes

```
import sys,collections as c;x,X,N,*Z=sys.argv;print([x for x in c.Counter(''.join([''.join(x)for x in map(set,filter(lambda l:len(l)==int(X)+1and all(x not in X.lower()for x in l)and all(l[int(x[0])-1]==x[1].lower()for x in Z),open('wordlist.txt')))]))if x not in ''.join(Z).lower()and x!='\n'][0])

```

pretty sure this can be golfed further.

Filters the wordlist for potential matches, builds a char frequency map, and selects the most often occuring character which is not yet picked.
> 7 votes

# Answer
# Java, 646 640 631 607 606 (short) 790 789 779 (fast) bytes

### ***SHORT***

```
import java.util.*;class I{public static void main(String[]a)throws Exception{char[]w=a[1].toCharArray(),p,q;int l=Integer.parseInt(a[0]),i,z=w.length,j;q=new char[l];for(i=2;i<a.length;i++)q[Character.getNumericValue(a[i].charAt(0))-1]=(char)(a[i].charAt(1)+32);java.io.File u=new java.io.File("wordlist.txt");Scanner s=new Scanner(u);while(s.hasNextLine()){p=s.nextLine().toCharArray();if(p.length==l)for(i=0;i<l;i++)if(p[i]==q[i]||q[i]=='\0'){if(i==l-1)y:for(i=0;i<l;i++)for(j=0;j<z;j++)if(!(p[i]==w[j])){if(j==z-1){System.out.print(p[new String(q).indexOf('\0')]);return;}}else break y;}else{break;}}}}

```

### ***FAST***

```
import java.util.*;class I{public static void main(String[]a)throws Exception{char[]w=a[1].toCharArray(),p,q;int l=Integer.parseInt(a[0]),i,z=w.length,j,k,o,n[]=new int[255],r[];q=new char[l];for(i=2;i<a.length;i++)q[Character.getNumericValue(a[i].charAt(0))-1]=(char)(a[i].charAt(1)+32);String m=new String(q);java.io.File u=new java.io.File("wordlist.txt");Scanner s=new Scanner(u);while(s.hasNextLine()){p=s.nextLine().toCharArray();h:if(p.length==l)for(i=0;i<l;i++)if(p[i]==q[i]||q[i]=='\0'){if(i==l-1)y:for(i=0;i<l;i++)for(j=0;j<z;j++)if(p[i]!=w[j]){if(j==z-1){for(k=0;k<l-m.replace("\0","").length();k++)n[(int)p[new String(q).indexOf('\0',k)]]++;break h;}}else break y;}else{break;}}r=n.clone();Arrays.sort(n);for(o=0;o<255;o++)System.out.print(r[o]==n[254]?(char)o:"");}}

```

Put the wordlist file in the folder.

Short version algorithm

1. Load Args
2. Construct the word we are trying to guess {'p','e','\0','p','\0','e'}
3. Load WordList
4. Go through each line of WordList
5. Stop when you find that the whole word matches this condition `p[i] == q[i] || q[i] == '\0'` where p is a word from the wordlist (char array), and q is the word we are trying to guess
6. Loop through wrong chars and compare to the word
7. Print the first missing character

Long version algorithm

1. Short steps 1-7
2. Increment the character count in the n array for the missing chars
3. Loop until all the words come through
4. Print the character that had the highest count
> 3 votes

# Answer
# PHP, 346 bytes

```
<?php $a='array_shift';$p='preg_match';$a($v=&$argv);$w=array_fill(1,$a($v),'(.)');$c=$a($v);foreach($v as$q)$p('/(\d+)(\w)/',$q,$m)&&$w[$m[1]]=$m[2];foreach(file('wordlist.txt')as$y)if($p("/^".implode($w)."$/",$y=strtoupper(trim($y)),$m)&&(!$c||!$p("/[$c]/",$y)))for($i=0;$i++<count($m);)($v=@++$g[$m[$i].$i])&&$v>@$t&&$t=$v&&$l=$m[$i];echo @$l;

```

It works as follows:

1. Creates a regex pattern for matching the letters guessed so far
2. Iterates over each word from the file
3. If the word matches the regex, it makes sure that it doesn't contain one of the wrong letters
4. Increments a counter for each of the possible letters of that word (based on their position)
5. Outputs the letter with the highest counter

Assumptions:

* PHP `>=5.4`
* There is a `wordlist.txt` file in the current folder
> 2 votes

# Answer
# Powershell, 153 bytes

*Inspired by briantist's answer.*

As other writers I used the filename `wordlist.txt`. Although it was possible to choose a shorter name.

```
param($l,$b,$c)((sls "^$(-join(1..$l|%{$p=$c|sls "$_."|% m*
("$p"[1],"[^$b$c]")[!$p]}))$" wordlist.txt|% l*e|% t*y|group|sort c*).Name-match"[^ $c]")[-1]

```

Less golfed test script:

```
$f = {

param($length,$bad,$chars)

$wordPattern=-join(1..$length|%{                  # join all subpatterns for $_ from 1 to $length
    $c=$chars|sls "$_."|% Matches                 # find subpattern in char array
    ("$c"[1],"[^$bad$chars]")[!$c]                # return a first char of subpattern if subpattern found, or bad characters
})

# Note 1: The word subpattern is similar to 'PE[^XBZ1P 4P 2E 6E]P[^XBZ1P 4P 2E 6E]E'
#         Spaces and digits does not affect the search for letters, only letters are important.
#
# Note 2: The same applies to 0. [^0] matches any letter.
#

$matches=sls "^$wordPattern$" wordlist.txt|% Line # find matched words in file wordlist.txt and return matched string only
$groups=$matches|% toCharArray|group|sort Count   # group all chars in matched words by count
$name=$groups.Name-match"[^ $chars]"              # select property Name from all grouped elements (chars itself) and return not matched to $chars only
$name[-1]                                         # return last element in the sorted array (most frequently found char)

# Note 3: The space is important in the regexp "[^ $chars]"
#         The space makes the regexp valid if the $chars array is empty

}

&$f 7 0 2o,5e,7t
&$f 7 nl 2o,5e,7t
&$f 6 XBZ 1P,4P,2E,6E

```

Output:

```
c
r
l

```

Variable values for `&$f 7 0 2o,5e,7t`:

```
$WordPattern: "[^02o 5e 7t]o[^02o 5e 7t][^02o 5e 7t]e[^02o 5e 7t]t"
$Matches: concept collect comment correct connect convert consent concert
$Groups:
    Count Name                      Group
    ----- ----                      -----
        1 p                         {p}
        1 v                         {v}
        1 s                         {s}
        2 m                         {m, m}
        2 l                         {l, l}
        4 r                         {r, r, r, r}
        8 n                         {n, n, n, n...}
        8 o                         {o, o, o, o...}
        8 t                         {t, t, t, t...}
        8 e                         {e, e, e, e...}
       13 c                         {c, c, c, c...}
$name: p v s m l r n c
$name[-1]: c
return: c

```
> 2 votes

---
Tags: code-golf, game, word-puzzle
---


title: Hangman wordgame golf

text:
# Question
Title: Hangman wordgame golf
Inspired by reddit.

Write a program which plays Hangman.

* The program chooses a random word from a list of N words, where N \> 2.
* The word list can be provided to the program in any way you choose.
* At each iteration

+ Print out the state of the game using underscores for letters not yet discovered:

`H _ N _ _ _ N`

+ Print the number of remaining attempts

`10`

+ Read a letter from stdin, and update the state of the game, subtracting an attempt if they guess an incorrect letter.

`A` *(input)*

`H A N _ _ A N`

`10`

+ Repeat until all letters are guessed or attempts reaches 0
* Use any language
* Fewest number of characters wins.
* Drawing the gallows is not necessary, but will earn you upvotes and kudos.

# Answer
> 6 votes
## Ruby 1.9, 134 132 120 117 108 107

Word list provided in ARGV. The words and the entered letters must match in case.

```
r=w=$*.sample
t=10
loop{puts [*w.tr(r,?_).chars]*' ',t
t>0&&r>''?w[l=STDIN.gets[0]]?r=r.tr(l,''):t-=1:exit}

```

# Answer
> 8 votes
Python 3.

```
from random,sys import *
w=choice(*argv)
L=set(w)
a=10
while L and a:
 print(" ".join("_"if x in L else x for x in w),a)
 try:L-=set(input()[0])
 except:a-=1

```

I prefer this one though: longer but nicer.

```
import random
w=random.choice(list(open("/usr/dict/words")))[:-1]
L=set(w)
a=10
while L and a:
 print(" ".join("_"if x in L else x for x in w),a)
 try:L.remove(input()[0])
 except:a-=1
print w

```

# Answer
> 8 votes
Darn, I thought it said "fewest number of lines wins." I'm not going to win any fewest-character contests here, but this Common Lisp program is only one line.

```
(let ((words (list "that" "help" "rent" "chair" "octopus" "monitor" "manual" "speakers" "onomatopoeia" "regardless" "irresponsible" "cornerstone"))) (let ((word (nth (random (length words)) words))) (format t "~a~%" (funcall (defun play (word current remaining-attempts) (progn (if (not (find #\_ current)) (return-from play "You win!")) (if (equalp remaining-attempts 0) (return-from play "You lose!")) (format t "~a~%~d~%" current remaining-attempts) (let ((guess (char (read-line) 0)) (index 0) (found nil)) (loop for letter across word do (if (equalp guess letter) (progn (setf (char current index) letter) (setf found t))) (setf   index (+ index 1))) (if found (play word current remaining-attempts) (play word current (- remaining-attempts 1)))))) word (map 'string #'(lambda (c) #\_) word) 10))))

```

# Answer
> 4 votes
c++ (-headers)

```
struct h{h(char a):b(a){}char operator()(char c,char d){return d!='_'?d:c==b?c:'_';}char b;};

int main(int a,char**b){
srand(time(0));string c=*(b+rand()%(a-1)+1),d(c.size(),'_'),e;
char f=10,g;
while(f){
cout<<"> ";cin>>g;e=d;
transform(c.begin(),c.end(),d.begin(),d.begin(),h(g));if(e==d)--f;
cout<<d<<endl<<(int)f<<endl;if(d==c)break;
}return 0;}

```

cat /usr/dict/words | xargs hangman

# Answer
> 2 votes
## Python

```
import random

DEFAULT_ATTEMPTS = 10

def print_word(word, uncovered):
    for c in word:
        if c not in uncovered:
            c = '_'
        print c,
    print ''

def get_letter():
    letter = None
    while letter is None:
        letter = raw_input('> ')
        if len(letter) != 1:
            print 'Letters must be 1 character.  Try again.'
            letter = None
    return letter

if __name__ == '__main__':
    import sys

    if len(sys.argv) != 2: sys.exit(1)
    with open(sys.argv[1], 'r') as f:
        words = [word.strip() for word in f.readlines() if word.strip()]

    word = random.choice(words)
    uncovered = set([' '])
    attempts = DEFAULT_ATTEMPTS

    while attempts > 0 and any(letter not in uncovered for letter in word):
        print_word(word, uncovered)
        print attempts

        letter = get_letter()
        if letter in uncovered:
            print 'You have already tried that letter.'
        elif letter in word:
            print 'You got it!'
        else:
            print 'Wrong!'
            attempts -= 1

        uncovered.add(letter)

    if attempts == 0:
        print 'You lose!',
    else:
        print 'You win!'
    print 'The phrase was "%s".' % word

```

I didn't really try for the fewest characters, just wanted to make it as small as possible without sacrificing anything.

# Answer
> 2 votes
Perl, 112 char. I feel like I can do better - perhaps I'll try again later

```
$_=$ARGV[rand@ARGV];$a=10;while($a&&/[a-z]/){print map/[A-Z]/?$_:'_',split'';$x=<STDIN>;chop$x;s/$x/$x/ig||$a--}

```

Words are given on the command line, letters typed upper case

# Answer
> 2 votes
**Clojure**

This is 400 bytes gzipped, which is still quite a lot, probably because of how Clojure handles mutable state.

```
(def m ["will" "work" "for" "food"])
(def w (nth m (rand-int (count m))))
(def *s* (atom (replicate (count w) "_")))
(def *a* (atom 10))

(defn g [s a]
  (str (apply str (interpose " " s)) "\n" a))

(loop [n (read-line)]
  (if (some (set n) w)
    (swap! *s* (fn [s]
                 (map
                   (fn [i]
                     (if (= n (str (nth w i)))
                       n
                       (nth s i)))
                   (range 0 (count s)))))
    (swap! *a* dec))

  (println (g (deref *s*) (deref *a*)))

  (if (and (< 0 (deref *a*)) (some #{"_"} (deref *s*)))
    (recur (read-line))))

```

# Answer
> 2 votes
C# 370

```
using System;namespace h{class P{static void Main(string[]a){int c=10,d,l;char y=' ';string w=a[new Random().Next(a.Length)];l=w.Length;char[]x=new char[l];for(d=-1;++d<l;x[d]='-');while(c>0){for(d=-1;++d<l;x[d]=(y==w[d]||x[d]!='-')?w[d]:x[d]);Console.WriteLine(new string(x)+" "+c);if(w==new string(x))return;y=Console.ReadKey(true).KeyChar;if(!w.Contains(y+""))c--;}}}

```

wordlist as argument

# Answer
> 1 votes
# VB.NET

~~I haven't tried shrinking it yet, but:~~
~~First shrinking:~~
Second shrinking (3759 characters):

```
Module Hangman
    Sub Main()
        Dim m As Int32, w = "banana|apple|pear|dog|cat|orange|monkey|programming|hangman".Split("|")(New Random().Next(9)), g = "", e = "", x, c As Char, f As Boolean, r = Sub(z) Console.Write(z), p = Sub(y, h) Console.SetCursorPosition(y, h), a = Sub() Console.Clear(), q = Function() Console.ReadKey(1), d = Sub()
                                                                                r("       +--------+S       |        |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S                |S   ---------------------".Replace("S", vbCrLf))
                                                                                p(0, 2)
                                                                                r(String.Join(vbCrLf, "    /------\S    | O   O|S    \  ... /S     ------ S        |   S        |   S        |   S        |   S -------+-------S        |   S        |   S        |   S       / \  S      /   \  S     /     \  S    /       \  ".Split("S").Take(m * 4)))
                                                                                End Sub
        Console.CursorVisible = 0
        Do
            a()
            d()
            p(30, 10)
            f = 0
            For Each x In w
                If g.Contains(x) Then
                    r(x)
                Else
                    r(" ")
                    f = 1
                End If
                Console.CursorTop += 1
                Console.CursorLeft -= 1
                r("_")
                Console.CursorTop -= 1
                r(" ")
            Next
            If Not f Then
                a()
                d()
                p(30, 10)
                r("You win! Press any key to close.")
                q()
                End
            End If
            p(30, 13)
            r(e)
            Do
                c = q().KeyChar
            Loop Until Char.IsLetter(c)
            If g.Contains(c) Then
                e = "You have already guessed that letter."
            Else
                g &= c
                If w.Contains(c) Then
                    e = "There is a" & If("aehilmnorsx".Contains(c), "n", "") & " """ & c & """ in the word."
                Else
                    e = "There is no """ & c & """ in the word. Try again."
                    m += 1
                End If
            End If
        Loop Until m = 4
        a()
        d()
        p(30, 10)
        r("You lose! Press any key to close.")
        q()
    End Sub
End Module

```

# Answer
> 0 votes
# Powershell, 125 bytes

```
$w=$h=$args|random|% t*y
for($n=10){$w-replace"[ $h]",'_'-join' ';$n
if(!$h+!$n){break}$n-=($c=Read-Host)-notin$h
$h=$h-ne$c}

```

Less golfed test script:

```
$f = {

$word=$hidden=$args|random|% toCharArray    # let $word and $hidden are a random word chars
#$word                                      # uncomment this to cheating
for($n=10){                                 # forever for with init section
    $word-replace"[ $hidden]",'_'-join' '   # display the word with hidden letters
    $n                                      # display $n
    if(!$hidden+!$n){break}                 # break loop if hidden array is empty or n equal to 0
    $n-=($c=Read-Host)-notin$hidden         # input $c from user, decrease $n if $c does not in $hidden array
    $hidden=$hidden-ne$c                    # recreate $hidden array with removed $c
}

}

$words = gc .\wordlist.txt
&$f $words

```

Output example when the guessing player has *lost*:

```
_ _ _ _ _ _ _ _
10
i
_ _ _ _ _ _ _ _
9
e
_ _ e _ _ _ _ e
9
o
o _ e _ _ o _ e
9
a
o _ e _ _ o _ e
8
q
o _ e _ _ o _ e
7
q
o _ e _ _ o _ e
6
q
o _ e _ _ o _ e
5
q
o _ e _ _ o _ e
4
q
o _ e _ _ o _ e
3
q
o _ e _ _ o _ e
2
q
o _ e _ _ o _ e
1
q
o _ e _ _ o _ e
0

```

Output example when the guessing player has *win*:

```
_ _ _ _ _ _ _ _ _ _
10
e
_ _ _ _ e _ _ _ _ _
10
o
_ o _ _ e _ _ _ _ _
10
i
_ o _ _ e _ _ i _ _
10
a
_ o _ _ e _ _ i a _
10
l
_ o _ _ e _ _ i a l
10
c
c o _ _ e _ c i a l
10
m
c o m m e _ c i a l
10
t
c o m m e _ c i a l
9
r
c o m m e r c i a l
9

```

---
Tags: code-golf, game, word-puzzle
---


title: Chop up my ASCII art

text:
# Question
Title: Chop up my ASCII art
Let's say I've got some ASCII art:

```
          ___
        ,"---".
        :     ;
         `-.-'
          | |
          | |
          | |
       _.-\_/-._
    _ / |     | \ _
   / /   `---'   \ \
  /  `-----------'  \
 /,-""-.       ,-""-.\
( i-..-i       i-..-i )
|`|    |-------|    |'|
\ `-..-'  ,=.  `-..-'/
 `--------|=|-------'
          | |
          \ \
           ) ) hjw
          / /
         ( (

```

(Source)

But I want to focus on the cable of this joystick, because I actually want a picture of a garden path, leading up to a door.

```
 ,=.
-|=|-
 | |
 \ \
  ) )
 / /
( (

```

I could copy out line after line, I could use a text editor with block selection mode, or... I could write some code!

So, my code needs five arguments:

* A piece of ASCII art, a newline separated string.
* The X axis of the top-left corner (1-indexed, from left hand column, positive integer)
* The Y axis of the top-left corner (1-indexed, from top row, positive integer)
* Width of the resultant image (positive integer)
* Height of the resultant image (positive integer)

## Test Cases

ASCII image:

```
          ___
        ,"---".
        :     ;
         `-.-'
          | |
          | |
          | |
       _.-\_/-._
    _ / |     | \ _
   / /   `---'   \ \
  /  `-----------'  \
 /,-""-.       ,-""-.\
( i-..-i       i-..-i )
|`|    |-------|    |'|
\ `-..-'  ,=.  `-..-'/
 `--------|=|-------'
          | |
          \ \
           ) ) hjw
          / /
         ( (

```

### Garden path

* X: 10
* Y: 15
* Width: 5
* Height: 7

Result:

```
 ,=.
-|=|-
 | |
 \ \
  ) )
 / /
( (

```

### DB icon

* X: 3
* Y: 12
* Width: 6
* Height: 4

Output:

```
,-""-.
i-..-i
|    |
`-..-'

```

### Alien Elder

* X: 9
* Y: 1
* Width: 7
* Height: 10

```
  ___
,"---".
:     ;
 `-.-'
  | |
  | |
  | |
.-\_/-.
|     |
 `---'
```

### Signature

* X: 16
* Y: 19
* Width: 3
* Height: 1

```
hjw
```

## Rules

# Answer
> 22 votes
# Canvas, 1 byte

Try it here!

It takes height, width, Y, X, and ASCII art as inputs, in that order.

Though almost everything about the ASCII art objects in Canvas is 0-indexed,  is 1-indexed by some reason. ¯\\\_(ツ)\_/¯

# Answer
> 7 votes
# Python 2, ~~64~~ 62 bytes

```
lambda I,x,y,w,h:[l[x-1:][:w]for l in I.split('\n')[y-1:][:h]]

```

Try it online!

---

If `X` and `Y` can be `0`-indexed:

# Python 2, 56 bytes

```
lambda I,x,y,w,h:[l[x:x+w]for l in I.split('\n')[y:y+h]]

```

Try it online!

# Answer
> 4 votes
# Charcoal, 7 bytes

```
δＪθηＴζε

```

Try it online! Link is to verbose version of code. Takes 0-indexed coordintaes. Explanation:

```
δ

```

Print the ASCII art.

```
Ｊθη

```

Jump to the top left corner of the desired rectangle.

```
Ｔζε

```

Trim the canvas to the desired size.

# Answer
> 3 votes
# 05AB1E, ~~21~~ 19 bytes

```
UV¶¡εXG¦}Y£}sG¦}s£»

```

Try it online!

Or if `0-indexing is allowed`:

# 05AB1E, 18 bytes

```
UV¶¡εX.$Y£}sF¦}s£»

```

Try it online!

# Answer
> 3 votes
# Pip `-n`, 21 bytes

```
_@>--b@<dM(a^n--c+,e)

```

Try it online!

Or, if 0-indexing is allowed...

## Pip `-n`, **17 bytes**:

```
_@>b@<dM(a^nc+,e)

```

Try it online!

### Explanation

Takes all five arguments as command-line args.

```
                   a-e are the 5 cmdline args; n is newline
         a^n       Split a on newlines
              ,e   Range(e)
            c+     Add c to each element
        (       )  Use the resulting range(c,c+e) to slice into the list of lines
       M           To each line, map this function:
_                   The line
 @>b                Slice, keeping indices b and greater
    @<d             Slice, keeping indices less than d
                   Print, joining on newlines (-n flag)

```

---

The above solutions also assume the input is a perfect rectangle--i.e., the lines are all the same length. Otherwise, 2 extra bytes are needed (use `-l` instead of `-n`):

```
(Z(a^nZDsb+,d)c+,e)      0-indexed, 19 bytes
(Z(a^nZDs--b+,d)--c+,e)  1-indexed, 23 bytes

```

# Answer
> 3 votes
# Japt `-R`, ~~13~~ 11 bytes

```
·tWÉY ®tVÉX

```

Try it

2 bytes saved thanks to Kamil Drakari

9 bytes if not for the unnecessary requirement that solutions use 1-based indexing.

```
·tWY ®tVX

```

---

## Explanation

```
                :Implicit input of string U and integers V=X, W=Y, X=Width & Y=Height
·               :Split U on newlines
 t              :Slice
  WÉ            : From 0-based index W-1
    Y           : To length Y
      ®         :Map
       t        :  Substring
        VÉ      :   From 0-based index V-1
          X     :   To length X
                :Implicitly join with newlines and output

```

# Answer
> 3 votes
# JavaScript (Node.js), ~~70~~ 69 bytes

-1 Thanks @Shaggy for the `splice()` idea.

```
(a,x,y,w,h)=>a.split`
`.map(q=>q.substr(x-1,w)).splice(--y,h).join`
`

```

Try it online!

The ASCII art given is annoying tbh

# Answer
> 2 votes
# , 45 bytes

```
f=:4 :0
'a b c d'=.x-#:10
y{~<(a+i.b);c+i.d
)

```

Try it online!

Notes:  accepts up to 2 arguments, left and right. The right argument is the ASCII art string, the left one - a list of U H X W values

I simulate the newline and the function call has a code to convert the string to an array.

# Answer
> 2 votes
# , 16 bytes

```
ÀGÀ|<C-v>@cl@djyHVGp

```

Try it online!

Input is expected to be padded with spaces to be a perfect rectangle. Also, the 'Y' input comes before the 'X'.

Hexdump:

```
00000000: c047 c07c 1640 636c 4064 6a79 4856 4770  .G.|.@cl@djyHVGp

```

# Answer
> 2 votes
# C (gcc), 118 109 bytes

The input can contain jagged lines: newlines are printed if they exist in the y-range.

Thanks to ceilingcat for the suggestion.

```
f(s,x,y,w,h,a,b,c)char*s;{for(b=1,a=0;*s;a=c?!b++:a,s++)((c=*s==10)|++a>=x&a-x<w)&b>=y&b-y<h-c&&putchar(*s);}

```

Try it online!

# Answer
> 1 votes
# Jelly, 11 bytes

```
Ỵṫ€¥ṫḣ€ḣ4ƭ/

```

Try it online!

Takes the ASCII-art as a Python multi-line r-string (so as to avoid problems with backslashes).

# Answer
> 1 votes
# Haskell, 61 bytes

```
(x#y)w h=unlines.map(take w.drop(x-1)).take h.drop(y-1).lines

```

Try it online!

Takes arguments in order: `x`, `y`, `w`, `h`, `s`.

# Answer
> 1 votes
# Bash \+ coreutils, 37

```
cut -b$1-$[$1+$3-1]|tail +$2|head -$4

```

Interestingly, GNU tail 8.28 (on Ubuntu 18.04) allows `+NUM` format, whereas GNU tail 8.29 on TIO requires 2 extra bytes for this `-n+NUM`.

Try it online!

I thought doing this all in `sed` might be shorter, but at 50 bytes its not:

```
sed -nr "$2,$[$2+$4-1]s/.{$[$1-1]}(.{,$3}).*/\1/p"

```

# Answer
> 1 votes
# , 62 bytes

Perhaps surprisingly short solution to a text challenge in R, because we don't need to actually read the whole text into a matrix.

```
function(x,y,w,h)write(substr(readLines()[y+1:h-1],x,x+w-1),1)

```

Try it online!

# Answer
> 1 votes
# K4, 31 bytes

**Solution:**

```
{[a;x;y;w;h]a .-1+(y;x)+!:'h,w}

```

**Examples:**

```
q)ASCII:("          ___";"        ,\"---\".";"        :     ;";"         `-.-'";"          | |";"          | |";"          | |";"       _.-\\_/-._";"    _ / |     | \\ _";"   / /   `---'   \\ \\";"  /  `-----------'  \\";" /,-\"\"-.       ,-\"\"-.\\";"( i-..-i       i-..-i )";"|`|    |-------|    |'|";"\\ `-..-'  ,=.  `-..-'/";" `--------|=|-------'";"          | |";"          \\ \\";"           ) ) hjw";"          / /";"         ( (")
q)k){[a;x;y;w;h]a .-1+(y;x)+!:'h,w}[ASCII;10;15;5;7]
" ,=. "
"-|=|-"
" | | "
" \\ \\ "
"  ) )"
" / / "
"( (  "
q)k){[a;x;y;w;h].[a;-1+(y;x)+!:'h,w]}[ASCII;3;12;6;4]
",-\"\"-."
"i-..-i"
"|    |"
"`-..-'"
q)k){[a;x;y;w;h].[a;-1+(y;x)+!:'h,w]}[ASCII;9;1;7;10]
"  ___  "
",\"---\"."
":     ;"
" `-.-' "
"  | |  "
"  | |  "
"  | |  "
".-\\_/-."
"|     |"
" `---' "
q)k){[a;x;y;w;h].[a;-1+(y;x)+!:'h,w]}[ASCII;16;19;3;1]
"hjw"

```

**Explanation:**

Take the 1-indexed input, generate the x/y coordinates and index into ascii art.

```
{[a;x;y;w;h]a .-1+(y;x)+!:'h,w} / the solution
{[a;x;y;w;h]                  } / lambda taking 5 inputs, a(scii), x, y, w(idth), h(eight)
                           h,w  / concatenate height and width, e.g. 7 5
                        !:'     / range til each, e.g. (0 1 2 3 4 5 6;0 1 2 3 4)
                  (y;x)+        / add list y x to it, e.g. (15 16 17 18 19 20 21;10 11 12 13 14)
               -1+              / subtract 1, e.g. (14 15 16 17 18 19 20;9 10 11 12 13)
            a .                 / index into a at these coordinates

```

# Answer
> 1 votes
# \\/\\/\>, 123 bytes

```
j:j8+}j+}j}pppp80x
{:}i:0(?v:a=?x@s1+:
~~~~1+0!/000y
yp:qqqq~
q{y?=p:+1q:}}g$q:pp:
1}x}p}ap:q~q+1{{y!?:-
ys{{
~!u.*2(0:;!?h

```

Input consists of a single line of space-delimited input variables `x`, `y`, `w`, and `h`, followed by the ascii art on the next line onward.

## Explanation

This code uses \\/\\/\>'s ability to self-modify by placing the ascii art in the code itself, which ends up looking like this:

It then grabs the characters in the specified rectangle off of the code and outputs it.

---
Tags: code-golf, ascii-art
---


title: Reverse and add degeneracy

text:
# Question
Title: Reverse and add degeneracy
# Intro

Reverse and add is as simple as it sounds, take `n` and add it to its digits in reverse order. (e.g. 234 + 432 = 666).

If you apply this process repeatedly some numbers will eventually hit a prime number, and some will never reach a prime.

# Example

I currently have

11431 rep.

```
11431 is not prime
11431 + 13411 = 24842 which is not prime
24842 + 24842 = 49684 which is not prime
49684 + 48694 = 98378 which is not prime
98378 + 87389 = 185767 which is prime!

```

This number hits a prime

In contrast any multiple of 3 will never hit a prime, this is because the all multiples of 3 have a digit sum that is a multiple of 3 and vice versa. Thus reverse and add on a multiple of 3 will always result in a new multiple of 3 and thus never a prime.

# Task

Take a positive integer `n` and determine if repeatedly reversing and adding will ever result in a prime number. Output a truthy or falsy value. Either truthy for reaches a prime and falsy value for does not or the other way around both are acceptable.

Prime numbers will be considered to reach a prime number in zero iterations.

This is so try to make your code as short as possible.

# Test Cases

True for reaches a prime false for never reaches a prime

```
11 -> True
11431 -> True
13201 -> True
13360 -> True
13450 -> True
1019410 -> True
1019510 -> True
22 -> False
1431 -> False
15621 -> False
14641 -> False

```

# Hint

While I was writing this challenge I discovered a cool trick that makes this problem a good deal easier. It is not impossible without this trick and it is not trivial with it either but it does help. I had a lot of fun discovering this so I will leave it in a spoiler below.

> Repeated reverse and add will always hit a multiple of 11 in 6 iterations or less. If it does not hit a prime before it hits a multiple of 11 it will never hit a prime.

# Answer
# Ruby, ~~84 79 77~~ 74 bytes

```
->x{y=1;x+="#{x}".reverse.to_i while(2...x).any?{|z|0==y=x%z}&&x%11>0;y>0}

```

Try it online!

> If I got it right, when we reach a multiple of 11 we can stop (we will only get multiples of 11 after that)
> 7 votes

# Answer
# Python 2, ~~123~~ 110 bytes

Saved 13 bytes thanks to Ørjan Johansen and Wheat Wizard!

```
n=input()
while 1:
 if all(n%m for m in range(2,n)):print 1;break
 if n%11==0:print 0;break
 n+=int(`n`[::-1])

```

Returns 1 if it reaches a prime, 0 if it doesn't. Try it online!
> 3 votes

# Answer
# Haskell, 65 bytes

`f` takes an `Integer` and returns a `Bool`. `True` means it reaches a prime.

```
f n=gcd(product[2..n-1])n<2||gcd 33n<2&&f(n+read(reverse$show n))

```

Try it online!

Unfortunately the short but inefficient prime test means that the OP's `True` test cases other than `11` grow too big to finish. But for example 11432 is a `True` case that does finish.

You can also try this 3 bytes longer one, for which TIO can finish all the `True` test cases:

```
f n=and[mod n i>0|i<-[2..n-1]]||gcd 33n<2&&f(n+read(reverse$show n))

```

Try it online!

Both versions' prime tests break on 1, but it so happens that it gets to a prime (2) anyway.

Otherwise, I noticed about the same thing as G.B. in the spoiler of the Ruby submission:

> Once a number grows to even length, the next iteration will be divisible by 11. Once a number is divisible by 11, so will all following iterations.
> 3 votes

# Answer
# Python 2, ~~78~~ ~~70~~ 69 bytes

```
f=lambda x:all(x%a for a in range(2,x))or x%11and f(x+int(`x`[::-1]))

```

Try it online!

# Explanation

This program relies on the fact that

> Every number that loss forever will reach a multiple of 11 in less than 6 moves

This program is a recursive lambda with circuited logical comparatives. It first checks if n is prime.

```
all(x%a for a in range(2,x))

```

If this is true we return true.

If it is false we check if it is a multiple of 11.

```
x%11

```

If false we return false otherwise we return the result of `f` on the next iteration

```
f(x+int(`x`[::-1]))

```
> 2 votes

# Answer
# Jelly, 11 bytes

```
ṚḌ$+$6Ð¡ÆPS

```

Try it online!
> 2 votes

# Answer
# 05AB1E, ~~14~~ 13 bytes

**EDIT**: Saved one byte because input is reused if there aren't enough elements on the stack

```
[Dp#D11Ö#R+]p

```

Try it online!

Uses the hint in the question

How it works

```
[              # begin infinite loop
               # implicit input
 D             # duplicate input
  p            # push primality of input
   #           # if prime, break
    D          # duplicate input
     11        # push 11
       Ö       # push input % 11 == 0
        #      # if multiple of 11, break
               # implicit push input
          R    # reverse input
           +   # add both numbers
            ]  # end infinite loop
             p # push primality of result; 1 if prime, 0 if multiple of 11
               # implicit print

```
> 1 votes

# Answer
# MATLAB, ~~88~~ 81 bytes

```
function r=f(n);r=0;for i=1:7 r=r+isprime(n);n=n+str2num(fliplr(num2str(n)));end;

```
> 0 votes

# Answer
## Microsoft Sql Server, 826 786\* bytes

* I've recalled about the IIF function that was introduced in Microsoft Sql Server 2012

```
set nocount on
use rextester
go
if object_id('dbo.n','IF')is not null drop function dbo.n
go
create function dbo.n(@ bigint,@f bigint)returns table as return
with a as(select 0 c union all select 0),b as(select 0 c from a,a t),c as(select 0 c from b,b t),
d as(select 0 c from c,c t),e as(select 0 c from d,d t),f as(select 0 c from e,e t),
v as(select top(@f-@+1)0 c from f)select row_number()over(order by(select 0))+@-1 n from v
go
with u as(select cast(a as bigint)a from(values(11),(11431),(13201),(13360),(13450),(1019410),(1019510),(22),(1431),
(15621),(14641))u(a)),v as(select a,a c from u union all select a,c+reverse(str(c,38))from v
where 0=any(select c%n from dbo.n(2,c/2))and c%11>0)select a,iif(0=any(select max(c)%n from dbo.n(2,max(c)/2)),0,1)
from v group by a option(maxrecursion 0)

```

Check it online

**The more neat formatting**

```
SET NOCOUNT ON;
USE rextester;
GO
IF OBJECT_ID('dbo.n', 'IF') IS NOT NULL DROP FUNCTION dbo.n;
GO
CREATE FUNCTION dbo.n(@ BIGINT,@f BIGINT)RETURNS TABLE AS RETURN
  WITH
    a AS(SELECT 0 c UNION ALL SELECT 0),
    b AS(SELECT 0 c FROM a,a t),
    c AS(SELECT 0 c FROM b,b t),
    d AS(SELECT 0 c FROM c,c t),
    e AS(SELECT 0 c FROM d,d t),
    f AS(SELECT 0 c FROM e,e t),
    v AS(SELECT TOP(@f-@+1)0 c FROM f)
    SELECT ROW_NUMBER()OVER(ORDER BY(SELECT 0))+@-1 n FROM v;
GO
WITH u AS(
  SELECT CAST(a AS BIGINT) a
  FROM(VALUES (11), (11431), (13201), (13360), (13450), (1019410), (1019510),
              (22), (1431), (15621), (14641)) u(a)
),
v AS(
  SELECT a, a c FROM u
    UNION ALL
  SELECT a, c + reverse(str(c, 38))
  FROM v
  WHERE 0 = ANY(SELECT c % n FROM dbo.n(2, c / 2)) AND c % 11 > 0
)
SELECT a, IIF(0 = ANY(SELECT MAX(c) % n FROM dbo.n(2, MAX(c) / 2)), 0, 1)
FROM v
GROUP BY a
OPTION (MAXRECURSION 0);

```
> 0 votes

# Answer
## JavaScript (ES6), 73 bytes

Returns `0` or `true`.

```
f=n=>{for(d=n;n%--d;);return d<2||n%11&&f(+[...n+''].reverse().join``+n)}

```

### Commented

This is based on the magic-spoiler formula described by Wheat Wizard.

```
f = n => {              // given n:
  for(d = n; n % --d;); // find the highest divisor d of n
  return                //
    d < 2 ||            // if this divisor is 1, return true (n is prime)
    n % 11 &&           // else: if 11 is a divisor of n, return 0
    f(                  // else: do a recursive call with
      +[...n + '']      // the digits of n
      .reverse().join`` // reversed, joined,
      + n               // coerced to a number and added to n
    )                   //
}                       //

```

### Test cases

I've removed the two largest inputs from the snippet, as they take a few seconds to complete. (But they do work as well.)

```
f=n=>{for(d=n;n%--d;);return d<2||n%11&&f(+[...n+''].reverse().join``+n)}

console.log(f(11))      // -> True
console.log(f(11431))   // -> True
console.log(f(13201))   // -> True
console.log(f(13360))   // -> True
console.log(f(13450))   // -> True
console.log(f(22))      // -> False
console.log(f(1431))    // -> False
console.log(f(15621))   // -> False
console.log(f(14641))   // -> False
```
> 0 votes

# Answer
# Mathematica, 45 bytes

```
Or@@PrimeQ@NestList[#+IntegerReverse@#&,#,6]&

```
> 0 votes

# Answer
# Jelly, 9 bytes

```
ṚḌ+Ɗ6Ð¡ẒẸ

```

Try it online!

### How it works

```
ṚḌ+Ɗ6Ð¡ẒẸ    Monadic main link.
ṚḌ+Ɗ         Monad: Reverse and add to original.
    6Ð¡      Repeatedly apply the above 6 times, collecting all iterations
       ẒẸ    Is any of them a prime?

```
> 0 votes

# Answer
PHP **114 bytes**

```
<?php function f($n){$n1=strrev((string)$n);$r=$n+(int)$n1;for($i=2;$i<$r;$i++){if($r%$i==0){die('0');}}die('1');}

```

More readable version:

```
<?php function f($n)
{
    $n1 = strrev((string)$n);
    $r = $n + (int)$n1;
    for ($i = 2; $i < $r; $i++) {
        if ($r % $i == 0) {
            die('0');
        }
    }
    die('1');
}

f(11431 );

```

Try it online!

I used this thing for counting bytes.
> 0 votes

---
Tags: code-golf, number-theory, decision-problem
---