# Generate the Chess Numbers™

I was browsing Stack Overflow when I saw this post in Puzzling in the hot network questions and decided to make a challenge out of it (all credit goes to the creator of the challenge).

## Overview

A Chess Number is a number that, when converted to base 18, results in a valid chess coordinate pair, where the first character is a-h and the second character is 1-8 (inclusive). Your job is to generate the full list of them, ordered. Output may be an array/list, printed individually, as a matrix/grid, or in a string. The numbers must be in decimal, not base 18.

## Examples

Here is a Python program to generate the full list:

def baseN(num, b, numerals = "0123456789abcdefghijklmnopqrstuvwxyz"):
return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])

for i in range(0, 10000):
s = baseN(i, 18)
if len(s) == 2 and s[0].isalpha() and s[1].isdigit() and 0 < int(s[1]) < 9:
print(i, s)


Try it online!

The complete list is:

181, 182, 183, 184, 185, 186, 187, 188, 199, 200, 201, 202, 203, 204, 205, 206, 217, 218, 219, 220, 221, 222, 223, 224, 235, 236, 237, 238, 239, 240, 241, 242, 253, 254, 255, 256, 257, 258, 259, 260, 271, 272, 273, 274, 275, 276, 277, 278, 289, 290, 291, 292, 293, 294, 295, 296, 307, 308, 309, 310, 311, 312, 313, 314


## Scoring

This is , shortest code in bytes wins

• Could you include the first few numbers in the post? Commented Dec 15, 2021 at 15:29
• 1st done, 2nd doing Commented Dec 15, 2021 at 15:31
• What format can the output be in? Commented Dec 15, 2021 at 15:34
• Is a two-dimensional array an acceptable form of output? (Displaying the numbers in an 8x8 grid seems thematically appropriate...) Commented Dec 15, 2021 at 16:13
• It is acceptable Commented Dec 15, 2021 at 16:26

# Jelly, 8 7 bytes

9Ṗ+pṖḅḤ


Try it online!

-1 byte thanks to Lynn by combining our answers, so make sure to upvote their answer as well!

## How it works

9Ṗ+pṖḅḤ - Main link. Takes no arguments
9       - Set the return value to 9, and execute with 9 on the left
Ṗ      - Pop, yielding [1,2,3,4,5,6,7,8]
+     - Add 9 to each: [10,11,12,13,14,15,16,17]
Ṗ   - Pop, yielding [1,2,3,4,5,6,7,8]
p    - Cartesian product: [[10,1],[10,2],...,[17,8]]
Ḥ - Unhalve; Yield 18
ḅ  - Unbase; Convert [a, b] to 18a+b

• Clever idea doing everything with 9! Our answers combine into a 7: 9Ṗ+pṖḅḤ
– lynn
Commented Dec 16, 2021 at 21:21
• @Lynn That's a clever trick with the base conversion! Commented Dec 17, 2021 at 16:44

# Python 3, 55 bytes

Edit: Was 56 bytes, now 55. Thanks to Dronir for proposing printing the numbers as a list.

Edit: Was 57 bytes, now 56. Thanks to Neil for proposing the -~j modification.

print([18*i-~j for i in range(10,18)for j in range(8)])


Try it online!

# Python 2, 53 bytes

Thanks to Kevin Cruijssen for propsing switching to Python 2 to save a couple of bytes.

print[18*i-~j for i in range(10,18)for j in range(8)]


Try it online!

• If you switch to Python 2 you can save a byte by removing the parenthesis around the print: 56 bytes. Commented Dec 15, 2021 at 16:56
• for j in range(8):print(18*i-~j) saves a byte.
– Neil
Commented Dec 15, 2021 at 17:35
• Printing a list comes to the same number of bytes: print([18*i-~j for i in range(10,18) for j in range(1,9)]) (56 bytes) Commented Dec 16, 2021 at 7:58
• @Dronir That doesn't seem for print the correct sequence. Commented Dec 16, 2021 at 14:05
• @Neil Thanks, I'll do that! Commented Dec 16, 2021 at 14:06

# R, 35 17 bytes

1:8+18*80:143%/%8


Try it online!

# Python 2, 37 36 bytes

x=64
while x:x-=1;print 314-x-x/8*10


Try it online!

1 byte saved thanks to loopy walt

# Jelly, 8 bytes

18⁵rṖp8ḅ


Try it online!

18         18
⁵r       Range from ⁵=10: [10..18]
Ṗ      Remove last element: [10..17] ([a..h])
p8    Cartesian product with [1..8]
ḅ   Convert from base 18


