[Question]
  [
A neat trick is if you ever need a nine-sided die, it is possible to make one using two six-sided dice using the numbers below. This is assuming you either have a way to rewrite the faces on the dice, or use some algorithm to map the numbers on a normal die onto these new numbers.
```
  0 0 3 3 6 6
  -----------
1|1 1 4 4 7 7 
1|1 1 4 4 7 7
2|2 2 5 5 8 8
2|2 2 5 5 8 8
3|3 3 6 6 9 9 
3|3 3 6 6 9 9
```
The challenge is:
* You are given two fair dice, die1 with A faces and die2 with B faces, where A may not necessarily equal B. You need to write numbers on the faces of those dice to create a "target die" with N faces. The numbers of the faces of die1 and die2 will be such that, if rolled and their results summed, it would yield a fair target die. The new numbers written on the dice must greater than or equal to zero (that is, no negative numbers can be on the new dice).
* Results should be a list (or whatever appropriate and reasonable format) of new faces for both die1 and die2. The numbers in those lists are not required to be in any sorted order.
* Assume A, B, and N are all given as positive integers, and that N is a divisor of A\*B.
* The target die is a regular, fair die with numbers 1 to N on its faces.
* If there are multiple solutions (such as when creating a one-sided die), you only need to return one solution from any of the possible solutions.
## Examples
```
input:                     input:
die1 = 6                   die1 = 5
die2 = 6                   die2 = 12
target = 9                 target = 20
output:                    output:
[0,0,3,3,6,6]              [1,2,3,4,5]
[1,1,2,2,3,3]              [0,0,0,5,5,5,10,10,10,15,15,15]
input:                     input:
die1 = 6                   die1 = 12
die2 = 4                   die2 = 12
target = 8                 target = 18
output:                    output:
[0,0,0,4,4,4]              [1,1,2,2,3,3,4,4,5,5,6,6]
[1,2,3,4]                  [0,0,0,0,6,6,6,6,12,12,12,12]
```
Normal code golf rules apply. Shortest answer in bytes wins.
  
[Answer]
# [Python](https://www.python.org) NumPy, 67 bytes
```
lambda n,m,o:(x:=r_[:n]*m%o,r_[:m]%(o-max(x))+1)
from numpy import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3nXMSc5NSEhXydHJ18q00Kqxsi-KjrfJitXJV83VAzNxYVY183dzECo0KTU1tQ02utKL8XIW80tyCSoXM3IL8ohItqFGuBUWZeSUaaRpmOmY6lpqaXDC-qY6hkY6RAZKImY6JjgUSHygPQiAhiGELFkBoAA)
# [Python](https://www.python.org), 77 bytes
```
lambda n,m,o,r=range:(x:=[a*m%o for a in r(n)],[b%(o-max(x))+1for b in r(m)])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3fXMSc5NSEhXydHJ18nWKbIsS89JTrTQqrGyjE7VyVfMV0vKLFBIVMvMUijTyNGN1opNUNfJ1cxMrNCo0NbUNQbJJENlczVhNqKGuBUWZeSUaaRpmOmY6lpqaXDC-qY6hkY6RAZKImY6JjgUSHygPQiAhiGELFkBoAA)
Just saw that output is not required to be sorted.
### [Python](https://www.python.org) NumPy, 75 bytes
```
lambda n,m,o:(x:=sort(r_[:n]*m%o),r_[:m]*(o-x[-1])//m+1)
from numpy import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3vXMSc5NSEhXydHJ18q00Kqxsi_OLSjSK4qOt8mK1clXzNXVA7NxYLY183YpoXcNYTX39XG1DTa60ovxchbzS3IJKhczcAqAmLaiRrgVFmXklGmkaZjpmOpaamlwwvqmOoZGOkQGSiJmOiY4FEh8oD0IgIYhhCxZAaAA)
### [Python](https://www.python.org), 85 bytes
```
lambda n,m,o,r=range:(x:=sorted(a*m%o for a in r(n)),[b*(o-x[-1])//m+1for b in r(m)])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3Q3MSc5NSEhXydHJ18nWKbIsS89JTrTQqrGyL84tKUlM0ErVyVfMV0vKLFBIVMvMUijTyNDV1opO0NPJ1K6J1DWM19fVztQ1B8kkQ-VzNWE2o4a4FRZl5JRppGmY6ZjqWmppcML6pjqGRjpEBkoiZjomOBRIfKA9CICGIYQsWQGgA)
[Answer]
# JavaScript (ES6), 116 bytes
Expects `(die1,die2)(target)`.
```
(a,b,d=b+1)=>g=c=>c%--d||a%d&&b%d?g(c):[a,b].map((n,j)=>[...Array(n)].map((_,i)=>~~(i*(j?d:c/d)/n+j)*(j||d),j^=a<b))
```
[Try it online!](https://tio.run/##bYvRCoIwGEbvew/l/2vOJiUlTek5pGJuKg6bohEE4quvEd3p5XfO@bR4i1EOTf8KTKdKW3ELghRE8WLHkKc1lzyVXhCoaRKe8v3CU1kNEpPcZTf6FD2AIdqlOaX0OgziAwb/4kEaJ@YZmi3oTCUyVBianUY3p0kh0XcuLgWilZ0Zu7akbVdDBTGJEWLEzQo@r@ADwmmBj4RFCNF@IVj0M8xd7Bc "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 93 bytes
```
import math
def f(a,b,t):A=math.gcd(a,t);return[*range(1,A+1)]*(a//A),([*range(0,t,A)]*b)[:b]
```
[Try it online!](https://tio.run/##Tck7DoMwEEXRnlVQzpBRwCSxCFEKrwNR2MF8CoxlTYqs3jEFEtJr7nn@x/PmbjEuq98C56vmORvsmI@gyRBjq967XafPkITxFSx/g@uKoN1kQZC6COwL0GWpkODwiphUcoNda/row@IYRpAk6YmYHf0gUVNdnUTSnZpTp39fovgH "Python 3 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~17~~ 15 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Output is `[d1.1,...,d1.n,[d2.1,...,d2.n]]`
```
Ç*V%WÃpVogVyW õ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=xypWJVfDcFZvZ1Z5VyD1&footer=8k7OIG9jIG1u&input=NQoxMgoyMAotUg) (footer splits & sorts output) or [run all test cases](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=V2dUIGcwCldnVCBnMQpXZ1QgZzI&code=xypWJVfDcFZvZ1Z5VyD1&footer=WPJVIG9jIG3NaVtVVlddIMtpRWciSW5wdXQ6XG5EaWUgMTpcbkRpZSAyOiK3%2brm4w7dpUnBUsM4&input=WwpbIDYgIDYgIDldClsgNSAxMiAyMF0KWyA2ICA0ICA4XQpbMTIgMTIgMThdCl0KLW1S)
```
Ç*V%WÃpVogVyW õ     :Implicit input of integers U=a, V=b & W=n
Ç                   :Map the range [0,U)
 *V%W               :  Multiply by V and modulo by W
     Ã              :End map
      p             :Push
       Vo           :  Range [0,V)
         g          :  Index (0-based and modular) each into
          VyW       :    GCD of V & W
              õ     :    Range [1,VyW]
```
[Answer]
# [Go](https://go.dev), 139 bytes
```
func f(a,b,t int)(l,r[]int){i,j,x,y:=0,0,b,t
for y!=0{g:=y;y,x=x%y,g}
for;i<a;i++{l=append(l,i*b%t)}
for;j<b;j++{r=append(r,j%x+1)}
return}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PZBRaoQwEIbfc4pUkGp3urhLK1Y3B-hbH_ZtWUpMVWLdKDGCEjxBj9CXpVDolfY2HatdSPLP8A0__-Tzq6jPl9uGi3deZPTEpSLy1NTarJ38ZJxr0-LrfHcmv48uH3mnBM09DikYKpXxvQr04ThVVkIJPQwxCyCYOMlrTYcbFtgiZkMyQM96d4BinEAidzyRq5WtGG-aTL2hkbxLXePPuNylSYlY_2MNpduvNoh1ZjqtxiXSjxmajO5pa3QnDLXXaOgzhZ0W83xqieBt1tKY0cNxb20IITyNYB9hs4VtgFUIDxChYj-daPwLQl9BxExzhX80O1iCK8cs98Sag1ineI1PnpVpvWpR7ZMXjREq5QnAaZ-MZMl7Ps_6Cw)
Port of [Shaggy's answer](https://codegolf.stackexchange.com/a/255480/77309).
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
ＮθＮηＮζ≔﹪×…⁰θηζεＩ⟦ε⊕﹪…⁰η⁻ζ⌈ε
```
[Try it online!](https://tio.run/##XYw/C8IwFMR3P0XGF4hQC06dxKlDRcRNHGL6aALNi80fkXz5GAdFPDi4H9yd0tIrJ@dSerqneEj2hh4W3q1@Wf9xrrwLwUwEgxvT7OBsLAY4SZoQGsEWLpiuztVYy0dvKMJehggXFKwn5dEiRRw/B9/pezYYSgFyDfJpbLKAvOrKeVfKlm1a1jZl/Zhf "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Port of @loopywalt's Python answer.
```
ＮθＮηＮζ
```
Input the dice.
```
≔﹪×…⁰θηζε
```
Multiply all of the digits on a regular first die by the size of the second die and reduce modulo the size of the third die.
```
Ｉ⟦ε
```
Output that as the first die, and as the second die output...
```
⊕﹪…⁰η⁻ζ⌈ε
```
... the digits on a regular second die modulo the minimum step in values on the output first die (calculated as the size of the third die minus the maximum value on the output first die, although the minimum nonzero value also works), plus one.
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 12 bytes (24 nibbles)
```
`:;.*@,_%$@+~.,_%$`/|@$[
```
Same approach as [Neil's answer](https://codegolf.stackexchange.com/a/255467/95126) (which apparently is a port of [loopy walt's answer](https://codegolf.stackexchange.com/a/255463/95126)): upvote those!
Input is target, die1, die2.
```
`:;.*@,_%$@+~.,_%$`/|@$[
`:                          # output list of 2 lists:
  ;                         #   save list 1:
    *                       #     multiply 
     @                      #     sides of die1 by
      ,_                    #     each value of die2
   .                        #     and map over each of thes values
        %$                  #       modulo it by
          @                 #       sides of the target die   
                            #   now make list 2:
                    |@$     #     remove nonzero values from list 1
                  `/        #     and fold over this
                       [    #     getting the minimum;
             .,_            #     now map over values of die1
                %$          #       moduloing each by
                            #       minimum nonzero value of list 1
           +~               #     and add 1 to each
```
[![enter image description here](https://i.stack.imgur.com/BRbMo.png)](https://i.stack.imgur.com/BRbMo.png)
[Answer]
# [Rust](https://www.rust-lang.org), ~~170~~ ~~159~~ 151 bytes
* -8 bytes thanks to corvus\_192
```
|a,b,c|(1..a).filter(move|d|a%d+b%d+c%(a/d)<1).flat_map(|d|[(d,1),(a/d,d)]).zip([b,c]).map(move|((u,w),e)|(0..e).map(|v|v/(e/u)*w).collect()).collect()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=fY9BTsMwEEX3OYWpVGmmDE6TFlRKW27BpkLItR0pkpNGwUkl6p6DBZssYM8dOAW3wSZdsAnSjGak9__XzNt73Tzb7jMrWSHyEvBotGXZ-qOx2dXi-9UJ2pF0kHAukGe5sbqGYt9qp5wYq8udbzkGEStcJV5ghH0qRAUeb0FRghQYKXxE_pJXsPVpfg2S3xSAhg5IGh1MOdc9ca1rY9Bxg5MDcrk3RksL-Gc9n_cV3UVROFgtH7RchW5m6WbD1iyDObFQ6CVVnZfWlBcwOi7vTyPy9JbYjS_0eJDOBmiy-Nd8xkPudErsmliSBh6d-le6rp8_)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
L*I%=αß²Ls%>?
```
Port of [*@loopyWalt*'s Python answer](https://codegolf.stackexchange.com/a/255463/52210).
Three loose inputs in the order \$die1,die2,target\$, output printed as two separated lists.
[Try it online](https://tio.run/##yy9OTMpM/f/fR8tT1fbcxsPzD23yKVa1s///39CIy5TLyAAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V@m5JlXUFpSbKWgZF@pw6XkX1oC5epUJoQeWhlR9N9HK0LV9tzGw/MPrfMpVrWz/39om87/6GgzHTMdy1idaEMjHVMdIwMgy1QHyAazzHRMdCyAtAlQjQVEDQhZgKWAMDYWAA).
Could alternatively be output as a pair of lists:
```
L*I%ZIα²Ls%>‚
```
[Try it online](https://tio.run/##yy9OTMpM/f/fR8tTNcrz3MZDm3yKVe0eNcz6/9/QiMuUy8gAAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V@m5JlXUFpSbKWgZF@pw6XkX1oC5yaEHlpZ/N9HK0I1KuLcxkPrfIpV7R41zPqvc2ib/f/oaDMdMx3LWJ1oQyMdUx0jAyDLVAfIBrPMdEx0LIC0CVCNBUQNCFmApYAwNhYA).
**Explanation:**
```
L         # Push a list in the range [1, first (implicit) input die1]
 *        # Multiply each value by the second (implicit) input die2
  I%      # Modulo each by the third input target
    =     # Print it with trailing newline (without popping)
α         # Take the absolute difference between the third (implicit) input target and
          # each value in the list
 ß        # Pop and push the minimum
  ²L      # Push a list in the range [1, input die2]
    s     # Swap so the minimum absolute difference is at the top
     %    # Modulo each value in the list by this
      >   # Increase each by 1
       ?  # Pop and output it (without trailing newline) as well
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 81 bytes
```
(a,b,x)=>(g=i=>x%i|b%i?g(--i):[a,b].map(Z=n=>n--?[n*i%x+1||n%i,...Z(n)]:x=''))(b)
```
[Try it online!](https://tio.run/##bcvBDoIwEATQu//RsKttI0SNkiz8B4RDQSBrsCViTA/8e61nzMzpTeZhPmbpXjy/lXX3PgwUwMhWeqQCRmIqvOC1FVyOoBRjXse10U8zQ0WWCqtUWds9C39I19UKllrrCiw2uackQYQWQ@fs4qZeT26EAS4yBnG31dsfPcnrRs8yzWR23HjUX@MhfAE "JavaScript (Node.js) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 27 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
k
[V=ogVk fU2 ×õ)WogU×o*VÌ]
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=awpbVj1vZ1ZrIGZVMiDX9SlXb2dV128qVsxd&input=MTggMTIgMTItUQ)
Input as `target die1 die2`, Output as `[[<die1 sides>],[<die2 sides>]]`, unsorted.
Explanation:
```
k              
k              # Get the prime factors of <target>
               # Store as U
[...]          # Return the enclosed statements as an array:
V=ogVk fU2 ×õ) 
    Vk         #  Prime factors of <die1>
       fU2     #  Remove and return from U numbers that are in both
           ×   #  Multiply them together
            õ  #  Get the range [1...N]
   g         ) #  Index into that range (wrapping):
  o            #   Numbers in [0...<die1>-1]
V=             #  Store as V and return it
WogU×o*VÌ      
   U           #  The remaining numbers in U
    ×          #  Multiplied together
     o         #  For X in the range [0...N-1]:
      *        #   Multiply X by
       VÌ      #   The last (highest) number in V
  g            #  Index into the result (wrapping):
Wo             #   Numbers in the range [0...<die2>-1]
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 101 bytes
```
x;y;*p;f(a,b,n,r){p=r;for(x=n,y=a;r=y%=x;x=r)y=x;for(;a--;*p++=y--)y=y?:x;for(;b--;*p++=y-=x)y=y?:n;}
```
[Try it online!](https://tio.run/##dVDRToMwFH3fV9ywkLRQjC5qdLXuxb9QHwoU14QVUpiCy7593lLY3KJNbtqcc@655zZLPrLsMNcmK7e5gqemzXV1tX6ezXNVaKPghaiuthRqq01bkCBsQECYv5mAzR3DPE8PHe95VPOCSJYywyzd1cLyorKkE4b1QnIr@lB0vBOW9ng7isskwa44Fn2SINqvliORngjRecbw/Z9Jf0OlTh02@6x07jNLawngHQG@mHtBo78VUNjNAM@4GASvEADlA/a11qUCMgiTBOhJFOZhEzCICJrFMWXeawWIBbDEesefcTb7MUOrmnaYD9IPT/1ljgGGbFY127LFr93IsqwygsMlxJCiKhpmVAVBIZ0SYhb0Qy/Dpt6ROS3tceZANPuHxiHO6Ix2i16ssZHakCmx3wnuma/HqXnE7xjcLBgsri9wp73FejjHnXaoAd8ffgA "C (gcc) – Try It Online")
**Edit #1:** -1 byte thanks to ceilingcat
[Answer]
# [Scala](https://www.scala-lang.org/), ~~177~~ 172 bytes
saved bytes due to replacing `List` to `Seq`
---
Golfed version, [try it online!](https://tio.run/##dY9NT8MwDIbv/RW@TLIhatfxIahoJY4cdpo4IQ5ukk5FWVratBNM/e0lKdzGLNuR30ev7PSSDc9N@aGlgy3XFk4RgNIVHPyA3O37DJ67jr/edq6r7f6dMni1tYMcTvPIBqocOXuxTpRLl6FTXmAKrgGmuKqN0x2qvOCVui59yRVyougp9dCw23Ib6E5/IiqRkghUKCKKv@sWg14K6acDtyfJvQbEQRxJ6LBmDYN1tQG9cBzzYkxQJwNdHSl2jXdPv88MPsLByp9e4a2AkBQFufU/c8ZihY8C7n3S//rNmZ4@XDD8gXPHZi3gTkC6WcgUTdH8Aw)
```
val f=(a:Int,b:Int,c:Int)=>(1 to a).filter(d=>a%d+b%d+c%(a/d)<1).flatMap(d=>Seq((d,1),(a/d,d))).zip(Seq(b,c)).map{case ((u,w),e)=>(0 until e).map(v=>v/(e/u)*w).toSeq}.toSeq
```
Ungolfed version
```
object Main {
  def main(args: Array[String]): Unit = {
    val f = (a: Int, b: Int, c: Int) =>
      (1 to a)
        .filter(d => a % d + b % d + c % (a / d) < 1)
        .flatMap(d => List((d, 1), (a / d, d)))
        .zip(List(b, c))
        .map { case ((u, w), e) => (0 until e).map(v => v / (e / u) * w).toList }
        .toList
    val d = f(4, 4, 4)
    println(f(9, 6, 6))
    println(f(9, 6, 3))
    println(f(18, 6, 6))
    println(f(18, 6, 3))
    println(f(20, 5, 12))
  }
}
```
]