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:

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

\$\begingroup\$Wow, this looks fun, I may try a Julia answer when i get home.\$\endgroup\$
– Magic Octopus UrnSep 21 '16 at 20:39

\$\begingroup\$Did you mean 2**31-1, or is your intent to be larger than most signed int types?\$\endgroup\$
– LinusSep 21 '16 at 21:54

\$\begingroup\$@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 a 25B chip in their image folder.)\$\endgroup\$
– Jonathan AllanSep 21 '16 at 21:58

Python 2.7, 282248 238 bytes

c=input();L=[]
for i in range(15):m=[5,1,25,5,1][i%5]*10**int("886665533322000"[i]);L+=[[c/m,i,"SVTILAMCOPYBGRW"[i]]];c%=m
L.sort();S=[]
while L[~1][0]:
s=""
for X in L[::-1]:
if X[0]>0:X[0]-=1;s+=X[2]
S+=[s]
for s in S[::-1]:print s

Explanation:
Fill list L with elements [quanity, chip_order, chip_character] indicating the quantity of each type of chip , where chip_order ensures chips of equal quantity get sorted in reverse order (higher value chips first). Take chips from L in reverse to build strings for each line. Print lines in reverse to get smallest lines on top.

\$\begingroup\$Great answer! However, there are a couple things you can do to golf it more. First, you can put multiple statements on one line by separating them by semicolons (but not statements that require indents after). Second, if you only use a variable once (like X, Y and S in the first for loop), you can just substitute the raw value to save some bytes. For more tips, check out codegolf.stackexchange.com/questions/54/…\$\endgroup\$
– BlueSep 22 '16 at 0:03

\$\begingroup\$Also, regular input will get you the integer w/o having to convert, and X[0]>0 can be shortened to X[0]\$\endgroup\$
– BlueSep 22 '16 at 0:07

\$\begingroup\$@Blue, thanks I hate python's input. I'll check the tips and see if I can come up with anything else.\$\endgroup\$
– LinusSep 22 '16 at 0:17

Your Answer

If this is an answer to a challenge…

…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.

…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

…Please make sure to answer the question and provide sufficient detail.

…Avoid asking for help, clarification or responding to other answers (use comments instead).

Code Golf Stack Exchange is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox.