Koalas, Crabs, and Commapillars Given two positive integers X and Y, output any combination of the following three ASCII-art animals such that the output contains exactly X commas (,) and Y periods (.), if it is possible.


Koala: 1 comma, 2 periods

&lt;.,.&gt;

Crab: 2 commas, 2 periods

,&lt;..&gt;,

Commapillar: 3 or more commas, 1 period

&lt;,,,.&gt;


or &lt;,,,,.&gt; or &lt;,,,,,.&gt; or &lt;,,,,,,.&gt; or &lt;,,,,,,,.&gt; etc.


If no combination of these animals can produce exactly X commas and Y periods, output a single commaleon who will camouflage the failure:

~&lt;.,,&gt;~~


The output animals can be in any amounts and any order. They may be in a string, space or newline separated, or else in a list where each animal is one element.

For example, for X = 7, Y = 5, these would all be valid outputs (separated by empty lines):

&lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,.&gt;

&lt;.,.&gt;
&lt;,,,,,.&gt;
&lt;.,.&gt;

,&lt;..&gt;, &lt;.,.&gt; &lt;,,,,.&gt;

&lt;,,,,.&gt;
,&lt;..&gt;,
&lt;.,.&gt;

,&lt;..&gt;, &lt;,,,.&gt; ,&lt;..&gt;,

[",&lt;..&gt;,", ",&lt;..&gt;,", "&lt;,,,.&gt;"] (list syntax depends on language)


Note that (at least in this example) there are multiple sets of animals than can work. But remember you only need to output any one valid solution, if one exists. The number of animals or number of distinct animals does not matter.

For inputs such as X = 3, Y = 3 or X = 1, Y = 5 where there is no solution, the output will always be

~&lt;.,,&gt;~~


perhaps in a single-element list.

The shortest code in bytes wins.
Ruby, 139 bytes
Lambda function, takes x and y as arguments and returns a string
-&gt;x,y{c=y-2*n=y-(x&gt;y ?1:0)&gt;&gt;1
x+=-c/2*s=[x-n,c*3].max
x&lt;n||x&gt;n*2?'~&lt;.,,&gt;~~':',&lt;..&gt;, '*(x-n)+'&lt;.,.&gt; '*(2*n-x)+&quot;&lt;%s.&gt; &quot;*c%[?,*s-=c/2*3,?,*3]}

If a solution exists, it can be done with all koalas+commapillars or all koalas+crabs.
The principle is to use a minimum of commapillars. If the number is odd, we use 1 commapillar. if even we use 0 commapillars, unless there are more commas than periods, in which case we use 2.
The number of periods used in noncommapillars (crabs + koalas) is necessarily even, and the number of noncommapillars is half (number of periods)-(number of commapillars). If there are insufficient commas for all koalas, or too many for all crabs, no solution is possible. Otherwise, we return a solution.
Commented in test program
uses &quot;fail&quot; instead of chameleon for clarity
f=-&gt;x,y{c=y-2*n=y-(x&gt;y ?1:0)&gt;&gt;1
#n=noncommapillars=y&gt;&gt;1 as they have 2 periods. c=commapillars=y-2*n, 1 for odd y, 0 for even y.
#if x&gt;y there are too many commas to have 0 commapillars for even y. noncommapillars= y-1 &gt;&gt; 1, so 2 commapillars

x+=-c/2*s=[x-n,c*3].max
# s=number of commas allocated to commapillars. x-n to allow all noncommapillars to be koalas, but at least 3 per commapillar.
#-c/2 == -1 if there are commapillars, 0 if not (Ruby truncates toward -inf). Subtract commas for commapillars from x if necessary

x&lt;n||x&gt;n*2?'fail':',&lt;..&gt;, '*(x-n)+'&lt;.,.&gt; '*(2*n-x)+&quot;&lt;%s.&gt; &quot;*c%[?,*s-=c/2*3,?,*3]}
#if x&lt;n (insufficient commas for all koalas) or x&gt;n*2 (too many for all crabs) return fail. Else...
#return string off crabs, koalas, and (using % operator like sprintf) c commapillars (0..2), the second with 3 commas (if present) and the first with the rest.  



10.times{|j|10.times{|i|puts &quot;%-20s %s&quot;%[?.*j+?,*i,f[i,j]]}}
#all x,y from 0..9