# R, 4425 22 bytes

x=180:313;x[x%%18<8]+1


Try it online!

• I think the () around 10:17 are unnecessary. Commented Dec 15, 2021 at 15:58
• 21 bytes Commented Dec 15, 2021 at 16:00
• 17 bytes? Commented Dec 15, 2021 at 16:13
• @Giuseppe - Go on, post it! I'm stuck at 22 so far with my own ideas... Commented Dec 15, 2021 at 16:18

# 05AB1E, 11 10 bytes

8Lã18δβƵz+


-1 byte thanks to @ovs.

Try it online.

A port of @JosephWalker's Python 3 answer is 11 bytes: 7ÝT+18*8LâO - Try it online.
A port of @Arnauld's JavaScript first answer is 12 bytes: ƵΔƵÖŸʒ<18%8‹ - Try it online.
A port of @GB's Ruby answer is 12 bytes as well: 63ÝD8÷T*ƵΘ++ - Try it online.
A port of @ovs' APL answer is 13 bytes: ƵgLD18%9›ÏƵη+ - Try it online.
A port of @Giuseppe's R answer is 14 bytes: 80ƵgŸ8÷18*8LÞ+ - Try it online.

Explanation:

8L         # Push a list in the range [1,8]
ã        # Create all possible pairs with the cartesian product
δ     # Map over each pair:
18 β    #  Convert it from a base-18 list to an integer
Ƶz+ # And add 162 to each
# (after which the result is output implicitly)


See this 05AB1E answer of mine (section How to compress large integers?) to understand why Ƶz is 162.

• 8Lã18δβƵz+ works for 10 bytes
– ovs
Commented Dec 15, 2021 at 19:10

# Ruby, 27 bytes

64.times{|x|p x+x/8*10+181}


Try it online!

# APL (Dyalog Unicode), 14 bytes

171+⍸9<18|⍳143


Try it online!

• equivalent BQN: 171+/9<18|↕144 Commented Dec 16, 2021 at 3:25

# BQN, 16 bytes

(181+⊢+18×⊣)⌜˜↕8


Run it online! Outputs an 8x8 array of numbers.

### Explanation

A port of my Pip solution.

(181+⊢+18×⊣)⌜˜↕8
↕8  Range(8)
(           )⌜˜    Generate a table, using that range twice, with this function:
18×⊣         18 times left argument
⊢+              plus right argument
181+                 plus 181


# APOL, 38 bytes

Port of Joeph Walker's genius answer, all credit goes to him.

ḟ(10 18 v(0 ∋) ḟ(1 9 p(*(18 +(∋ ⁰)))))

Sadly, APOL doesn't support nested for counters, so I have to use a clunkier solution. Maybe I'll implement them and come back to this later.

# JavaScript (V8), 35 bytes

Test modulo $$\18\$$.

for(n=180;n<314;)n++%18<8&&print(n)


Try it online!

# JavaScript (V8), 36 bytes

Expanding $$\[0\dots63]\$$ in reverse order to $$\[181\dots314]\$$.

for(n=64;n--;)print(314-(n>>3)*10-n)


Try it online!

# Husk, 12 bytes

ṠṪ+mo*18+9ḣ8


Try it online!

          ḣ8 # get the range from 1..8
Ṡ            # Ṡfgx = f(g(x),x)
# so we use the range 1..8 twice
# once directly as an argument to f
# and once after applying g to it
Ṫ+          # f = Ṫ+ = outer product by addition
mo*18+9   # g =
mo        #   map over each element
*18     #   and then multiply by 18

• Wow is that the S combinator?
– Neil
Commented Dec 15, 2021 at 21:02
• @Neil - "hookf (Ṡ) is a flipped S-combinator": Husk wiki Commented Dec 15, 2021 at 21:36

# Python 3 with NumPy, 62 5246 bytes

lambda:18*r_[10:18]+c_[1:9]
from numpy import*


Try it online!

Utilizing the option to return output in a 2d array. I'm a little fuzzy on how I/O is allowed in python so let me know if this is unacceptable / I need more boilerplate.

Thanks to loopy wait for r_ and c_

• Commented Dec 16, 2021 at 2:50

# APL+WIN, 24 bytes

18⊥(∊9+¨8/¨⍳8),[.1]64⍴⍳8


Try it online! Thanks to Dyalog Classic

# MathGolf, 12 bytes

8r♂+G*mÉ8╒+─


Try it online.

Explanation:

