[Question]
  [
## The task
In this challenge, your task is to write a program in a programming language **L** that takes a positive integer **n**, and outputs the sum of the proper divisors of **n** ([sequence A001065](http://oeis.org/A001065) on OEIS).
It should return the correct output for any **1 ≤ n ≤ 10 000**.
Here are the first 10 outputs:
```
0, 1, 1, 3, 1, 6, 1, 7, 4, 8
```
Furthermore, your program must be a *fake polyglot*, which means the following.
It is a valid program in another programming language **L'**, and for each input **1 ≤ n ≤ 10** (the test cases above), it returns the sum of proper divisors of **n**, but there exists some **11 ≤ n ≤ 10 000** for which it doesn't return the correct result.
It may return something incorrect, loop forever, crash etc.
It can give a wrong result for all **n ≥ 11**, for some of them or just one.
## Rules and scoring
You can write a full program or a function, and you can have different means of input and output in the two languages.
The lowest byte count wins.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
In this challenge, different major versions or implementations of a language are considered distinct.
Note that if you use programming languages with non-ASCII encodings (as many do on this site), the same *sequence of bytes* must be used for both languages.
This means that you must either convert between potentially different code pages or suffer penalties for multi-byte Unicode characters.
## Additional test cases
```
20 -> 22
36 -> 55
180 -> 366
997 -> 1
2875 -> 869
10000 -> 14211
```
  
[Answer]
## JavaScript (ES6), [V8](https://en.wikipedia.org/wiki/Chrome_V8) / [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) vs [Chakra](https://en.wikipedia.org/wiki/Chakra_(JavaScript_engine)), ~~66~~ 63 bytes
```
n=>[...Array(n)].map((_,d)=>s+=n%d?0:d,[0,n>10].sort(x=>s=x))|s
```
### Demo
```
let f =
n=>[...Array(n)].map((_,d)=>s+=n%d?0:d,[0,n>10].sort(x=>s=x))|s
console.log(JSON.stringify(
  [...Array(20)].map((_, n) => n + 1).map(f)
))
```
### Output
Output of the above snippet on Chrome and Firefox (all correct):
```
[0,1,1,3,1,6,1,7,4,8,1,16,1,10,9,15,1,21,1,22]
```
Output on Edge (off by 1, starting at n = 11):
```
[0,1,1,3,1,6,1,7,4,8,2,17,2,11,10,16,2,22,2,23]
```
### Why?
No algorithm is imposed by the specification for the `.sort()` method. It's not even required to be stable. Therefore, each JavaScript engine uses its very own implementation.
However, `[0,1].sort(x=>x)` gives `[0,1]` with all engines.
So what's the difference?
What's happening here is that Chakra is passing `1` as the first parameter of the first (and only) iteration to the callback function (asking for a comparison of `1` with `0`), while V8 and SpiderMonkey are passing `0` (asking for a comparison of `0` with `1`).
You can use the following snippet to check what your browser is doing.
```
[0, 1].sort((x, y) => console.log("Let's compare " + x + " with " + y + "!"))
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E) / [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 bytes
The byte-code (hexadecimal):
```
d1 a8 4f 71 0d ad 53 fa
```
Using [Jelly's code-page](https://github.com/DennisMitchell/jelly/wiki/Code-page) returns incorrect results for any [excessive](https://en.wikipedia.org/wiki/Abundant_number) number (e.g. an input of **12** returns `12` rather than `16`):
```
ẎƭOqÆḌS«
```
**[Try it online!](https://tio.run/##y0rNyan8///hrr5ja/0LD7c93NETfGj1////DY0A "Jelly – Try It Online")**
Using [05AB1E's code-page](https://github.com/Adriandmen/05AB1E/blob/master/docs/code-page.md) returns correct results:
```
Ñ¨OqмλSú
```
**[Try it online!](https://tio.run/##MzBNTDJM/f//8MRDK/wLL@w5tzv48K7//w2NAA "05AB1E - Try It Online")**
### How?
05AB1E parses up to and including the `71` (`q`) which instructs to quit and then stops parsing:
```
Ñ¨Oq - Takes input from stdin
Ñ    - get divisors
 ¨   - remove right-most (the input value itself - yielding proper divisors)
  O  - sum
   q - quit (causing an implicit print of the top of the stack)
...мλSú is never parsed
```
Jelly parses the whole program up-front as three links due to the effect of the bytes without an assigned meaning, `ƭ` and `q` acting as delimiters. The entry point of a program is it's final link:
```
Ẏ - Link 1 (never used), tighten list
...ƭ delimits links 1 & 2)
O - Link 2 (never used), cast from characters to their ordinals
...q delimits link 2 and the main link
ÆḌS« - Main link: number, n
ÆḌ   - proper divisors
  S  - sum
   « - minimum of that and n
     - as a full-program: implicit print
```
[Answer]
# Python 2 and Python 3, 58 bytes
[TIO for Python 2](https://tio.run/##Xck7DoAgDADQ3VN0MVDDICYuRm7AEVwg/ppoMRUHT4@7b33Xm/fEXfFuKkc44xyAh/s5NTWaR2uTKOVcVArXJEBADBJ4W7Q1jLQC1zRaLL/sWxwquIQ4AxnwmrB8)
[TIO for Python 3](https://tio.run/##Xck7DoAgDADQ3VN0MbTGQWJcDNyAI7hA/DWRYlAHT4@7b33ne@9J@uLsVA4fw@xBxuuJyA2K0TplpawNStGaMjCwQPayLahbIV5Bajaayi@HjsYKzsxyA3ILDpmofA)
```
lambda n:sum(i*(n<11or''==b'')for i in range(1,n)if n%i<1)
```
It works in python 2, but for every n > 10 it would output 0 in python 3.  
All because of different approaches in comparing strings with bytes: 
* in Python 2 `'' == b''`
* in Python 3 `'' != b''`
[Answer]
# [JavaScript (Node.js)](https://nodejs.org) and [PHP](https://php.net/), ~~73~~ 70 bytes
```
function($n){for($d=$i=0;++$i<$n;)$d+=$i*!($n%$i);return"$n">10?0:$d;}
```
In both languages, this is an anonymous function. JavaScript gives the correct result, but PHP gives **0** for all **n >= 11**.
[Try it JS!](https://tio.run/##DctNCsIwEEDhq8QwQuKgpAs3nUbPUvIjI2VS0taNePaY7eN77/kzb6Hyul@lxNSy8i0fEnYuYkDsN5dqIHpg7wgReAIhCxF7uZy6OANbqmk/qmgQ/Rjc040Q6df6qQz7gXi6O2JEq0KRrSzptpSXYdSj0pgNW0vtDw "JavaScript (Node.js) – Try It Online")
[Try it PHP!](https://tio.run/##HYuxCsMgFEX3foV93EKsIGbokhebH@kWI7o8JSRT6Ldb6XKGwzk11TYvNdUbovItnrIeucgA0Vcs@4Dgkb1jY5BnCGsE083z3osHsuZ9O85dCELv0S1uQuBv4/@a/cj9erlOY7Ta1lQUsqVJkUXsgbb0EeL2Aw "PHP – Try It Online")
### How it works
Both languages do the same thing at first: iterate from 1 up to n-1, keeping a running sum of all numbers **i** for which **n % i = 0**.
What causes the difference in behaviour is the final part:
```
return"$n">10?0:$d;
```
In JavaScript, `"$n"` is just a string literal. The comparison `>` with `10` casts it to a number implicitly, but since it doesn't look like a number, it becomes NaN. NaN gives false when compared with a number in any way. As a result, `$d` is always returned.
However, in PHP, `"$n"` is a string containing the value of `$n`. When PHP casts this to a number, it simply becomes the value of `$n`. If it's greater than `10`, then `0` is returned instead of `$d`.
[Answer]
# [Python 3](https://docs.python.org/3/) / [Python 2](https://docs.python.org/2/), ~~64~~ ~~60~~ 58 bytes
*Thanks to @officialaimm for 2 bytes off*
```
lambda n:sum(d*(round((n>10)*.5)==n%d)for d in range(1,n))
```
In Python 3 this gives the correct results. In Python 2 the ouput is wrong for inputs exceeding `10`. The code exploits banker's rounding, which is done by Python 3 but not by Python 2.
Try it online! [Python 3](https://tio.run/##NckxDoQgEAXQq9CYzBhjcI2NCZ7Ehs3ISiIfglh4etzG1750lz1irM6s9bDhK1ZhPq9A0lKOF4QIy6C57Sc2Bo2wi1mJ8lDZ4rfR0IG5puxR6PBnoWATue7Nj@a/@gA) (correct), [Python 2](https://tio.run/##NclBCsMgEAXQq8ymMBMkJIFuCvYk2VgmtkL8ippFTm@6ydu@fLZfwtK9Xfvu4kcd4VWPyDpwSQeUGe95kmF8irV4qPhUSCmAisN349lApOcS0GgPtXF0mb25c5nk3xc) (wrong for `n > 10`).
[Answer]
# [Python 3](https://docs.python.org/3/) / [Python 2](https://docs.python.org/2/), 47 bytes
```
lambda n:sum(d*(n%d<1)for d in range(10/n>0,n))
```
An unnamed function, fake in Python 2.
Try it online for **[Python 3](https://tio.run/##VU67jsIwEKyTr9gmwgYDNoingAp@4u4oDN6ApWQTeQ2Crw8JR8MU08yzfsZrRdMm3/41hS1PzgKt@VYK1xeUuY2ReRXAgScIli4ojB7TTiuSsumUiBw7sfAcxcehwBgpYQC/E62mc2WWWq1WCzVZLmbK6BbHdZrE8Gw5Cci3IsIWctF1yTTBxxnrCD8Yqr2/e/YVHUJotywDfkVwVCKzvWCa1MFTFL1s5mC4g4x72btOwb@5fdu8AA "Python 3 – Try It Online")** or **[Python 2](https://tio.run/##VU7LUoMwFF3DV9wN06TGmuBQ2o5lZX@i6iKaC2YGLkxu2pGvR2jdeBZnc57DGL97yqf6@D61tvt0FujAl064taDMvRhZ9wEceIJgqUFh9BNVWpGU06JE5LiIreco/hwKjJESHuAt1@p5q8xOq/2@VPmuLJTRMz4OaRLDOHMSkC9thCPUYumSaYI/XzhEOGPoX/3Vs@/pFMK8ZRnwXwQ3HTLbBtNkCJ6iWGWFg8cKMl5ltzoFd/P8dvoF "Python 2 - Try It Online")**
In Python 2 `/` is integer division with integer arguments, whereas in Python 3 it is division.
When `n` exceeds **10** `10/n` evaluates to **0** in Python 2, but to a small positive number in Python 3 (this is certainly true up to the maximum required of **10,000** at least).
As such `10/n>0` evaluates to `True` for Python 3 and `range(10/n>0,n)` is equivalent to `range(1,n)` while in Python 2 `10/n>0` evaluates to `False` when `n` exceeds **10** whereupon `range(10/n>0,n)` becomes equivalent to `range(0,n)` causing `n%d` to attempt to perform modulo zero arithmetic, raising a `ZeroDivisionError`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly) / [05AB1E](https://github.com/Adriandmen/05AB1E), 12 bytes
What Jelly sees:
```
11⁻iẎƭO}qÆḌS
```
[Try it online!](https://tio.run/##y0rNyan8/9/Q8FHj7syHu/qOrfWvLTzc9nBHT/B/oLABAA "Jelly – Try It Online")
Explanation:
`q` is unsupported in Jelly, so Jelly only "sees" what's after the `q`.
```
ÆḌS
ÆḌ  Proper divisors
  S Sum
```
What 05AB1E sees:
```
11‹iÑ¨O}qмλS
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f0PBRw87MwxMPrfCvLbyw59zuYJAYAA "05AB1E – Try It Online")
Explanation:
```
11‹iÑ¨O}qмλS Implicit input multiple times
11           Push 11
  ‹          Less than 11?
   i   }     If equals 1, then
    Ñ         Divisors
     ¨        Remove last
      O       Sum
       q     Implicit print and quit
        м    Negative filter
         λ   Undefined, ignored error
          S  Split into chars
```
Of course everything after "quit" doesn't actually happen.
]