[Question]
  [
# Objective
Given an input list of `6` distinct digits, find 3 numbers `a`, `b` and `c` such that `a × b = c`, with `a` having 2 digits, `b` having 1 digit and `c` having 3 digits. In a more visual way, your program must arrange those 6 digits in the boxes of this image:
[![enter image description here](https://i.stack.imgur.com/3veFP.jpg)](https://i.stack.imgur.com/3veFP.jpg)
If more than one solution exists, you may output any of them.
# Input
6 distinct digits. You may take them in any reasonable way for your language.
# Output
The 3 numbers `a`, `b` and `c`. The output format is relatively free, as long as the 3 numbers are separated and are always printed in the same order (but not necessarily in the order `a, b, c`).
# Test Cases
```
1, 2, 3, 4, 5, 6 -> 54,3,162  
2, 3, 4, 5, 6, 7 -> 57,6,342 or 52,7,364
```
# Scoring
The shortest code in bytes wins.
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog) (2), 10 bytes
```
p~c₃o.k×~t
```
[Try it online!](https://tio.run/nexus/brachylog2#@19Ql/yoqTlfL/vw9LqS///NjIz/RwEA "Brachylog – TIO Nexus")
Far too slow to run in a reasonable length of time (the Brachylog interpreter spends a long time doing multiplications on empty strings, 4-digit numbers, negative numbers etc. using a very slow constraint solver). The TIO link uses an input with only 3 digits (this program can handle input with any number of digits). This is a function whose input is a number containing all the digits required (e.g. `234567`) – the lack of duplicates in the input means that you can always just put any `0` at the end to avoid a leading zero – and whose output is a list in the order `[b, a, c]` (e.g. `[6, 57, 342]`).
## Explanation
```
p~c₃o.k×~t
p           Permute the digits of the input
 ~c₃        Split them into three groups
    o       Sort the three groups
     .      to produce the output, which must have the following property:
      k     all but the last group
       ×    when multiplied together
        ~t  produces the last group
```
So where did the requirement on the groups to be 2, 1, and 3 digits go? Well, we know there are 6 digits in the input, and the groups are in sorted orders. The only possible sizes they can have, therefore, are [1, 1, 4], [1, 2, 3], or [2, 2, 2]. The first case is impossible (you can't multiply two 1-digit numbers to produce a 4-digit number, as 9×9 is only 81), as is the last case (you can't multiply two 2-digit numbers to produce a 2-digit number, as even 10×10 produces 100). Thus, the return values `[b, a, c]` must be 1, 2, and 3 digits long in that order, so `a` is 2 digits, `b` is 1 digit, and `c` is 3 digits, as requested.
[Answer]
## JavaScript (ES6), ~~90~~ 88 bytes
Takes input as an array of 6 digits. Returns a string describing a possible solution (such as `'54*3==162'`) or exits with a 'too much recursion' error if (and only if) there's no solution.
```
f=(a,k=1)=>eval(s='01*2==345'.replace(/\d/g,n=>a[n],a.sort(_=>(k=k*2%3779)&2)))?s:f(a,k)
```
### How it works
This is a deterministic algorithm.
The primes `P=2` and `Q=3779` were chosen in such a way that the sort callback `(k = k * P % Q) & 2` is guaranteed to generate all 720 possible permutations of the input array over time. More precisely, all permutations are covered after 2798 sorts -- which should be within the recursion limit of all browsers.
We inject each permutation in the expression `01*2==345` by mapping the digits to the corresponding entries in the array.
We evaluate this expression and do recursive calls until it's true.
### Test
```
f=(a,k=1)=>eval(s='01*2==345'.replace(/\d/g,n=>a[n],a.sort(_=>(k=k*2%3779)&2)))?s:f(a,k)
console.log(f([1,2,3,4,5,6])); // 54*3==162
console.log(f([2,3,4,5,6,7])); // 52*7==364
console.log(f([1,2,3,4,6,7])); // 73*2==146
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 17 bytes
```
p~c[Ċ,I,Ṫ]cᵐ.k×~t
```
[Try it online!](https://tio.run/nexus/brachylog2#@19Qlxx9pEvHU@fhzlWxyQ@3TtDLPjy9ruT//2gjHWMdEx1THTMd89j/UQA "Brachylog – TIO Nexus")
### Explanation
```
p                   Try a permutation of the Input
 ~c[Ċ,I,Ṫ]          Deconcatenate it; the result must be a list of the form [[_,_],_,[_,_,_]]
          cᵐ.       Output is the list of integers you get when mapping concatenate on the
                      previous list
             k×~t   The first two ints of the Output, when multiplied, result in the third
                      int of the Output
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 13 bytes
Saved two bytes thanks to *Emigna*!
```
œJvy3L£Â`*Qi,
```
Uses the **CP-1252** encoding. [Try it online!](https://tio.run/nexus/05ab1e#@390sldZpbHPocWHmxK0AjN1/v@PNtJRMNZRMNFRMNVRMNNRMI8FAA "05AB1E – TIO Nexus")
Explanation:
```
œ                 # Get all permutations of the input
 J                # Join them to get the numbers
  vy              # For each element in the list..
    3L            #   Push the list [1, 2, 3]
      £           #   Pops a and pushes [a[0:1], a[1:3], a[3:6]]
       Â`         #   Bifurcate and flatten
         *        #   Multiply the top two elements in the stack
          Qi      #   If equal to the third element..
            ,     #     Print the array
```
[Answer]
# Bash + coreutils, 70
```
for((b=1;b;));{
a=`shuf -ze $@`
b=${a:0:2}*${a:2:1}-${a:3:3}
}
echo $b
```
No particularly easy way to generate all the permutations. Instead randomly generate permutations and calculate until we find a good one.
Output is in the form `A*B-C` - i.e. the expression that will evaluate to zero when we have the correct permutation.
[Try it online](https://tio.run/nexus/bash#@5@WX6ShkWRraJ1kralpXc2VaJtQnFGapqBblaqg4pDAlWSrUp1oZWBlVKsFYhhZGdbqghjGVsa1XLVcqckZ@QoqSf///zdSMFYwUTBVMFMw/5qXr5ucmJyRCgA).
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 23 bytes
```
qm!{3/)2/+:i}%{(\:*=}=p
```
[Try it online!](https://tio.run/nexus/cjam#@1@Yq1htrK9ppK9tlVmrWq0RY6VlW2tb8P@/oZGxiakZAA "CJam – TIO Nexus")
[Answer]
# [Python 2](https://docs.python.org/2/), 105 bytes
```
lambda s:[(x[0],x[1:3],x[3:])for x in permutations(s)if eval('%s*%s%s==%s%s%s'%x)]
from itertools import*
```
[Try it online!](https://tio.run/nexus/python2#FcVLCsMgEADQfU8xG1FDF23TDwiexLqwNMJAdMSZFG@fks172b/3NZXPNwG7YEa4xPMIVzcfzS7aTB0GYIW29LJJEqTKhi1mWH5pNVrxpFix94eKtRo2nnKnAihLF6KVAUujLtPeOlYx2WBtmxhr7a5v8/3xfOk/ "Python 2 – TIO Nexus")
# 88 bytes solution with a more *flexible* output
```
lambda s:[x for x in permutations(s)if eval('%s*%s%s==%s%s%s'%x)]
from itertools import*
```
[Try it online!](https://tio.run/nexus/python2#FcRLCgMhDADQfU@RjWhm2S8UPEnbhaUKATWSZIq3t/QtXonPVVN7fxLo/TGhsMAE6jCytN2SEXcNilQgf1MN3unm1GmM/516N/F1KMINyLIYc1WgNlhsW0OoWyiB@tgtIOLyx9P5cr35Hw "Python 2 – TIO Nexus")  
where the output would be ['6', '5', '7', '3', '4', '2'] instead '6', '57', '342'
[Answer]
# PHP, 110 bytes
It'll get there... eventually...
```
<?$v=$argv;unset($v[0]);do shuffle($v)&[$a,$b,$c,$d,$e,$f]=$v;while("$a$b"*$c!="$d$e$f");echo"$a$b $c $d$e$f";
```
Ungolfed:
```
<?
$v=$argv;
unset($v[0]);
do
  shuffle($v);
  [$a,$b,$c,$d,$e,$f]=$v;
while("$a$b"*$c!="$d$e$f");
echo"$a$b $c $d$e$f";
```
[Answer]
# PHP, 77 bytes
```
for(;;)eval(strtr('0.*1-"428"||die("0.,1,428");',1/7,str_shuffle($argv[1])));
```
Takes input as a string.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 18 bytes
17 bytes of code, +1 for `-S` flag.
```
$/_=1FI_^@3,5MPMa
```
Takes input as a string of digits via command-line argument. Output is in the order c, b, a. [Try it online!](https://tio.run/nexus/pip#@6@iH29r6OYZH@dgrGPqG@Cb@P//fyNjE1Mz8/@6wQA "Pip – TIO Nexus")
This code outputs *all* solutions if multiple exist. If it is required to output only *one* solution, then add three bytes and wrap the program in `(...0)`.
### Explanation
```
                   a is 1st cmdline arg (implicit)
              PMa  Compute all permutations of a
             M     To each, map this function:
          3,5       Range(3,5)--contains values 3 and 4
       _^@          Split the function argument at those indices
                    This transforms a string like 342657 into a list [342; 6; 57]
     FI            Now filter the list of split permutations on this function:
$/_                 Fold on division: takes 1st element and divides it by the rest
   =1               Compare the quotient with 1
                    This keeps only the permutations where the first number is the product
                    of the other two
                   Autoprint the list (implicit), with each sublist on a separate line
                   and space-separated (-S flag)
```
[Answer]
## Ruby, 60 bytes
```
->x{x.permutation{|a|(eval a="%d%d*%d==%d%d%d"%a)&&puts(a)}}
```
Prints all solutions as "a\*b==c"
### Example:
```
->x{x.permutation{|a|(eval a="%d%d*%d==%d%d%d"%a)&&puts(a)}}[[1,2,3,4,5,6]]
54*3==162
->x{x.permutation{|a|(eval a="%d%d*%d==%d%d%d"%a)&&puts(a)}}[[2,3,4,5,6,7]]
52*7==364
57*6==342
```
[Answer]
# ES6 (Javascript), ~~85~~, ~~82~~, 79 bytes
Accepts an array of digits (strings), returns a 3-element array `[A,B,C]` => `C=A*B`
**Golfed**
```
R=(w,[a,b,c,d,e,f]=w)=>f*(d+=e)^(a+=b+c)?R(w.sort(_=>Math.random()-.5)):[a,d,f]
```
EDITS:
* Saved 3 more bytes by reusing `d` and `a`, and getting rid of `==` (Thanks @Arnauld !)
* Saved 3 bytes using destructuring assignment
**Try It !**
```
R=(w,[a,b,c,d,e,f]=w)=>f*(d+=e)^(a+=b+c)?R(w.sort(_=>Math.random()-.5)):[a,d,f];
function generate(A) {
   console.log(R([...A]));
}
```
```
<input type="text" id="A" value="123456"/><button onclick="generate(A.value)">GENERATE</button>
```
[Answer]
## Batch, 305 bytes
```
@echo off
set/pd=
for /l %%i in (0,1,719)do set n=%%i&call:c
exit/b
:c
set t=%d%
set s=
for /l %%j in (6,-1,1)do set/ap=n%%%%j,n/=%%j&call:l
set s=%s:~0,2%*%s:~2,1%-%s:~3%
set/an=%s%
if %n%==0 echo %s%
exit/b
:l
call set u=%%t:~%p%%%
call set s=%%s%%%%u:~,1%%
call set t=%%t:~,%p%%%%%u:~1%%
```
Takes input on STDIN as a string `[1-9]{6}` and outputs all solutions in `dd*d-ddd` format. Batch isn't very good at string manipulation so generating the 720 permutations is a little awkward.
]