8r           # Push a list in the range [0,8)
♂+         # Add 10 to each to make the range [10,18)
G*       # Multiply each by 18
m      # Map over this list,
É     # Using 3 characters as inner code-block:
8╒   #  Push range [1,8]
+  #  Add the map-integer to each
─ # After the map: flatten the list of lists
# (after which the entire stack is output implicitly as result)


# Charcoal, 14 bytes

Ｉ⁺¹⁸¹Ｅ⁶⁴↨¹⁸↨ι⁸


Try it online! Link is to verbose version of code. I had three 15 byte solutions (including one which generated the range a1..h8 and converted them from base 18) but I was able to golf one of them down to 14. Explanation:

      ⁶⁴        Literal integer 64
Ｅ          Map over implicit range
ι   Current integer
↨ ⁸  Divmod by 8 using base conversion
↨¹⁸     Interpret as base 18
Ｉ               Cast to string
Implicitly print


# Pip, 13 bytes

181+18*_+BMC8


Use with some kind of list-formatting flag: -P and -S work well. Try it online!

### Explanation

181+18*_+BMC8
MC   Map the following function to coordinate pairs
8  from an 8x8 grid:
181+            181 plus
18*_        18 times the row number
+B      plus the column number


Here's a 16-byte solution that uses base conversion:

J_MzH8CP\,8FB:18
z              Lowercase alphabet
H8            First 8 characters
CP          Cartesian product with
\,8       1-based range up to 8
M               To each of the resulting pairs, map:
J_                 Join into a single string
FB:    Convert from base
18  18


You can run it at Replit, or a 17-byte version on TIO.

• When I got this in my inbox I was like, "How on Earth did you do this with Python's package manager?" ;) Commented Dec 15, 2021 at 17:53

# Wolfram Language (Mathematica), 23 bytes

18#+162+#2&~Array~{8,8}


Try it online!

Returns a 2d array.

# Clojure, 59 45 bytes

(map read-string(for[x"abcdefgh"y"12345678"](str"18r"x y)))

(for[x(range 10 18)y(range 1 9)](+(* 18 x)y))

# C, 64, 62 bytes

Thank you @JustinFinnerty for the improvement

j;main(i){for(i=9;++i%18;)while(++j%9)printf("%d ",i*18+j%9);}


Try it here!

Less golfed version:

i,j;
main(){
for(i=9;++i%18;)
while(++j%9)
printf("%d ",i*18+j%9);
}

• Good answer, but we can save one byte using "i=9;while(++i%18)" instead of "for(i=10;i-18;i++)" Commented Dec 18, 2021 at 11:13
• @JustinFinnerty you're right! Thank you! Commented Dec 18, 2021 at 13:19

# Retina 0.8.2, 37 bytes


63$*¶$.
.+
$*_181$*
_{8}
18$* %.  Try it online! Explanation:  63$*¶

$.  Insert the numbers from 0 to 63. .+$*_181$*  Convert to unary and add 181. _{8} 18$*


Add an extra 10 for each multiple of 8 in the original number.

%.


Convert to decimal.

# Desmos, 37 31 bytes

[a+bfora=[1...8],b=[10...17]18]


Try It On Desmos!

Try It On Desmos! - Prettified

Finally got a chance to utilize the new list comprehension feature in Desmos!

### Explanation:

[   for                       ]         initiate list comprehension for loop
a=[1...8],                       loop from a=1 to a=8, incrementing by 1
b=[10...17]18          loop from b=10*18 to b=17*18, incrementing by 18
(essentially creates a nested for loop)
a+b                                    calculate a+b


# Vyxal, 11 10 bytes

8:Ẋ18vβ⁺=+


Try it Online!

I actually didn't port anything for once lol 05ab1e porting go brrr.

## Explained

8:Ẋ18vβ⁺=+
8:Ẋ        # The cartesian product of the range(1, 9) and range(1, 9)
18vβ    # convert each pair from arbitrary base 18
⁺=+ # add 162 to each (128 + the index of = in the vyxal codepage)


## 11 bytes

8ƛ₀*9ɾM18vβ


Try it Online!

8ƛ₀*9ɾM18vβ
8ƛ          # For each item n in the range [1, 8]:
₀*        #   Mulitply n by 10
9ɾM     #   [[n * 10, x] for x in range(1, 10)]
18vβ #   and convert each from arbitrary base 18 to base 10


# Scratch, 112 bytes

Try it online!

Not much room for improvement

