[Question]
  [
Given a standard combination lock like the one in the picture. The way to unlock it is to align the 4 numbers in the code on the combination line. After years of loyal service you have been fired from the lock factory and have decided to exact revenge by not jumbling up the locks before you send them off, thus leaving every lock with the combination to unlock it on the combination line.
![Combination lock](https://i.stack.imgur.com/Zwexf.jpg)
You also know that by looking at the order of the numbers in the other lines it is possible to work out what numbers must be on the combination line (and therefore the combination to unlock it is). 
If every line on the lock is given a number starting from line 0 for the combination line (the line which unlocks the lock) to line 9. For example, if the numbers on line 4 are `5336`, then the combination to unlock it would be `1992`.
Unfortunately the locks have already been packaged and your view of each lock is obscured, so you can only see numbers on different lines of the lock.
**The Challenge**
Given 4 pairs of digits, where the first digit of the integer represents the line number and the second digit represents the the number which appears on that line, work out the combination to the lock.
For example if you input: 
```
57 23 99 45
```
Then it should output:
```
2101
```
Or
```
25 78 63 15
```
and
```
3174
```
Assume the input will always be 4 positive integers in the form `25 64 72 18.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest programs in number of bytes wins.
Also this is my first question, so any feedback is appreciated.
  
[Answer]
# CJam, ~~9~~ 8 bytes
```
ea9fbAf%
```
Reads the digit pairs as command-line arguments. To [try the code online](http://cjam.aditsu.net/), change `ea` to `lS/` to read from simulated STDIN.
### Example run
```
$ cjam <(echo ea9fbAf%) 57 23 99 45; echo
2101
$ cjam <(echo ea9fbAf%) 25 78 63 15; echo
3174
```
### How it works
The character code of the digit **d** is **48 + d**. Thus, considering the two-digit string **xy** a base 9 number yields **9 \* (48 + x) + (48 + y) = 10 \* (48 + x) + y - x ≡ y - x (mod 10)**.
```
ea       " Push the array of command-line arguments.                                      ";
  9fb    " Mapped base 9 conversion; replace each string 'xy' with (9 * ord(x) + ord(y)). ";
     Af% " Take the results modulo 10.                                                    ";
```
[Answer]
# CJam, ~~13~~ ~~12~~ 11 characters
Thanks to user23013, its now down to 11 characters :)
```
4{Ar:--A%}*
```
Explanations:
```
4{       }*     "Run the code block 4 times";
   r            "Read the next input token (whitespace separated)";
    :-          "Subtract 2nd number from the first treating r as a 2 numbered string";
  A   -         "Subtract the result of above from 10";
       A%       "Take modulus of 10 and store it on stack";
```
[Try it online](http://cjam.aditsu.net/)
I know it can be golfed more. But this is my first real attempt on CJam and I am limited by experience :)
---
Alternatively, the other methods to do the same thing in 1 extra character:
```
l~]{_A/-A%}/     // My previous solution
```
or
```
4{ri_A/-A%}*     // As pointed out by Ingo
```
or
```
ea{i_A/-A%}/     // If input is passed through command line
```
[Answer]
# Golfscript (14 ~~13~~)
[Try it online here](http://golfscript.apphb.com/?c=OyIyNSA3OCA2MyAxNSIKfl17LjEwOl4vLV4lfS8%3D)
It's pretty much the same as [Optimizer's solution](https://codegolf.stackexchange.com/a/37790/26765), but in a different language. It's hard to approach it in a different way because the problem is fairly simple~~, so the tie definitely goes to Optimizer, whose entry was earlier anyway.~~
```
~]{.10:^/-^%}/
```
For the same number of bytes you can do
```
~]{.10/- 10%}/
```
[Answer]
# [GNU dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 14 bytes
Borrowing [@Dennis's clever base 9 trick](https://codegolf.stackexchange.com/a/37815/11259):
```
9i[?A%nd]dxxxx
```
Input integers read from STDIN, one per line.
### Explanation:
```
9i                # Set input radix to 9
  [     ]         # push a macro, defined thus:
   ?              #   read number from STDIN and push
    A             #   push literal 10
     %            #   calculate number mod 10
      n           #   print, with no newline
       d          #   duplicate macro
         d        # duplicate macro
          xxxx    # execute the macro 4 times    
