Implement the divisibility-by-7 rule To check whether a decimal number is divisible by 7:


  Erase the last digit. Multiply it by 2 and subtract from what is left. If the result is divisible by 7, the original number is divisible by 7.


(also described e.g. here)

This rule is good for manual divisibility check. For example:


  Is 2016 divisible by 7?
  
  Subtract 6*2 from 201; we get 189. Is this divisible by 7? To check it, let's apply the rule again.
  
  Subtract 9*2 from 18; we get 0. Therefore, 2016 is divisible by 7.


In this challenge, you should apply this rule until the divisibility status is obvious, that is, the number is not greater than 70 (however, see below for details). Make a function or a full program.

Input: a positive integer; your code should support inputs up to 32767 (supporting arbitrary-precision integers is a bonus; see below).

Output: an integer (possibly negative), not greater than 70, that is a result of applying the divisibility-by-7 rule zero or more times.

Test cases:

Input                   Output      Alternative output

1                       1
10                      10          1
100                     10          1
13                      13          -5
42                      42          0
2016                    0
9                       9
99                      -9
9999                    -3
12345                   3
32767                   28          -14

---------- Values below are only relevant for the bonus

700168844221            70          7
36893488147419103232    32          -1
231584178474632390847141970017375815706539969331281128078915168015826259279872    8


Where two possible outputs are specified, either result is correct: the second one corresponds to applying the rule one more time. It's forbidden to apply the rule on a single-digit number: if you erase the digit, nothing (not 0) is left.



Bonus: If your algorithm


Supports arbitrary-precision integers
Performs only one pass on the input
Has space complexity o(n) (i.e. less than O(n)); and
Has time complexity O(n),


where n is the number of decimal digits:

Subtract 50% from your code's byte count.

Real bonus:

In addition, if your algorithm reads the input in normal direction, starting from the most significant digit, subtract 50% once again - your score is 25% of your byte count (it seems possible, but I'm not absolutely sure).
Golfscript, 27 22 bytes

{.9&gt;{.10/\10%2*-f}*}:f


You can use it this way:

1000f


Explanation

{.9&gt;{.10/\10%2*-f}*}:f
{                  }:f    # Define block 'f' (similar to a function)
 .                        # Duplicate the first value of the stack
  9&gt;{            }*       # If the value on top of the stack is greater than 9 then the block is executed
     .10/\10%2*-          # Same as nb/10 - (nb%10 * 2) with some stack manipulations '.' to duplicate the top of the stack and '\' to swap the the first and second element of the stack
                f         # Execute block 'f'


5 bytes saved thanks to Dennis !