Sum of Modulo Sums
05AB1E, 12 10 bytes
v¹¹N¹‚£O%O
Uses the CP-1252 encoding. Try it online!
JavaScript, 43 47 bytes
f=
n=>eval(n.replace(/./g,'+'+n+"%($`+ +'$&$'')"))
I.oninput=_=>O.value=f(I.value)
<input id=I>
<input id=O disabled>
Takes input as string.
Edit:
+4 bytes: Leading zeroes in JavaScript converts the number to octal ):
Brachylog, 20 bytes
:{$@~c#C:@$a+:?r%}f+
Try it online!
Explanation
This implements the formula given. The only thing we have to be careful about is when a 0
is in the middle of the input: in that case Brachylog gets pretty quirky, for example it won't accept that a list of integers starting with a 0
can be concatenated into an integer (which would require ignoring the leading 0
— this is mainly programmed that way to avoid infinite loops). Therefore to circumvent that problem, we convert the input to a string and then convert back all splitted inputs into integers.
Example Input: 47852
:{ }f Find all outputs of that predicate: [716,205,152,4769]
$@ Integer to String: "47852"
~c#C #C is a list of two strings which when concatenated yield the Input
e.g. ["47","852"]. Leave choice points for all possibilities.
:@$a Apply String to integer: [47,852]
+ Sum: 899
:?r% Input modulo that result: 205
+ Sum all elements of that list