Make An ASCII Poker Chip Stack Arrangement 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 &gt; 25 &gt; 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 &gt; 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.
JavaScript (ES6), 185 177 ... 171 bytes



f=(a,s='')=&gt;(a=(a[0]?a:[...(m='25455')+m+m].map((m,i)=&gt;(a-=(k=a/(v/=m)|0)*v,k*16+i),v=1E9).sort((a,b)=&gt;b-a)).map(n=&gt;n&gt;15&amp;&amp;(s+='SVTILAMCOPYBGRW'[n&amp;15],n-16)),s&amp;&amp;f(a)+`
`+s)


Formatted and commented

(a, s = '') =&gt; (                           // a = bankroll OR array of chip stacks
  a = (                                    // s = string of chip initials for this iteration
    a[0] ?                                 // if 'a' already is an array:
      a                                    // use it as-is
    :                                      // else, 'a' is the bankroll:
      [...(m = '25455') + m + m]           // for each 'm' in [ 2, 5, 4, 5, 5, ... ] (x3)
      .map((m, i) =&gt;                       // v = current chip value = previous value / m
        (                                  // k = floor(a / v) = number of these chips
          a -= (k = a / (v /= m) | 0) * v, // update remaining bankroll: a = a - k * v
          k * 16 + i                       // saved in array: chip index in bits 0-3
        ),                                 // and number of chips in bits 4+
        v = 1E9                            // initial chip value = 1 billion
      )                                    // (1B / 2 -&gt; 500M, 500M / 5 -&gt; 100M, etc.)
      .sort((a, b) =&gt; b - a)               // sort the chip stacks
  )                                        //
  .map(n =&gt;                                // for each chip stack:
    n &gt; 15 &amp;&amp;                              // if there's at least one remaining chip of
    (                                      // this kind:
      s += 'SVTILAMCOPYBGRW'[n &amp; 15],      // append its initial to the string
      n - 16                               // decrement the number of chips in this stack
    )                                      //
  ),                                       // process recursive call if there was at least
  s &amp;&amp; f(a) + '\n' + s                     // one non-empty chip stack (the next lines are
)                                          // appended at the beginning of the final string)


Demo



let f=(a,s='')=&gt;(a=(a[0]?a:[...(m='25455')+m+m].map((m,i)=&gt;(a-=(k=a/(v/=m)|0)*v,k*16+i),v=1E9).sort((a,b)=&gt;b-a)).map(n=&gt;n&gt;15&amp;&amp;(s+='SVTILAMCOPYBGRW'[n&amp;15],n-16)),s&amp;&amp;f(a)+`
`+s)

function update() {
  document.getElementById('o').innerHTML = f(+document.getElementById('i').value);
}
update();
&lt;input id="i" value="1342185143" oninput="update()"&gt;&lt;pre id="o"&gt;&lt;/pre&gt;