19
3
You know how you get a voicemail message and the person's connection wasn't great, and you're trying to figure out how to call them back, but you're not sure if that was a "5" or an "8" they said?
That's this challenge.
The good news is that the caller read off their number twice, but it's garbled in both places.
Your program should take input like this:
5551231234 / 5551231234
Where the first ten digits are the first time the phone number is said in the voice mail and the second set are the second time it's said. Only...it'll look more like this:
555?ABC1_36? / 55?522_1?234
- A digit followed by a question mark means that that's the best-guess for that digit (e.g. "5?" means "probably a 5, compare with repeat").
- An underscore indicates a known missing digit, something too fuzzed by static to be deciphered at all.
- Letters are just that: letters. Treat them as their respective digits
- ABC -> 2, DEF -> 3, GHI -> 4, JKL -> 5, MNO -> 6, PQRS -> 7, TUV -> 8, WXYZ ->9
- All sample inputs use uppercase (you can safely omit a ToUpper() call)
- If your language works better in lower case, you can freely use lowercase for the input and omit a ToLower() call. Just note that in your answer.
You can additionally assume the following judgement calls:
5? / _ -> 5 //5 is the best guess we have, use it
5? / 5? -> 5 //uncertain, but matching
5? / 4? -> ? //conflict
5 / 4 -> ? //conflict
5? / 4 -> 4 //solid information overrides possible value
5 / 4? -> 5 //solid information overrides possible value
_ / _ -> ? //no information available
Additionally you can assume that all inputs will contain ten-digit phone numbers, not including the question marks. Inputs that aren't ten digits (e.g. 1234567 / 1234567
) can either be treated as unsolvable (falsey output) or throw an error.
Input
One line of characters 0-9A-Z _?/
, as described above.
Output
If it can be parsed to a single valid ten-digit phone number, output the phone number. Otherwise output some form of error indication (e.g. -1, false, or an empty line).
Shortest wins, as per usual.
Sample inputs:
1234567890 / 1234567890
1234567890? / 1234567890
123456789_ / 1234567890
1234567890? / 123456789_
1234567890 / 1234567890?
1234567890 / 123456789_
123456789_ / 1234567890?
1234567890? / 1234567890?
1234567890? / 1234567891?
123456789_ / 123456789_
555CALLUS1 / 5552255871
404_12?6039 / 4041?1560_9
_GETREVENGE / 16?36?_2838_
1?691460_50 / 16_14609?50
61?08977211 / 612?897725?1
40?0INSTA__ / 8?00_NSTI?LL
3985_534?10 / 39?8?5053_10
7__7294?737 / 7797299?_37
28?897_384?1 / _8?89763861
271168090_ / 27116800?09
6802?148343 / 67?01148343
94_11628?2?6? / 9491162_47?
17?4285_689 / 1__26?52689
6_311?95_38 / 6731194?7?38
380?7DRAGON / 3807378?5?66
4?647_93236 / 5646?6?9__36
365?268898_ / 366267?7?984
GRATEDBATE / IRATEDBATE
5307_079?93 / ____8_____
535_3_0255 / 52?5_3_024?5
55_____088 / 54?2397207?7?
6_48398_95 / _946?398?6_5?
_0_312_3_1 / 81?53123?1?71
____1_____ / 64?255?508?61
8427820607 / 6?424?8?__6?07
50_3707__6 / 52?8375?74?56
615___8255 / 62?526?983?2?1?
__652618__ / 8365261__0
149___933_ / 1_9677?92?31
___7?281562 / 3438?28154?2
5?7?7?___8?3?7?4 / 57_855837_
605_272481 / 605427__81
86?569__731 / 88560?0?7721
1__91654?15 / 17?9?9165715
800NWABODE / 80069ABI?DE
8___9017_0 / 8_2494?12?9_
_024?5?91?470 / 304?17908?7_
42510704_2 / 4_51070492
9338737_89 / 93_873PLUS
327762_401 / 327_MASH01
33093_2058 / 3309_12058
4061_33578 / 40619_3578
559_383197 / 559938_197
94_9746084 / 9459746_84
1_37655238 / 163POLKA_T
_672FRIZZY / 767237499_
8_76318872 / TIP63188_2
51_8404321 / 5178404_21
358_030314 / 358603_314
2597_85802 / 25979_5802
77141_1408 / 7714_91408
330858_457 / 330_586457
4686079_39 / 46_6079239
86457508_6 / 8_45750826
523226626_ / _23BANNANA
_ISSY_ISSY / 44__9548?79?
6?00B_YJILT / 800289KILL?
2?52803___0 / 1526?0390?61?
FI?ND___T?HE / EAS?T?EREGGS?
0_231?95_38 / 0723194?7?38
0?647_39236 / 0646?6?3__36
025?267798_ / 06?6265?9?984
0061_33578 / _0619_3578
I've only insured that every possible edge-case is covered (the first 11 entries), but other than that, it's pretty much random.
Update
Four entries at the bottom added with leading zeros (at Jonathan Allan's suggestion).
Correct output for the sample inputs:
Based on the output from Jonathan Allan's entry (the formatted output was ideal).
Do we have to take the inputs as a single string, seperated by
" / "
, or can we just take them as two standard inputs? – L3viathan – 2017-04-22T17:10:46.647@L3viathan I had originally conceived the idea as having to take a single string. – Draco18s no longer trusts SE – 2017-04-22T17:24:08.727
7@Draco18s single string doesn't bring anything to the challenge – fəˈnɛtɪk – 2017-04-22T17:28:13.500
1@fəˈnɛtɪk No one said anything in the sandbox, but I have nothing against using input pairs. It was just the way I originally conceived it. – Draco18s no longer trusts SE – 2017-04-22T17:57:09.740
Would it be fine in case of failure to output a part of the output and a 0 in the next line? – dzaima – 2017-04-22T19:14:30.180
@dzaima I would say no. – Draco18s no longer trusts SE – 2017-04-22T19:34:40.027
Can we take the input without the spaces before and after the
/
? – math junkie – 2017-04-22T21:48:13.060@mathjunkie Not unless you take two separate input strings. – Draco18s no longer trusts SE – 2017-04-22T22:35:37.710
1Who leaves a voicemail using letters for their phone number?! – Jonathan Allan – 2017-04-22T23:25:26.447
@JonathanAllan 0-800-SRVCSPMRS, that's who. – John Dvorak – 2017-04-23T09:32:41.323
Can we output a string with uncertain digits marked with a
?
, such as543?56?890
? – Arnauld – 2017-04-23T10:22:46.103@Arnauld No, the point is to identify those digits. If you are unable to, then the phone number cannot be uniquely identified and the program should output some sort of error or falsey value. – Draco18s no longer trusts SE – 2017-04-23T14:38:32.547