Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Totally random Catan number distributions

I like to play (The Settlers of) Catan on Board Game Arena with totally random number tokens. These tokens determine the production rate of the terrain tiles beneath:

There are 18 number tokens, two each of 3, 4, 5, 6, 8, 9, 10, 11 and one each of 2 and 12. A valid arrangement of these tokens on the board (19 hexes in a side-3 hexagon) has each token placed in exactly one hex, leaving one empty hex (the desert), and none of the 6 and 8 tokens adjacent. So a 6 cannot be adjacent to the other 6, an 8 cannot be adjacent to the other 8 and a 6 cannot be adjacent to an 8.

Task

Output a valid random arrangement of the number tokens. Each possible arrangement only needs a nonzero probability of being output.

You may output in any reasonable format, which may be 2D (like the valid and invalid outputs below) or 1D (e.g. mapping the hexes to a 19-character string in a fixed and consistent order). In either case it must be specified how the different positions in the output map to the hexagon. You may use any set of 11 different symbols to denote the number tokens or lack thereof.

This is ; fewest bytes wins.

Valid outputs

These use A B C for 10 11 12 respectively and . for the empty desert hex.

 6 3 8
 2 4 5 A
5 9 . 6 9
 A B 3 C
 8 4 B
 B 9 A
 5 6 C 8
6 4 B 5 3
 2 8 9 3
 A . 4
 B B C
 3 3 A A
2 4 6 . 6
 4 5 9 9
 8 5 8

Invalid outputs

This one has three 5s and only one 4:

 6 A 2
 C 5 9 3
8 B 3 6 A
 . 9 4 5
 5 B 8

The two 6s are adjacent here:

 5 2 4
 3 8 B 4
9 B 3 5 8
 A 6 9 C
 . 6 A

A 6 and an 8 are adjacent here:

 4 3 A
 . 8 2 5
4 6 A 8 B
 5 C 3 9
 B 6 9

Answer*

Draft saved
Draft discarded
Cancel
2
  • 2
    \$\begingroup\$ (1) There's an extra 7 in your code. (2) 1D formatting is acceptable as per the rules. \$\endgroup\$ Commented Nov 29, 2022 at 20:17
  • \$\begingroup\$ 325 bytes \$\endgroup\$ Commented Oct 6 at 8:55

AltStyle によって変換されたページ (->オリジナル) /