Output
,                    fail
,,                   fail
,,,                  fail
,,,,                 fail
,,,,,                fail
,,,,,,               fail
,,,,,,,              fail
,,,,,,,,             fail
,,,,,,,,,            fail
.                    fail
.,                   fail
.,,                  fail
.,,,                 &lt;,,,.&gt;
.,,,,                &lt;,,,,.&gt;
.,,,,,               &lt;,,,,,.&gt;
.,,,,,,              &lt;,,,,,,.&gt;
.,,,,,,,             &lt;,,,,,,,.&gt;
.,,,,,,,,            &lt;,,,,,,,,.&gt;
.,,,,,,,,,           &lt;,,,,,,,,,.&gt;
..                   fail
..,                  &lt;.,.&gt;
..,,                 ,&lt;..&gt;,
..,,,                fail
..,,,,               fail
..,,,,,              fail
..,,,,,,             &lt;,,,.&gt; &lt;,,,.&gt;
..,,,,,,,            &lt;,,,,.&gt; &lt;,,,.&gt;
..,,,,,,,,           &lt;,,,,,.&gt; &lt;,,,.&gt;
..,,,,,,,,,          &lt;,,,,,,.&gt; &lt;,,,.&gt;
...                  fail
...,                 fail
...,,                fail
...,,,               fail
...,,,,              &lt;.,.&gt; &lt;,,,.&gt;
...,,,,,             &lt;.,.&gt; &lt;,,,,.&gt;
...,,,,,,            &lt;.,.&gt; &lt;,,,,,.&gt;
...,,,,,,,           &lt;.,.&gt; &lt;,,,,,,.&gt;
...,,,,,,,,          &lt;.,.&gt; &lt;,,,,,,,.&gt;
...,,,,,,,,,         &lt;.,.&gt; &lt;,,,,,,,,.&gt;
....                 fail
....,                fail
....,,               &lt;.,.&gt; &lt;.,.&gt;
....,,,              ,&lt;..&gt;, &lt;.,.&gt;
....,,,,             ,&lt;..&gt;, ,&lt;..&gt;,
....,,,,,            fail
....,,,,,,           fail
....,,,,,,,          &lt;.,.&gt; &lt;,,,.&gt; &lt;,,,.&gt;
....,,,,,,,,         &lt;.,.&gt; &lt;,,,,.&gt; &lt;,,,.&gt;
....,,,,,,,,,        &lt;.,.&gt; &lt;,,,,,.&gt; &lt;,,,.&gt;
.....                fail
.....,               fail
.....,,              fail
.....,,,             fail
.....,,,,            fail
.....,,,,,           &lt;.,.&gt; &lt;.,.&gt; &lt;,,,.&gt;
.....,,,,,,          &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,.&gt;
.....,,,,,,,         &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,.&gt;
.....,,,,,,,,        &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,,.&gt;
.....,,,,,,,,,       &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,,,.&gt;
......               fail
......,              fail
......,,             fail
......,,,            &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt;
......,,,,           ,&lt;..&gt;, &lt;.,.&gt; &lt;.,.&gt;
......,,,,,          ,&lt;..&gt;, ,&lt;..&gt;, &lt;.,.&gt;
......,,,,,,         ,&lt;..&gt;, ,&lt;..&gt;, ,&lt;..&gt;,
......,,,,,,,        fail
......,,,,,,,,       &lt;.,.&gt; &lt;.,.&gt; &lt;,,,.&gt; &lt;,,,.&gt;
......,,,,,,,,,      &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,.&gt; &lt;,,,.&gt;
.......              fail
.......,             fail
.......,,            fail
.......,,,           fail
.......,,,,          fail
.......,,,,,         fail
.......,,,,,,        &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,.&gt;
.......,,,,,,,       &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,.&gt;
.......,,,,,,,,      &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,.&gt;
.......,,,,,,,,,     &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,,.&gt;
........             fail
........,            fail
........,,           fail
........,,,          fail
........,,,,         &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt;
........,,,,,        ,&lt;..&gt;, &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt;
........,,,,,,       ,&lt;..&gt;, ,&lt;..&gt;, &lt;.,.&gt; &lt;.,.&gt;
........,,,,,,,      ,&lt;..&gt;, ,&lt;..&gt;, ,&lt;..&gt;, &lt;.,.&gt;
........,,,,,,,,     ,&lt;..&gt;, ,&lt;..&gt;, ,&lt;..&gt;, ,&lt;..&gt;,
........,,,,,,,,,    &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,.&gt; &lt;,,,.&gt;
.........            fail
.........,           fail
.........,,          fail
.........,,,         fail
.........,,,,        fail
.........,,,,,       fail
.........,,,,,,      fail
.........,,,,,,,     &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,.&gt;
.........,,,,,,,,    &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,.&gt;
.........,,,,,,,,,   &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;.,.&gt; &lt;,,,,,.&gt;