# Multiplying substrings

Write a program that takes two integers as an input; the first can be any integer and the second is less than or equal to the number of digits in the first number. Let these numbers be a and b respectively.

The program will do the following

• Concatenate a minimal number of 1s to the end of a so the number of digits in a is divisible by b.
• Split a along every b digits.
• Multiply the digits in each section together.
• Concatenate the products together (if one of the numbers is zero, then concatenate 0).
• Repeat this process until a number with strictly fewer than b digits is formed. Print this as the output, as well as the number of the process is repeated. Units are not necessary, but some form of separation between the final number and number of iterations is.

In the following test cases, the individual steps are shown for the purpose of understanding. It is not necessary for your program to display the steps.

Test case 1

1883915502469, 3

Steps

1883915502469          //Iteration 1
188391550246911
188 391 550 246 911
64 27 0 48 9
64270489               //Iteration 2
642704891
642 704 891
48 0 72
48072                  //Iteration 3
480721
480 721
0 14
014                    //Iteration 4
0


Sample Output: 0, 4

Test case 2

792624998126442, 4

Steps

792624998126442        //Iteration 1
7926249981264421
7926 2499 8126 4421
756 648 96 32
7566489632             //Iteration 2
756648963211
7566 4896 3211
1260 1728 6
126017286              //Iteration 3
126017286111
1260 1728 6111
0 112 6
01126                  //Iteration 4
01126111
0112 6111
0 6
06


Sample Output: 06, 4

The program must return an error (or just not print anything) if b>len(a). Also, b cannot equal 1 or the program will result in an infinite loop.

This is code golf, so standard rules apply. Shortest code in bytes wins.

• Does it need to be a complete program, or is a function enough? – Ypnypn Nov 3 '15 at 16:01
• @Ypnypn A complete program. – Arcturus Nov 3 '15 at 16:02
• So leading zeros count towards the length of a and are also included in the output? – mbomb007 Nov 3 '15 at 22:44
• @mbomb007 Yes, but only in the initial number. The chain of zeroes would be shortened to single zeroes in the concatenation of products. – Arcturus Nov 4 '15 at 3:04
• @ypnypn you should say that explicitly in the question. The "standard rules"from the tag wiki say "the following defaults ... Answers may be either full programs or functions (or equivalent)." – Joshua Taylor Nov 7 '15 at 1:15

# CJam, 42 bytes

q~:N;Ab{_N(>}{_N/)N1e]a+::*s:~}w])S@,_])g*


Test it here.

## Perl 6, 116 bytes

my ($a,$b)=@*ARGS;for 0..* {if $b>$a.chars {$_&&say "$a,$_";last};$a=map({[*] @_},($a~1 x$b-1).comb.rotor($b)).join}  my ($a,$b)=@*ARGS; for 0..* { if$b>$a.chars {$_&&say "$a,$_";last}; # you need a ｢;｣ if you remove the newline
$a=map( {[*] @_}, ($a~1 x$b-1).comb.rotor($b)
).join
}


# Pyth, 32 bytes

IglzQf<l=zjk*MsMMc+z*\1%_lzQQQ)z


Demonstration

Takes input on two lines, a followed by b. Gives output on two lines, operations followed by result.

Pad: +z*\1%_lzQ

Chop: c ... Q

Convert to list of ints: sMM

Take products: *M

Convert back to str: jk

Assign back: =z

Check for termination: <l ... Q

Print iterations taken: f ... )

Print result: z

Initial check of whether to print anything at all: IglzQ