when gf clicked
set[N v]to(170
delete all of[C v
repeat(8
change[N v]by(10
repeat(8
change[N v]by(1


Commentated:

when gf clicked      Initiates code
set[N v]to(170       Sets N to 98 (in base-18)
delete all of[C v    Clears the list
repeat(8             Loops code for each column of the chessboard
change[N v]by(10     Increases the tens digit by 1 and decreases the ones digit by 8
repeat(8             Loops code for each row of the chessboard
change[N v]by(1      Increases the ones digit by 1


# X86-64 Machine Code, Microsoft Calling Convention, 27 bytes

33 C0                xor         eax,eax
B0 B5                mov         al,0B5h
B2 08                mov         dl,8
outerLoop:
B6 08                mov         dh,8
innerLoop:
89 01                mov         dword ptr [rcx],eax
48 83 C1 04          add         rcx,4
FF C0                inc         eax
FE CE                dec         dh
75 F4                jne         innerLoop
FE CA                dec         dl
75 EC                jne         outerLoop
C3                   ret


Which has the following function signature:

extern "C" void chessNumbers(uint32_t* out);


# Brachylog, 14 bytes

8⟦₁+₉ᶻ\↔ẋ~ḃ₁₈ᵐ


Try it online!

8⟦₁               Range [1..8]
+₉ᶻ            Add 9 to each element [[1,10],[2,11],..,[8,17]]
\↔          Transpose and swap [[10..17],[1..8]]
ẋ         Cartesian product [[10,1],[10,2]..]
~ḃ₁₈ᵐ    Convert each element from base 18



# Python 3, 53 bytes

b=181
while b<308:[print(b+x)for x in range(8)];b+=18


Try it online!

I believe this straightforward solution is currently the shortest vanilla Python 3 solution. :)

# Perl 5, 33 bytes

map{//;say$_+$'*18for 1..8}10..17


Try it online!

# SimpleTemplate 0.84, 163 bytes

This code simply outputs a space separated list of numbers.

{@setN 181}{@for to314}{@if_ matches"@18[2-8]|199|2([09][0-6]|3[5-9]|4[012]|5[3-9]|60|7[1-8]|89|9[0-6])|(21|30)[789]|(22|31)[0-4]@"}{@setN N,_}{@/}{@/}{@echoj" "N}


It looks yucky, but works!

## How it works?

The code loops from 0 to 314, and then verifies if the number matches the following regular expression:

@18[2-8]|199|2([09][0-6]|3[5-9]|4[012]|5[3-9]|60|7[1-8]|89|9[0-6])|(21|30)[789]|(22|31)[0-4]@


If it matches, it is added to the array of numbers we need.

The generated array looks like this:

[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[181,182],183],184],185],186],187],188],199],200],201],202],203],204],205],206],217],218],219],220],221],222],223],224],235],236],237],238],239],240],241],242],253],254],255],256],257],258],259],260],271],272],273],274],275],276],277],278],289],290],291],292],293],294],295],296],307],308],309],310],311],312],313],314]


And this is the final output:

181 182 183 184 185 186 187 188 199 200 201 202 203 204 205 206 217 218 219 220 221 222 223 224 235 236 237 238 239 240 241 242 253 254 255 256 257 258 259 260 271 272 273 274 275 276 277 278 289 290 291 292 293 294 295 296 307 308 309 310 311 312 313 314


The {@echo} will automatically flatten the array internally, before printing it.

## Ungolfed:

The code is pretty nasty to look at, so, here's an ungolfed version that does the same:

{@set numbers 181}

{@for i from 0 to 314}
{@if i matches "@18[2-8]|199|2([09][0-6]|3[5-9]|4[012]|5[3-9]|60|7[1-8]|89|9[0-6])|(21|30)[789]|(22|31)[0-4]@"}
{@set numbers numbers, i}
{@/}
{@/}

{@echo separator " " numbers}


There are a few things that are important to know to fully understand how it works.

• Almost all whitespace is optional.
• It is required to start with 181 in the variable.
If the variable isn't set to 181, the output will be incorrect, because the first value in the array will be null.
• The {@for to314} is the same as {@for i from 0 to 314}.
The variable is optional, and automatically assigns to _.
The from 0 isn't required, as the loop will automatically start from 0 to the final number.
• Both {@echo separator " " numbers} and {@echoj" "N} do the same:
Output the variable values separated by " ". The j stands for "join", in echoj.

## Running the code:

You can run the code on: http://sandbox.onlinephpfunctions.com/code/117ed06567a1d0e710e75b963566b86b510ca7ab

Please pick a version between 5.6 and 7.4.13. Can't fix the 8.0.0 compatibility issue without invalidating this answer.