Skip to main content
added 11 characters in body
Source Link
Andreas Louv
  • 1.7k
  • 13
  • 25

JavaScript ES6, 38 bytesJavaScript ES6, 38 bytes

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i

Fails with 36893488147419103232 and using ~~(1/10) will also fail for 700168844221

Test:

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 38 bytes

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i

Fails with 36893488147419103232 and using ~~(1/10) will also fail for 700168844221

Test:

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 38 bytes

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i

Fails with 36893488147419103232 and using ~~(1/10) will also fail for 700168844221

Test:

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

added 16 characters in body
Source Link
Andreas Louv
  • 1.7k
  • 13
  • 25

JavaScript ES6, 30 bytesJavaScript ES6, 38 bytes

a=i=>i>70?a(~~Math.floor(i/10)-i%10*2):i

Fails with 36893488147419103232 and using ~~(1/10) will also fail for 700168844221

Test:

a=i=>i>70?a(~~Math.floor(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 30 bytes

a=i=>i>70?a(~~(i/10)-i%10*2):i

Test:

a=i=>i>70?a(~~(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 38 bytes

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i

Fails with 36893488147419103232 and using ~~(1/10) will also fail for 700168844221

Test:

a=i=>i>70?a(Math.floor(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

added 11 characters in body
Source Link
Andreas Louv
  • 1.7k
  • 13
  • 25

JavaScript ES6, 30 bytesJavaScript ES6, 30 bytes

a=i=>i>70?a(~~(i/10)-i%10*2):i

Test:

a=i=>i>70?a(~~(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 30 bytes

a=i=>i>70?a(~~(i/10)-i%10*2):i

Test:

a=i=>i>70?a(~~(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

JavaScript ES6, 30 bytes

a=i=>i>70?a(~~(i/10)-i%10*2):i

Test:

a=i=>i>70?a(~~(i/10)-i%10*2):i
O.textContent = O.textContent.replace(/(-?\d+) +(-?\d+)/g, (_,i,o) =>
  _+": "+(a(+i)==o?"OK":"Fail")
);
<pre id=O>1                       1
10                      10
100                     10
13                      13
42                      42
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
700168844221            70
36893488147419103232    32</pre>

added 690 characters in body
Source Link
Andreas Louv
  • 1.7k
  • 13
  • 25
Loading
Source Link
Andreas Louv
  • 1.7k
  • 13
  • 25
Loading