[Question]
  [
Given an integer `n > 9`, for each possible insertion between digits in that integer, insert an addition `+` and evaluate. Then, take the original number modulo those results. Output the sum total of these operations.
An example with `n = 47852`:
```
47852 % (4785+2) = 4769
47852 % (478+52) =  152
47852 % (47+852) =  205
47852 % (4+7852) =  716
                  -----
                   5842
```
### Input
A single positive integer [in any convenient format](http://meta.codegolf.stackexchange.com/q/2447/42963), `n > 9`.
### Output
The single integer output following the above construction technique.
### Rules
* You don't need to worry about input larger than your language's default type.
* Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
* [Standard loopholes](http://meta.codegolf.stackexchange.com/q/1061/42963) are forbidden.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so all usual golfing rules apply, and the shortest code (in bytes) wins.
### Examples
```
47852 -> 5842
13 -> 1
111 -> 6
12345 -> 2097
54321 -> 8331
3729105472 -> 505598476
```
  
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~12~~ 10 bytes
```
v¹¹N¹‚£O%O
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=dsK5wrlOwrnigJrCo08lTw&input=NDc4NTI)
[Answer]
# 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 ):
[Answer]
# [Brachylog v1](http://github.com/JCumin/Brachylog), 20 bytes
```
:{$@~c#C:@$a+:?r%}f+
```
[Try it online!](http://brachylog.tryitonline.net/#code=OnskQH5jI0M6QCRhKzo_ciV9Zis&input=MzcyOTEwNTQ3Mg&args=Wg)
### 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               
  
```
[Answer]
# ES6 (Javascript), ~~42~~, 40 bytes
EDITS:
* Got rid of *s*, -2 bytes
**Golfed**
```
M=(m,x=10)=>x<m&&m%(m%x+m/x|0)+M(m,x*10)
```
**Test**
```
M=(m,x=10)=>x<m&&m%(m%x+m/x|0)+M(m,x*10);
[47852,13,111,12345,54321,3729105472].map(x=>console.log(M(x)));
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ŒṖṖLÐṂḌS€⁸%S
```
**[TryItOnline!](http://jelly.tryitonline.net/#code=xZLhuZbhuZZMw5DhuYLhuIxT4oKs4oG4JVM&input=&args=NDc4NTI)**
### How?
```
ŒṖṖLÐṂḌS€⁸%S - Main link: n
ŒṖ           - partitions (implicitly treats the integer n as a list of digits)
  Ṗ          - pop - remove the last partition (the one with length one)
    ÐṂ       - keep those with minimal...
   L         - length (now we have all partitions of length 2)
      Ḍ      - undecimal (convert each entry back to an integer)
       S€    - sum each (add the pairs up)
         ⁸   - left argument, n
          %  - mod (vectorises)
           S - sum
```
[Answer]
## Python 2, 45 bytes
```
f=lambda n,c=10:n/c and n%(n/c+n%c)+f(n,c*10)
```
Uses arithmetic rather than strings to divide the input `n` into parts `n/c` and `n%c`, which `c` recurses through powers of 10.
[Answer]
# Perl ~~35 32~~ 27 Bytes
Includes +3 for `-p`
Saved 8 bytes thanks to Dada
```
$\+=$_%($`+$')while//g}{
```
[Answer]
# C 77 + 4 = 81 bytes
### golfed
```
i,N,t,r,m;f(n){for(r=0,m=n;n;t=n%10,n/=10,N+=t*pow(10,i++),r+=m%(n+N));return r;}  
```
### Ungolfed
```
#include<stdio.h>
#include<math.h>
i,N,t,r,m;
f(n)
{
    m=n;
    r=0;
    while(n)
    {
        t=n%10;
        n/=10;
        N+=t*pow(10,i++);
        r+=m%(n+N);
    }
    return r;
}
main()
{
    printf("%d",f(47852));
}
```
[Answer]
## Python 2, ~~68~~ ~~64~~ 68 bytes
-4 bytes thanks to atlasologist
```
lambda x:sum(int(x)%(int(x[:i])+int(x[i:]))for i in range(1,len(x)))
```
\*Input is a string
[Answer]
# C, 59 bytes
```
t,s;f(n){s=0;t=10;while(t<n)s+=n%(n/t+n%t),t*=10;return s;}
```
`t` is `10,100,1000,...` and represents the cut in the big number. `n/t` is the right part and `n%t` the left part. If `t` is bigger than the number, it is finished.
Ungolfed and usage:
```
t,s;
f(n){
 s=0;
 t=10;
 while(t<n)
  s += n % (n/t + n%t),
  t *= 10;
 return s;
}
main(){
 printf("%d\n",f(47852));
}
```
[Answer]
## [Retina](http://github.com/mbuettner/retina), 38 bytes
Byte count assumes ISO 8859-1 encoding.
```
\B
,$';$_¶$`
G-2`
\d+|,
$*
(1+);\1*
1
```
Not exactly efficient...
[Try it online!](http://retina.tryitonline.net/#code=JShHYApcQgosJCc7JF_CtiRgCkctMmAKXGQrfCwKJCoKKDErKTtcMSoKCjE&input=MTMKMTExCjEyMzQ1CjQ3ODUyCjU0MzIx) (The first line enables a linefeed-separated test suite.)
### Explanation
```
\B
,$';$_¶$`
```
Between every pair of characters, we insert a comma, everything in front of the match, a semicolon, the entire input, a linefeed, and everything after the match. For input `12345` this gives us:
```
1,2345;12345
12,345;12345
123,45;12345
1234,5;12345
12345
```
I.e. every possible splitting of the input along with a pair of the input. We don't need that last line though so:
```
G-2`
```
We discard it.
```
\d+|,
$*
```
This replaces each number as well as the comma with its unary representation. Since the comma isn't a number, it's treated as zero and simply removed. This adds the two parts in each splitting.
```
(1+);\1*
```
This computes the modulo by removing all copies of the first number from the second number.
```
1
```
That's it, we simply count how many `1`s are left in the string and print that as the result.
[Answer]
# Pyth, 14 bytes
```
s.e%QssMc`Q]k`
```
A program that takes input of an integer and prints the result.
[Test suite](http://pyth.herokuapp.com/?code=s.e%25QssMc%60Q%5Dk%60&test_suite=1&test_suite_input=47852%0A13%0A111%0A12345%0A54321%0A3729105472&debug=0)
**How it works**
```
s.e%QssMc`Q]k`   Program. Input: Q
s.e%QssMc`Q]k`Q  Implicit input fill
 .e          `Q  Map over str(Q) with k as 0-indexed index:
        c`Q]k     Split str(Q) into two parts at index k
      sM          Convert both elements to integers
     s            Sum
   %Q             Q % that
s                Sum
                 Implicitly print
```
[Answer]
## Haskell, 62 bytes
```
f x|m<-mod x=sum[m$div x(10^k)+m(10^k)|(k,_)<-zip[0..]$show x]
```
Defines a function `f`.
[See it pass all test cases.](http://rextester.com/TDY24542)
[Answer]
# [Perl 6](https://perl6.org), 33 bytes
```
{sum $_ X%m:ex/^(.+)(.+)$/».sum}
```
## Expanded:
```
{                  # bare block lambda with implicit parameter ｢$_｣
  sum
    $_             # the input
    X%             # cross modulus
    m :exhaustive /  # all possible ways to segment the input
      ^
      (.+)
      (.+)
      $
    /».sum         # sum the pairs
}
```
[Answer]
## Mathematica, 75 bytes
```
Tr@ReplaceList[IntegerDigits@#,{a__,b__}:>Mod[#,FromDigits/@({a}+{b}+{})]]&
```
This uses pattern matching on the list of digits to extract all partitions of them into two parts. Each such partition into `a` and `b` is then replaced with
```
Mod[#,FromDigits/@({a}+{b}+{})]
```
The notable thing here is that sums of lists of unequal length remain unevaluated, so e.g. if `a` is `1,2` and `b` is `3,4,5` then we first replace this with `{1,2} + {3,4,5} + {}`. The last term is there to ensure that it still remains unevaluated when we evenly split an even number of digits. Now the `Map` operation in Mathematica is sufficiently generalised that it works with any kind of expression, not just lists. So if we map `FromDigits` over this sum, it will turn each of those lists back into a number. At that point, the expression is a sum of integers, which now gets evaluated. This saves a byte over the more conventional solution `Tr[FromDigits/@{{a},{b}}]` which converts the two lists first and then sums up the result.
[Answer]
# [Actually](https://github.com/Mego/Seriously), ~~16~~ 15 bytes
Golfing suggestions welcome! [Try it online!](https://tio.run/nexus/actually#@2/9aOp0lZyihEdTlzyaOidFG0ioJvieW/z/v4m5hakRAA "Actually – TIO Nexus")
**Edit:** -1 byte thanks to Teal pelican. 
```
;╗$lr`╤╜d+╜%`MΣ
```
**Ungolfing**
```
         Implicit input n.
;╗       Save a copy of n to register 0.
$l       Yield the number of digits the number has, len_digits.
r        Yield the range from 0 to len_digits - 1, inclusive.
`...`M   Map the following function over that range, with variable x.
  ╤        Yield 10**x.
  ╜        Push a copy of n from register 0.
  d        Push divmod(n, 10**x).
  +        Add the div to the mod.
  ╜        Push a copy of n from register 0.
  %        Vectorized modulo n % x, where x is a member of parition_sums.
         This function will yield a list of modulos.
Σ        Sum the results together.
         Implicit return.
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 63 bytes
```
N+C+M:-N>C,N+C*10+T,M is N mod(N//C+N mod C)+T;M=0.
N-M:-N+1+M.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/30/bWdvXStfPzlkHyNQyNNAO0fFVyCxW8FPIzU/R8NPXd9YGMxWcNbVDrH1tDfS4/HRBOrQNtX31/lvpKpiYW5ga6frqKBQUZeaVaPhq6v0HAA "Prolog (SWI) – Try It Online")
-1 thanks to Jo King
More interesting:
# [Prolog (SWI)](http://www.swi-prolog.org), 104 bytes
```
X/Y:-number_codes(X,Y).
N-M:-findall(N mod(A+B),(N/C,append(X,Y,C),X\=[],Y\=[],A/X,B/Y),L),sumlist(L,M).
```
[Try it online!](https://tio.run/##HcpNC8IgHIDxe5/Co9LfCVEUgx3crptnpSJWWgi@oRt9fHu5PIcfT8rRxRctb1urZKqlYfV3k2@PqE3BEhRpNoJOLX3aoGfnsEA@asy3PQEs2ABzSibo3wkDAXnpzldQ/3ImoWeKwEigrN7ZsuARJtLUlqL98XTYIYo4oJRtWDD/@gc "Prolog (SWI) – Try It Online")
[Answer]
# Ruby, 64 bytes
```
->s{s.size.times.reduce{|a,i|a+s.to_i%eval(s[0,i]+?++s[i..-1])}}
```
Takes the input as a string
[Answer]
# Befunge, ~~101~~ 96 bytes
```
&10v
`#v_00p:::v>+%\00g1+:9
*v$v+55g00</|_\55+
\<$>>\1-:v ^<^!:-1 
+^+^*+55\_$%\00g55
.@>+++++++
```
[Try it online!](http://befunge.tryitonline.net/#code=JjEwdgpgI3ZfMDBwOjo6dj4rJVwwMGcxKzo5Cip2JHYrNTVnMDA8L3xfXDU1KwpcPCQ-PlwxLTp2IF48XiE6LTEgCiteK14qKzU1XF8kJVwwMGc1NQouQD4rKysrKysr&input=MzcyOTEwNTQ3Mg)
**Explanation**
```
&              Read n from stdin.
100p           Initialise the current digit number to 1.
               -- The main loop starts here --
:::            Make several duplicates of n for later manipulation.
v+55g00<       Starting top right, and ending bottom right, this
>>\1-:v          routine calculates 10 to the power of the
^*+55\_$         current digit number.
%              The modulo of this number gives us the initial digits.
\              Swap another copy of n to the top of the stack.
_\55+*v        Starting bottom left and ending top left, this
^!:-1\<          is another calculation of 10 to the power of
00g55+^          the current digit number.
/              Dividing by this number gives us the remaining digits.
+              Add the two sets of digits together.
%              Calculate n modulo this sum.
\              Swap the result down the stack bringing n back to the top.
00g1+          Add 1 to the current digit number.
:9`#v_         Test if that is greater than 9.
00p            If not, save it and repeat the main loop.
               -- The main loop ends here --
$$             Clear the digit number and N from the stack.
++++++++       Sum all the values that were calculated.
.@             Output the result and exit.
```
[Answer]
# APL, 29 bytes
```
{+/⍵|⍨{(⍎⍵↑R)+⍎⍵↓R}¨⍳⍴1↓R←⍕⍵}
```
`⎕IO` must be `1`.
Explanation (I'm not good at explaining, any imporvements to this are **very** welcome):
```
{+/⍵|⍨{(⍎⍵↑R)+⍎⍵↓R}¨⍳⍴1↓R←⍕⍵}
{                           } - Function (Monadic - 1 argument)
                           ⍵  - The argument to the function
                          ⍕   - As a string
                        R←    - Stored in R
                      1↓      - All except the first element
                    ⍳⍴        - 1 to the length
      {           }           - Another function
               ⍵↓R            - R without ⍵ (argument of inner function) leading digits
              ⍎               - As a number
             +                - Plus
       (    )                 - Grouping
         ⍵↑R                  - The first ⍵ digits of R
        ⍎                     - As a number
                   ¨          - Applied to each argument
   ⍵|⍨                        - That modulo ⍵ (outer function argument)
 +/                           - Sum
```
[Answer]
# C#, 67 bytes
```
n=>{long d=n,s=0,p=1;while(d>9)s+=n%((d/=10)+n%(p*=10));return s;};
```
Full program with ungolfed, explained method and test cases:
```
using System;
public class Program
{
    public static void Main()
    {
        Func<long,long> f=
        n=>
        {
            long d = n, // stores the initial number
                 r,         // remainder, stores the last digits
                 s = 0, // the sum which will be returned
                 p = 1; // used to extract the last digit(s) of the number through a modulo operation
            while ( d > 9 ) // while the number has more than 1 digit
            {
                d /= 10;    // divides the current number by 10 to remove its last digit
                p *= 10;    // multiplies this value by 10
                r = n % p;  // calculates the remainder, thus including the just removed digit
                s += n % (d + r);   // adds the curent modulo to the sum
            }
            return s;   // we return the sum
        };
                
        // test cases:
        Console.WriteLine(f(47852)); //5842
        Console.WriteLine(f(13));   // 1
        Console.WriteLine(f(111));  // 6
        Console.WriteLine(f(12345));    // 2097
        Console.WriteLine(f(54321));    // 8331
        Console.WriteLine(f(3729105472));   // 505598476
    }
}
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/attache), 48 bytes
```
Sum@{N[_]%Sum@Map[N]=>SplitAt[_,1..#_-1]}@Digits
```
[Try it online!](https://tio.run/##Lci9CsIwFIbhPVdRsG6xmD@qg1Kxq0Wo2yGUUE9qQEswcRKvPf71W96Hz8Ro@gumGq0bEXJLU/u4Vc8GOj3/6mA8NHqzbf3VxV2EjrKimHULpl9V7QYXQyKakAbxHCD3vh80Od7dGE8Y4t4EDGBpBiT7TJYrxemPTExlbAIXUv2ppODTK0q@ZkslS060Tm8 "Attache – Try It Online")
## Explanation
```
Sum@{N[_]%Sum@Map[N]=>SplitAt[_,1..#_-1]}@Digits
                                          Digits    convert input to digits
    {                                   }@          call lambda with digits as argument
                      SplitAt[_,1..#_-1]            split digits at each partition
              Map[N]=>                              Map N to two-deep elements
          Sum@                                      Takes the sum of each sub array
     N[_]%                                          convert digits to int and vector mod
Sum@                                                sum the resultant array
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 15 bytes
```
a%$+(a^@_)MS,#a
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJhJSQrKGFeQF8pTVMsI2EiLCIiLCIiLCI0Nzg1MiJd)
### Explanation
```
a%$+(a^@_)MS,#a
              a  Program argument: the input number
            ,#   Range(length)
          MS     Map this function to each of those numbers and sum the results:
     a^@_          Split the input number at that index
  $+(    )         Sum the two halves
a%                 Take the input number modulo the sum
```
Using range(len) as the list of indices to split on means that in addition to `4785+2`, `478+52`, `47+852`, and `4+7852`, we also have `+47852`. However, a number modulo itself is 0, which doesn't change the sum, so that's no problem.
[Answer]
**Clojure, ~~91~~ 81 bytes**
Edit: this is shorter as it declares an anonymous function `(fn[v](->> ...))` and not using `->>` macro although it was easier to read and call that way.
```
(fn[v](apply +(map #(mod v(+(quot v %)(mod v %)))(take 10(iterate #(* 10 %)1)))))
```
Original:
```
(defn s[v](->> 1(iterate #(* 10 %))(take 10)(map #(mod v(+(quot v %)(mod v %))))(apply +)))
```
Generates a sequence of 1, 10, 100, ... and takes first 10 items (assuming input values are less than 10^11), maps to modulos as specified in specs and calculates the sum. Long function names makes this solution quite long but at least even the golfed version should be quite easy to follow.
First I tried juggling strings around but it required tons of boilerplate.
[Answer]
## Racket 134 bytes
```
(let((s(number->string n))(h string->number)(g substring))(for/sum((i(range 1(string-length s))))(modulo n(+(h(g s 0 i))(h(g s i))))))
```
Ungolfed: 
```
(define (f n)
  (let ((s (number->string n))
        (h string->number)
        (g substring))
    (for/sum ((i (range 1 (string-length s))))
      (modulo n (+ (h (g s 0 i)) (h (g s i)))))))
```
Testing: 
```
(f 47852)
(f 13)
(f 111)
(f 12345)
(f 54321)
(f 3729105472)
```
Output: 
```
5842
1
6
2097
8331
505598476
```
[Answer]
## Ruby 45 Bytes
```
->q{t=0;q.times{|x|p=10**x;t+=q%(q/p+q%p)};t}
```
This is a really neat solution. It is technically correct, but it is super inefficient. It would be much more efficient to write q.to\_s.size.times{...}. We use q.times because it saves characters, and the extra number of times it goes through the proc the expression just evaluates to zero. 
[Answer]
# [R](https://www.r-project.org/), 50 bytes
```
function(n)sum(n%%(n%%10^(x=1:nchar(n))+n%/%10^x))
```
[Try it online!](https://tio.run/##FYpBCsIwEADvvsJLYRdXzGazTSLmK0IJBAWNpbVQXx/bw1xmZmrleDu3stT8fX4qVJyXN9Su22FzhzXxtebHMG0JT7W77HZFbAVY8DAP4/j6QQbng1piIWYmtuKU1IllEm8jG3XeIhVMKYMGt53UkzXRUxBhUqMag/M9tj8 "R – Try It Online")
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 92 bytes
```
	N =INPUT
S	N LEN(X) . L REM . R	:F(O)
	S =S + REMDR(N,L + R)
	X =X + 1	:(S)
O	OUTPUT =S
END
```
[Try it online!](https://tio.run/##FYyxCoAgFEXn51e8USmCypbATYPAnqEGzs1RQ/@PvaZ7OBzuez/nc@lagdCstB9ZJEbvSBaFHXqMbuONMC8yKAEJTcLmtzZKav3PrAuawtjDLJMSAcKR@Ytb4cjWOulx6D8 "SNOBOL4 (CSNOBOL4) – Try It Online")
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), 31 bytes
**Solution:**
```
+/(+/+.:''1_(0,'!#$x)_\:$x)!'x:
```
[Try it online!](https://tio.run/##y9bNz/7/X1tfQ1tfW89KXd0wXsNAR11RWaVCMz7GCkgqqldYGZsbWRoamJqYG/3/DwA "K (oK) – Try It Online")
**Example:**
```
+/(+/+.:''1_(0,'!#$x)_\:$x)!'x:47852
5842
```
**Explanation:**
Most of the code goes to building up the lists out of the input. Am wondering if there is a trick I'm missing.
```
{.:''1_(0,'!#$x)_\:$x}47852
(4 7852
47 852
478 52
4785 2)
```
Full breakdown:
```
+/(+/+.:''1_(0,'!#$x)_\:$x)!'x: / the solution
                             x: / store input as variable x
                           !'   / mod (!) each-both (')
  (                       )     / do this together
                        $x      / string x
                     _\:        / cut (_) each-left (\:)
            (       )           / do this together
                  $x            / string x
                 #              / count length of the string
                !               / til, range 0..n-1
             0,'                / prepend 0 to each
          1_                    / drop the first one
      .:''                      / value (.:) each-each (nested)
     +                          / flip rows and columns
   +/                           / sum up the columns
+/                              / sum up results of the modulo
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `s`, ~~14~~ 11 bytes
*-3 bytes thanks to [Lyxal](https://codegolf.stackexchange.com/users/78850/lyxal)*
```
żðvṀṪƛĖ+?$%
```
[Try it online](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwixbzDsHbhuYDhuarGm8SWKz8kJSIsIiIsIjQ3ODUyIl0=), or [verify all test cases](https://vyxal.pythonanywhere.com/#WyJzQSIsIiIsIsW8w7B24bmA4bmqxpvElis/JCUiLCIiLCI0Nzg1MlxuMTNcbjExMVxuMTIzNDVcbjU0MzIxXG4zNzI5MTA1NDcyIl0=).
Explanation:
```
ż            # Range from 1 to the length of the input
  v          # Map each of those to
 ð           # A space
   Ṁ         # Inserted into the input at the nth index (resulting in ["4 7852", "47 852", "478 52", ...])
    Ṫ        # Remove the last one (which has doesn't space)
     ƛ       # On each string with the inserted space:
      Ė      #   Evaluate it as Vyxal code (so push both numbers in the string to the stack)
       +     #   Add them
        ?    #   Push the input
         $   #   Swap the top two items
          %  #   Modulo
             # Sum with the s flag
```
]