In long multiplication, after multiplying the numbers, you are left with the partial products, in this challenge you will output those partial products.

Because long multiplication is long, to compensate your code will need to be as short as possible.


34, 53
102, 1700

48, 38 
384, 1440

361, 674
1444, 25270, 216600

0, 0

1, 8


  • Input / Output may be in any reasonable format such as array, comma-separated string (or any other delimiter that's not a digit), list, function arguments, etc.
  • Partial products must be in increasing order.
  • If a partial product is 0, you can choose whether you want to output it or not.

This is so shortest code in bytes wins!

  • \$\begingroup\$ I'm assuming that the numbers can be strings, right? \$\endgroup\$ Commented Dec 30, 2015 at 1:46
  • \$\begingroup\$ That 0,0 test case is making it a lot harder. \$\endgroup\$
    – xnor
    Commented Dec 30, 2015 at 2:21
  • \$\begingroup\$ What is the expected outcome for 12, 102? Most answers seem to return 24, 0, 1200. \$\endgroup\$
    – Dennis
    Commented Dec 30, 2015 at 3:00
  • \$\begingroup\$ @Dennis 24, 0, 1200 is fine. I'll specify in the post \$\endgroup\$
    – Downgoat
    Commented Dec 30, 2015 at 3:43

18 Answers 18


Pyth, 12 bytes


Test suite

Takes input newline separated, e.g.



                Implicit: Q = eval(input()),T = 10
           w    Input the second number as a string.
          _     Reverse it.
.e              Enumerated map, where b is the character and k is the index.
     sb         Convert the character to an int.
   *Q           Multiply by Q.
  *    ^Tk      Multiply by T ^ k. (10 ^ index)

Jelly, 10 bytes


Try it online!

How it works

DU×µLR’⁵*×  Left argument: multiplier -- Right argument: multiplicant

D           Convert the multiplier to base 10 (array of digits).
 U          Reverse the array.
  ×         Multiply each digit by the multiplicant.
   µ        Begin a new, monadic chain. Argument: A(array of products)
    L       Get the length of A.
     R      Turn length l into [1, ..., l].
      ’     Decrement to yield [0, ..., l-1].
       ⁵*   Compute 10**i for each i in that range.
         ×  Hook; multiply the powers of ten by the corresponding elements of A.
  • 4
    \$\begingroup\$ I'm guessing the name of this language comes from the fact that it makes everyone feel jelly. \$\endgroup\$
    – geokavel
    Commented Dec 30, 2015 at 5:00

JavaScript (ES7), 48 bytes


ES6 (56 bytes)



Returns an array of partial products as numbers.

  [...b+""]    // convert the multiplier to an array of digits
  .reverse()   // reverse the digits of the multiplier so the output is in the right order
  .map((d,i)=> // for each digit d of the multiplier
    10**i      // get the power of ten of the digit
      *a*d     // raise the product of the digit to it


Test uses Math.pow instead of ** to make it work in standard browsers.

var solution = (a,b)=>[...b+""].reverse().map((d,i)=>Math.pow(10,i)*a*d)
A = <input type="text" id="A" value="361" /><br />
B = <input type="text" id="B" value="674" /><br />
<button onclick="result.textContent=solution(+A.value,+B.value)">Go</button>
<pre id="result"></pre>


Lua, 72 68 Bytes

b=arg[2]:reverse()for i=1,#b do print(arg[1]*b:sub(i,i)*10^(i-1))end

APL, 21 bytes


This is a dyadic function that accepts integers on the left and right and returns an array. To call it, assign it to a variable.


             x←⊖⍎¨⍕⍵} ⍝ Define x to be the reversed digits of the right input
     10*1-⍨⍳≢         ⍝ Generate all 10^(1-i) for i from 1 to the number of digits
{⍺×x×                 ⍝ Multiply the right input by the digits and the powers of 10
  • 1
    \$\begingroup\$ ⍎¨⍕ is pretty clever. \$\endgroup\$
    – Dennis
    Commented Dec 30, 2015 at 14:53

05AB1E, 15 bytes





V                 # Assign the input to Y
 D                # Duplicate of input, because the stack is empty
  g               # Pushes the length of the last item
   U              # Assign the length to X
    S             # Split the last item
     X            # Pushes X (length of the last item)
      F           # Creates a for loop: for N in range(0, X)
       TNm        # Pushes 10 ^ N
          Y       # Pushes Y (first input)
           *      # Multiplies the last two items
            *     # Multiplies the last two items
             =    # Output the last item
              \   # Discard the last item

Pyth, 26 bytes


This defines a function c such that it accepts 2 arguments, and the function prints the partial products.

DCGH                      Define function c(G, H)
    KjHT                  Set K to the list of digits converting H to base 10
        FNJlK             Set J to the length of K and loop with variable N
                          (Implicit: print)
             *G*@Kt-JN    Calculates the partial product
                      ^TN Raising it to the appropriate power of 10

MATL, 18 bytes


The compiler (5.1.0) works in Matlab and in Octave.

Each number is input on a separate line.


>> matl ij48-tn:1-P10w^**P
> 361
> 674
1444  25270 216600


i           % input first number (say 361)
j           % input second number, interpreted as a string (say '674')
48-         % subtract '0' to obtain vector of figures (gives [6 7 4])
tn:1-P      % vector [n-1, ... 1, 0] where n is the number of figures (gives [2 1 0])
10w^        % 10 raised to that, element-wise (gives [100 10 1])
*           % multiply, element-wise (gives [600 70 4])
*           % multiply (gives 361*[600 70 4], or [216600 25270 1444])
P           % flip vector ([1444 25270 216600]). Implicitly display

Haskell, 60 57 54 bytes

g x=zipWith(\b->(x*10^b*).read.pure)[0..].reverse.show

5 bytes less (drop the .show) if I can take the second number as a string.

Usage example: g 361 674 -> [1444,25270,216600].

Multiply every digit of the reverse of y with x and scale with 10^i where i = 0,1,2,....

Edit: Thanks to @Mauris for 3 bytes!

  • \$\begingroup\$ You can even do (\b->(x*10^b*).read.pure). \$\endgroup\$
    – lynn
    Commented Dec 30, 2015 at 2:17
  • \$\begingroup\$ @Mauris: Nice. Thanks a lot! \$\endgroup\$
    – nimi
    Commented Dec 30, 2015 at 2:30

Julia, 50 49 bytes

f(a,b)=[a*d*10^~-i for(i,d)=enumerate(digits(b))]

This is a function that accepts two integers and returns an integer array.

The digits function returns an array of the input integer's digits in reverse order. We get the index, value pairs using enumerate and compute the partial products as the first input times the digits times 10 raised to the power of the digit's index - 1.

Saved a byte thanks to Dennis!


Python 2, 61

def p(a,b):
 while b>0:

CJam, 19 17 bytes


Takes input with the first item being an integer and the second a string (e.g. 34 "53"). Suggestions are welcome, as I'm sure it can be shorter. Thanks to Dennis for saving two bytes.

Try it online.


q~    e# Get input and evaluate it, x and "y"
W%    e# Reverse y so it will be properly sorted
ee    e# Enumerate through y with each character and its index
f{    e# For each digit in y...
  ~~  e# Convert the digit to an integer on the stack
  A@# e# Take 10 to the power of y's index
  **  e# Multiply all three together to get the final result
p     e# Print the array
  • 1
    \$\begingroup\$ ~~A@#** saves a couple of bytes. \$\endgroup\$
    – Dennis
    Commented Dec 30, 2015 at 4:46

Haskell, 37 bytes

a%b=b`mod`10*a:(a*10)%div b 10

No stringifying, just arithmetic. Recursively prepends the smallest partial product to the rest, where the last digit of b is truncated and a multiplier of 10 is applied. The operator precedence works nicely.


Japt, 8 bytes

Takes input in reverse order with the first being a digit array and the second being an integer. If both inputs must be of the same type then we can take them both as strings and add ¬ to the beginning.


Try it

¬ÔË*V*ApE     :Implicit input of array U & integer V (or strings U & V)
¬             :(Split U, if inputs are strings)
 Ô            :Reverse U
  Ë           :Map each element at 0-based index E
   *V*        :  Multiply by V multiplied by
      A       :  10
       pE     :  Raised to the power of E (1eE would also work in place of ApE)

𝔼𝕊𝕄𝕚𝕟, 11 chars / 23 bytes (non-competitive)


Try it here (Firefox only).

Found a bug while coding the solution to this problem...


          // Implicit: î = input 1, í = input 2
ᴙíⓢ      // reverse í and split it into an array
ⓜî*$*Ⅹⁿ_ // multiply î by each individual digit in í and put in previous array
          // implicit output

Japt, 28 bytes

I=[]Vs w m@IpApY+1 /A*U*X};I


I=[]Vs w m@IpApY+1 /A*U*X};I
I=[]                         //that's simple, init an array I
    Vs                       //take the second input and convert to string
       w                     //reverse it and...
         m@              }   //...map through the chars; X is a char, Y is counter
           Ip............    //push the following value into I...
             ApY+1 /A*U*X    //10^(Y+1)/10*U*X, U is the first input
                           I //output the resulting array
  • \$\begingroup\$ Due to the bug in the interpreter, have to use ApY+1 /10 instead of ApY, because Ap0 (which is 10^0) gives 100. I guess it's for the reason to allow fast squaring with Ap, but 0 doesn't mean "no arguments". Plz fix, Eth. \$\endgroup\$
    – nicael
    Commented Dec 30, 2015 at 7:49

Python 2, 42 bytes

f=lambda a,b:b*[0]and[b%10*a]+f(a*10,b/10)

No stringifying, just arithmetic. Recursively appends the smallest partial product to the rest, where the last digit of b is truncated and a multiplier of 10 is applied.


Husk, 10 bytes


Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.