```
### Output:
```
$ for i in 57 23 99 45; do echo $i; done | dc ./combolock.dc
2101$ 
$ for i in 25 78 63 15; do echo $i; done | dc ./combolock.dc
3174$ 
$ 
```
---
### Previous Answer, 18 bytes:
Because I thought I could get closer to the "golfing" languages with this (but didn't):
```
[A?A~--A%n]dddxxxx
```
[Answer]
**C 64 63 56 or 61**
If the input can be piped from file
```
main(a){while(scanf("%d",&a)>0)putchar(48+(a-a/10)%10);}
```
If the input should be typed to stdin
```
i;main(a){for(;i++-4;putchar(48+(a-a/10)%10))scanf("%d",&a);}
```
Reads the four numbers in a loop and then processes each by subtracting the first digit from the value and printing the result modulo 10.
Savings thanks to various comments below and also using putchar instead of printf
[Answer]
## Python 3 , 64
Straightforward. 
```
print(''.join([(i-i//10)%10 for i in map(int,input().split())]))
```
It can be shorter if I'm allowed to print, say, `[2, 1, 0, 1]` instead (**46**):
```
print([i%10-i//10 for i in map(int,input().split())])
```
[Answer]
# C, 92
```
#define a(n) ,(10+v[n][1]-*v[n])%10
main(int c,char**v){printf("%d%d%d%d"a(1)a(2)a(3)a(4));}
```
Input from commandline. Subtracts the first ASCII code of each argument from the second, adds 10 and takes modulo 10.
I think this is the first time I've written a `printf` with four `%`s and no comma (the comma is in the `#define.`)
[Answer]
## Java - 203 bytes
Just because there *has* to be a Java entry, I saw a nice opportunity to give this code golfing a chance (first submission ever).
```
class M{public static void main(String[] a){String r="";for(int i=0;i<4;i++){int l=Byte.valueOf(a[i].substring(1));int f=Byte.valueOf(a[i].substring(0,1));r+=(l-f<0)?l-f+10:l-f;}System.out.print(r);}}
```
If there's room for some improvements, I'd glad to know about them ;-)
[Answer]
# Lua - 46 characters
```
while''do a,b=io.read(1,1,1)print((b-a)%10)end
```
Reads three characters at a time (grant me the small mercy of inputing a space at the end), and eventhough a and b are string-y... b-a MAGICALUALY allows them to conceive a healthy baby integer. Does the wrap-around check while printing.
![How I run it:](https://i.stack.imgur.com/1cBBd.jpg)
[Answer]
# JavaScript ES6 – ~~53~~ 43 bytes
```
f=n=>n.replace(/.. ?/g,a=>(1+a[1]-a[0])%10)
```
Fairly straightforward function, uses regex to get the numbers. Try it out at <http://jsfiddle.net/efc93986/1/>. If functions are not allowed, a standalone program at 52 bytes:
```
alert(prompt().replace(/.. ?/g,a=>(1+a[1]-a[0])%10))
```
As ES6 currently only works on Firefox, the following code works on any modern browser, at 70 bytes:
```
alert(prompt().replace(/.. ?/g,function(a){return(1+a[1]-a[0])%10}))
```
[Answer]
# Python 2 - 33 bytes
```
for i in input():print(i-i/10)%10
```
Accepts comma-delimited user input.
E.g. Input:
```
29,26, 31, 88
```
Output:
```
7
4
8
0
```
If output is required to exactly match the example then it is much longer. 47 bytes:
```
print"%d"*4%tuple((i-i/10)%10 for i in input())
```
[Answer]
## APL, 14
```
10|{--/⍎¨⍕⍵}¨⎕
```
**Explaination**  
`⎕` takes input from screen. Space-separated values are parsed as an array.  
`{...}¨` for each number, feed it into function.  
`⍎¨⍕⍵` takes the argument, create an array of its digits.  
`--/` calculates units minus tens.  
`10|` mod 10.
[Answer]
## J - 20 15
The non-verb form (as statement instead of function definition) it's 5 characters shorter:
```
10|-~/|:10#.inv
```
The verb form which is a nice [train](http://www.jsoftware.com/help/dictionary/dictf.htm): 
```
10|[:-~/[:|:10#.inv]
```
This verb used on the example inputs:
```
   10|-~/|:10#.inv 57 23 99 45
2 1 0 1
   10|-~/|:10#.inv 25 78 63 15
3 1 7 4
rotd =: 10|[:-~/[:|:10#.inv] NB. verb form
   rotd 25 78 63 15
3 1 7 4
   rotd 57 23 99 45
2 1 0 1
```
[Answer]
# Haskell 60 58
```
main=interact$show.map((\x->mod(x-x`div`10)10).read).words
```
Single character digits, a real nemesis in Haskell golfing.
[Answer]
# Perl: 38 40
```
print abs($_-int$_/10)%10for split" ",<>
```
Output:
```
% perl code.pl
57 23 99 45
2101
25 78 63 15                                     
3174
```
[Answer]
## Ruby, 35 bytes
```
$*.map{|n|a,b=n.bytes;$><<(b-a)%10}
```
### Explanation
Input is taken as command line arguments. `String#bytes` returns an Array of Integers (ASCII character codes). Only the difference between the last and first character code is of importance, not the Integers themselves.
[Answer]
**C# & LinqPad: 104** 
```
Util.ReadLine<string>("").Split(' ').Select(s =>(s[1]-s[0])).Aggregate("",(r,a)=>r+(a<0?10+a:a)).Dump();
```
[Answer]
## C++ 118
```
int main()
{
int a,b,c;
for(int i=0; i<4; i++)
{
cin>>a;
b=a/10;
a=a%10;
c=a-b;
if(c<0)c+=10;
cout<<c;
}
}
```
[Answer]
# PHP - 90 characters
Thought I'd give code golf a try so here it is, my first attempt - can probably be golfed more.
```
<?php $a=array(57,23,99,45);foreach($a as$b){echo abs(substr($b,0,1)-substr($b,1,1)%10);}
```
## 58 characters (courtesy of Ismael Miguel)
```
for($i=0,$a=$_GET[n];$i<8;)echo abs($a[$i++]-$a[$i++]);
```
Access file using 
```
file.php?n=57239945
```
[Answer]
# Python 3, 60
```
for x in input().split():print(-eval('-'.join(x))%10,end='')
```
Input and output exactly as specified, although it doesn't print a trailing newline. Two interesting tricks here: 1) replacing two calls to `int()` with one call to `eval()`, and 2) using `join()` to get `a-b`, then negating it for `b-a` as required. Fortunately Python's modulo operator gives positive values even if the first argument is negative!
]