Here's an ASCII pumpkin carved into a Jack-o-Lantern. Isn't it cute?
((^v^))
Here's an ASCII ghost. Look how spooky it is!
\{O.O}/
Obviously, the pumpkins have to be on the ground, with a space between them so they don't rot.
Ghosts, however, like to stand on top of pumpkins, so they're even spookier. However, they have to stand on two pumpkins, else their ghostly weight will crush the pumpkin beneath them. But, due to how their ghostly magic works, multiple ghosts can stack and share pumpkins, provided that the ghosts are either split evenly on the lower pumpkins or the lower ghosts. In other words, forming a shape like a human pyramid. Note that ghosts can't stack on ghosts unless there's a pumpkin underneath (that's how the magic works).
Given two non-negative integers, g
and p
, representing the number of g
hosts and p
umpkins, output the most-compact left-most formation possible, following the above pyramid stacking rules. Leftover pumpkins and ghosts (that is, those not forming the pyramid) go on the ground to the right.
For clarification, these formations are OK (blank newline separated), and serve as example I/O:
0p 1g
\{O.O}/
1p 0g
((^v^))
1p 1g
((^v^)) \{O.O}/
2p 1g
\{O.O}/
((^v^)) ((^v^))
2p 2g
\{O.O}/
((^v^)) ((^v^)) \{O.O}/
3p 1g
\{O.O}/
((^v^)) ((^v^)) ((^v^))
3p 2g
\{O.O}/ \{O.O}/
((^v^)) ((^v^)) ((^v^))
3p 3g
\{O.O}/
\{O.O}/ \{O.O}/
((^v^)) ((^v^)) ((^v^))
0p 4g
\{O.O}/ \{O.O}/ \{O.O}/ \{O.O}/
3p 0g
((^v^)) ((^v^)) ((^v^))
7p 6g
\{O.O}/
\{O.O}/ \{O.O}/
\{O.O}/ \{O.O}/ \{O.O}/
((^v^)) ((^v^)) ((^v^)) ((^v^)) ((^v^)) ((^v^)) ((^v^))
These formations are Not OK
\{O.O}/
((^v^))
\{O.O}/
((^v^))
((^v^)) ((^v^)) \{O.O}/
\{O.O}/
\{O.O}/
((^v^)) ((^v^))
\{O.O}/
\{O.O}/ ((^v^)) ((^v^))
((^v^))
((^v^)) ((^v^))
\{O.O}/
((^v^)) ((^v^))
Input
Two non-negative integers in any convenient format. At least one of the numbers will be non-zero. You can take the inputs in either order (i.e., in the examples I had pumpkins first) -- please specify how you take input in your answer.
Output
An ASCII-art representation of the ghosts and pumpkins, following the above rules. Leading/trailing newlines or other whitespace are optional, provided that the ghosts and pumpkins line up appropriately.
Rules
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.