44

4

# Background:

Standard operation math like basic addition and multiplication in the real world work like these:

```
12 + 123 = 135
```

and

```
12 * 123 = 1476
```

*That's not interesting and boring!* Many schools are already interpreting this as practice, practice, practice of formal algorithms. That implies a pretty rigid and boring mathematical diet and is not what is intended in this challenge. Get ready to play some fun on our beloved site.

Consider the process of adding two positive integer numbers, then adding again all the digits of its result. Repeating with the addition until only a single digit is obtained. For example:

- The result of
`12 + 123`

is 135. - Adding all the digits of 135 we obtain
`1 + 3 + 5 = 9`

.

The number of steps required to obtain a single digit value 9 in this repeated addition is 2.

As with the previous process of the addition, the multiplication of two positive integer numbers follows the same process. Multiply all the digits of its result and then repeating this process until only a single digit remains. Take the above example:

- The result of
`12 * 123`

is 1476. - Multiply all the digits of 1476 we obtain
`1 * 4 * 7 * 6 = 168`

. - Multiply again all the digits of 168 we obtain
`1 * 6 * 8 = 48`

. - Multiply again all the digits of 48 we obtain
`4 * 8 = 32`

. - Multiply once again all the digits of 32 we obtain
`3 * 2 = 6`

.

The number of steps required to obtain a single digit value 6 this repeated multiplication is 5.

For this challenge's sake and avoiding any misuse of math notations, I introduce these two dummy notations: `(+)`

and `(*)`

, **but you may use any notation you like**, which work like the followings:

- The operation of repeated addition process to obtain a single value is
`12 (+) 123 = 9`

. - The operation of repeated multiplication process to obtain a single value is
`12 (*) 123 = 6`

.

# Challenge:

The challenge is to write either a program or a function which can perform **both of operations** as explained in the background section: `(+)`

and `(*)`

.

# Input:

The inputs of the program or the function are two positive integers and one operation either `(+)`

and `(*)`

. **The format of the input is an arbitrary choice of the programmer**. You may format the input, for example, `a (+) b`

or `F(a, (+), b)`

or any format you wish.

# Output:

The output of the program or the function must contain the result of operation and the number of steps required with freestyle format as you wish.

Test Cases (ignore the input and output format):

```
81 (+) 31 --> (4 ; 2)
351 (+) 14568 --> (6 ; 3)
21 (*) 111 --> (8 ; 3)
136 (*) 2356 --> (0 ; 2)
```

# General rules:

- This is code-golf, so the shortest answer in bytes wins the challenge.

Don't let esolangs discourage you from posting an answer with regular languages. Enjoy this challenge by providing an answer as short as possible with your programming language. If you post a clever answer and a clear explanation, your answer will be appreciated (hence the upvotes) regardless of the programming language you use. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/ method with the proper parameters, full programs, etc. The choice is yours.
- If possible, your program can properly handle large numbers. If not, that will just be fine.

The repeated addition part (

– Peter Taylor – 2016-08-24T09:49:43.917digital root) is essentially a duplicate of http://codegolf.stackexchange.com/q/1128/194@PeterTaylor The addition part might be true, but there are additive and multiplicative persistence part here, so they're semi-related but not a dup, IMHO. – Anastasiya-Romanova 秀 – 2016-08-24T09:55:39.433

4Great first question! And I recognize the general rules format and sentences from my own Questions. ;) – Kevin Cruijssen – 2016-08-24T11:10:16.057

4@KevinCruijssen Yup. that's right. Since it has no copyright so I duplicate it without your permission. Hehehe :D – Anastasiya-Romanova 秀 – 2016-08-24T11:11:43.337

Related: Manhattan and Fuzzy-Logic.

– Adám – 2016-08-24T13:26:52.1904@Anastasiya-Romanova秀 "no copyright"? In XXI century? Nope; everything here is CC-BY-SA 3.0. Permission is granted when the content is submitted. Check the site footer. – Mindwin – 2016-08-24T14:42:08.897

Can the input to the function be

`(12, &[+], 123)`

, where`&[+]`

is short for`&infix:< + >`

a reference to the infix numeric addition operator subroutine? – Brad Gilbert b2gills – 2016-08-24T15:11:08.6071@BradGilbertb2gills Yes, of course. It's stated in the post by the way.

Quote:"The format of the input is an arbitrary choice of the programmer". – Anastasiya-Romanova 秀 – 2016-08-24T15:43:27.177