# Catch some drug dealers

(spoilers on decade-old TV show below)

In the HBO show "The Wire", the dealers use a system of encoding phone numbers where they "jump the 5" on the number pad.

+-----------+
| 1 | 2 | 3 |
+-----------+
| 4 | 5 | 6 |
+-----------+
| 7 | 8 | 9 |
+-----------+
| # | 0 | * |
+-----------+

A "1" becomes a "9", "4" becomes "6", etc ... and "5" and "0" swap places. So, the input number 2983794-07 becomes 8127316-53. # and * are undefined. Input in the show was numeric with a dash, your code does not need to preserve the dash but it does need to accept it. No real restrictions on how user interaction is handled, can be a function or console application as needed.

Scoring criteria:

This is a code golf, fewest characters wins. There is a 100 character penalty for solving it with a number/character swap or array lookup (I'm trying to broadly paint a brush stroke to avoid "9876043215"[i]-style lookups). 10 character bonus for not stripping dashes.

• Isn't every solution going to use number/character swap with or without a detour? – Martin Ender Oct 21 '14 at 15:04
• Maybe I should make it a pop-con question instead, to get creative answers out of it? – Bryan Boettcher Oct 21 '14 at 15:05
• Isn't this just ten minus each digit? (Beside 5/0) – Geobits Oct 21 '14 at 15:05
• @insta Taking a simple task and saying "solve this creatively", generally makes for a very bad popularity contest. – Martin Ender Oct 21 '14 at 15:06
• "There is a 100 character penalty for solving it with a number/character swap or array lookup." This is a vague and unenforceable rule. If your challenge has a boring optimal solution, you should rethink the challenge rather than try to ban that solution. – xnor Oct 21 '14 at 21:28

# MATLAB, 25 bytes

Function accepting a string.

- is converted to =... so the dash is not just preserved, there is twice as much of it?

@(n)106-n-5*(n==48|n==53)
• LOL twice as much :D – Optimizer Oct 21 '14 at 15:24
• I think you need to add a few bytes. You need to convert the answer from int to char. I think the easiest way is: f=@(n)['' 106-n-5*(n==48|n==53)]. (Fewer bytes than char(...).) – Stewie Griffin Oct 22 '14 at 11:27
• @RobertP. True, it will display numbers if you simply evaluate f on the command line, but it will work fine if used where a string is expected, e.g. fprintf('%s\n', f('3259232352')) – feersum Oct 22 '14 at 14:39

## GolfScript 9 (= 19 - 10)

{16|106\-.5%3=5*-}%

or

{16|~107+.5%3=5*-}%

Online demo

### Explanation

As observed by a few people, this calls for subtraction of the digit from 10 in most cases. Since the digits in ASCII start at 48, that means subtracting the ASCII code from 48*2+10 = 106. That leaves three special cases:

• 0 and 5: these map to 10 and 5 respectively, and need to map to 5 and 0. Solution: .5%3=5*- subtracts 5 if the result is equal to 3 modulo 5.
• -: this is the fun one. ASCII code 45, so equivalent to digit -3. After the reflection it's equivalent to digit 13, so I need to subtract 16. But I can equivalently do that by adding 16 before the reflection, and since 45 is the only relevant ASCII code not to have the bit corresponding to 16 set, I can accomplish that with a simple bitwise OR: 16|.

## tr, 107 (17 + 100 - 10)

tr 0-9 5987604321
• Perl port: y/0-9/5987604321/ and -p flag. Run with: perl -pe'y/0-9/5987604321/' <(echo 2983794-07) Score is 17 + 1 + 100 - 10 = 108. – hmatt1 Oct 22 '14 at 22:36

## JavaScript, ES6, 27 bytes (37 - 10)

f=_=>_.replace(/\d/g,y=>y%5?10-y:5-y)

Try it in latest Firefox like

f("2983794-07")
• Perl port: Run s/\d/$&%5?10-$&:5-$&/ge with p flag like this: perl -pe's/\d/$&%5?10-$&:5-$&/ge' <(echo "2983794-07") which would be 23 + 1 - 10 = 14 bytes. – hmatt1 Oct 21 '14 at 15:58

## CJam, 13 (23 - 10) bytes

'-_l\/{{si_5%A5?\-}%}%*

Try it online here

# C (63 - 10 = 53)

main(_){while(_=getchar())putchar(_>47?(_-=48)%5?58-_:53-_:_);}