Books, groceries, bank accounts, and credit cards are all identified mainly by a number, and those numbers often run to many digits. Transcribing one is easy to get wrong, so most numbering schemes carry a mechanism that detects errors and sometimes corrects them.
The simplest scheme appends a single check digit. Multiply the rightmost digit by 2, the digit to its left by 3, and so on, raising the weight by 1 at every step to the left, then add all the products. Divide that sum by 11 and subtract the remainder from 11. If the result lies between 1 and 9, append it to the right end of the number. If the result is 11, append the digit 0 as the check digit. If the result is 10, reject the original number.
To test whether a complete number is correct, multiply successive digits from the right by 1, 2, 3, ... and add the products. The number is good when that sum is divisible by 11, and bad otherwise.
Take the number 2763. Multiply 3 by 2 to get 6; multiply 6 by 3 to get 18 and add for 24; multiply 7 by 4 to get 28 and add for 52; multiply 2 by 5 to get 10 and add for 62. Dividing 62 by 11 leaves a remainder of 7, and 11 minus 7 gives the check digit 4, so the full number is 27634. Check for yourself that the test works in the other direction, and that changing any digit, or even swapping two digits, makes the number bad.
Write a program that reads a series of numbers, each at most 15 digits long, and produces the check digit for each one.
The input is a series of numbers, one per line. Each number consists of decimal digits only with no embedded whitespace, and is at least 1 and at most 15 digits long. The input ends with a line containing a single #.
Print one line for every number in the input, excluding the terminating #. Each line holds the original number, then the four characters ->, then either the check digit or the word Rejected.