# 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-_:_);}
{"ft_lang_label":"__label__en","ft_lang_prob":0.90235233,"math_prob":0.8773057,"size":951,"snap":"2021-04-2021-17","text_gpt3_token_len":261,"char_repetition_ratio":0.14783527,"word_repetition_ratio":0.0,"special_character_ratio":0.38275498,"punctuation_ratio":0.11173184,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9551588,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-19T15:26:31Z\",\"WARC-Record-ID\":\"<urn:uuid:1025e34f-088c-43b3-8328-ac67c9ff93f0>\",\"Content-Length\":\"206363\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:634f45db-becf-4739-8584-17d111f729ef>\",\"WARC-Concurrent-To\":\"<urn:uuid:cefd28d0-6e38-478e-b1ac-657882df8bb4>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://codegolf.stackexchange.com/questions/40094/catch-some-drug-dealers/40128\",\"WARC-Payload-Digest\":\"sha1:6YYGSADW7JKDMB2CQ5WZBYAVKVPFWAE5\",\"WARC-Block-Digest\":\"sha1:AZRO7XV7HYLNYDKS4SGSHXNWFAPDKIIN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703519395.23_warc_CC-MAIN-20210119135001-20210119165001-00702.warc.gz\"}"}