Recently I was trying out one of the more obscure use-cases of a modern smartphone: Calling someone by number. While typing it in, I noticed that some of my phonebook entries were displayed, even though the number I was trying to call was different! After some experiments, I figured out why.
What it does
Every entry in the phone book is examined like this:
- Split the entry by space into "words".
- Check every word like so:
- For every digit in the number...
- Is the character of the word at the current index on the key with the digit at the current number?
- If at least one such word exists, display this entry
Emulate my smartphone's behaviour!
Take the list of names below and a numeric string as input. The format for the phonebook may be chosen freely. Assume the phone number to always match
[0-9]* and all names to match
You can expect entries consisting of ASCII characters with values between 32 and 126 (including both). Your program should handle any length of entry and words within, as well as a list of any size.
Output a filtered list.
Input and output order is not relevant.
Use the following phone keyboard:
1 | 2 | 3 | abc | def ----------------- 4 | 5 | 6 ghi | jkl | mno ----------------- 7 | 8 | 9 pqr | tuv | wxy s | | z ----------------- | 0 | | |
- This is code-golf, shortest code wins
- No standard loopholes
Phone Book, values comma-seperated.
noodle9, Kevin Cruijssen, Arnauld, RGS, xnor, Bubbler, J42161217, Neil, petStorm, fireflame241, Dennis, Martin Ender, Leaky Nun, Lyxal, HighlyRadioactive, Dingus, math, Beefster, Razetime, my pronoun is monicareinstate, Dom Hastings, Dion
Input: 0815 Output:  Input: 731 Output:  Input: 532596 Output:  Input: 53259 Output: [Leaky Nun] Input: 542 Output: [J42161217] Input: 27 Output: [Kevin Cruijssen, Arnauld] Input: 36 Output: [Martin Ender, Dom Hastings] Input: 6 Output; [noodle9, Neil, Martin Ender, math, my pronoun is monicareinstate, Leaky Nun] Input: 3 Output; [Dennis, Martin Ender, fireflame241, Dingus, Dion, Dom Hastings] ```