20
Poker has etiquette in how you arrange your chips, often enforced in tournaments - your chips may not be "hidden" from your opponents by being behind others, mostly to not hide some large denomination chip(s).
The Challenge
We are going to be playing poker in ASCII, so we need to write a function or program that will draw our ASCII chip stack arrangement given its total value, n
.
Input
- A positive integer, n
(up to 2**32-1
should be handled)
Output
- An ASCII representation of the stack arrangement as defined below.
This may contain white-space to the right of each line such that no line is longer than one more character than the length used by printable characters in the longest (bottom) line;
This may contain a single trailing new line; and
The characters representing chips may be in lowercase if you prefer.
The stack arrangement will:
- Contain the fewest chips possible, given the denominations (see below);
- Will have equal valued chips in "stacks" (columns);
- Be ordered such that the shorter stacks are to the right of taller stacks; and
- Be ordered such that stacks with greater denomination chips will be to the right of equal sized stacks of lower denominations (representing that they are visible to our opponent(s) on the right)
The chips themselves are to be represented as individual characters identifying their colour:
White : 1 = W
Red : 5 = R
Green : 25 = G
Black : 100 = B
Yellow : 500 = Y
Pink : 1K = P
Orange : 5K = O
Cyan : 25K = C
Magenta : 100K = M
Aqua-blue : 500K = A
Lavender : 1M = L
Indigo : 5M = I
Turquoise : 25M = T
Violet : 100M = V
Silver : 500M = S
Example
For n = 276,352
the smallest number of chips would be:
2 * 100K + 3 * 25K + 1 * 1K + 3 * 100 + 2 * 25 + 2 * 1
MM CCC P BBB GG WW
The single P
must go on the far right,
then the three stacks of size 2
must go next,
- but the MM
must go furthest to the right followed by the GG
and then the WW
since 100K > 25 > 1
then the two stacks of size 3
go on the left,
- but the CCC
must go to the right of the BBB
since 25K > 100
Now we must place these chips into actual stacks, to make our output:
BC
BCWGM
BCWGMP
Test Cases
Input:
1
Output:
W
Input:
9378278
Output:
L
LWGPCM
LWGPCMB
LWGPCMBI
Input:
22222222
Output:
ROI
ROI
ROIWBPML
ROIWBPML
Input:
1342185143
Output:
WRCIV
WRCIVOLS
WRCIVOLSGBMT
Input:
2147483647
Output:
RMIS
RMISPC
RMISPCWL
RMISPCWLGBYOTV
Input:
4294967295
Output:
S
S
S
S
SRML
SRMLGOIT
SRMLGOITBPCV
SRMLGOITBPCVA
This is code-golf, so shortest code in bytes wins. No loopholes, yada yada, you know the drill.
Wow, this looks fun, I may try a Julia answer when i get home. – Magic Octopus Urn – 2016-09-21T20:39:53.773
Did you mean
2**31-1
, or is your intent to be larger than most signedint
types? – Linus – 2016-09-21T21:54:22.217@Linus hmm, I made it unsigned; I did actually specifically ask if the input range was OK in the sandbox and no one responded. As you can see
2**32-1
is a test case, but I'm willing to lower it. (Interesting fact: PokerStars has a25B
chip in their image folder.) – Jonathan Allan – 2016-09-21T21:58:54.723