Skip to main content
added 763 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 3434 32 bytes

[:(0=[<;.1~*)/[:*+/*.&#$&>,|/i:&(;2>#\)

Try it online!

Explanation

[:(<;.@*1~*)/[:+/*.&#$&>,:&(;2>#\)&#<;  Input: array A (LHS), array B (RHS)
                             #\   Length of each prefix of A and B
                           2>     Less than 2
                          ;       Link each with A and B
                      ,:&         Pair them
                  #               Length of A and B
               *.1[&                LCM of the lengths
                    &>            For each box
                   $              Reshape it to the LCM of the lengths
           [:+/                   Reduce by addition
[:        /                       Reduce by
        *                           Sign of RHS
   <;.&#$&>;1~                            Box each partition of LHS

Probably could be made less than 30 bytes.

Try it online!

J, 34 bytes

(0=[:*/,|/i.@*.)&#<;.1[:+/*.&#$&>;

Probably could be made less than 30 bytes.

Try it online!

J, 34 32 bytes

[:(<;.1~*)/[:+/*.&#$&>,:&(;2>#\)

Try it online!

Explanation

[:(<;.1~*)/[:+/*.&#$&>,:&(;2>#\)  Input: array A (LHS), array B (RHS)
                             #\   Length of each prefix of A and B
                           2>     Less than 2
                          ;       Link each with A and B
                      ,:&         Pair them
                  #               Length of A and B
               *.&                LCM of the lengths
                    &>            For each box
                   $              Reshape it to the LCM of the lengths
           [:+/                   Reduce by addition
[:        /                       Reduce by
        *                           Sign of RHS
   <;.1~                            Box each partition of LHS
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 34 bytes

(0=[:*/,|/i.@*.)&#<;.1[:+/*.&#$&>;

Probably could be made less than 30 bytes.

Try it online!