Text Door Neighbors - Phone Keypad
Description:
Summary
Started in 2008 and recently resurging in popularity, a game known as Number Neighbour or Text Door Neighbor has people sending a text message to phone numbers near their own. Traditionally this was done for numbers ±1, so someone with the phone number 555-555-5555 has neighbors 555-555-5554 and 555-555-5556.
We're going to take this a step further and think about neighbors based on a classic phone keypad.
First, let's take a look at the classic phone keypad:
1 2 3
4 5 6
7 8 9
0
We can consider certain numbers adjacent if they appear directly next to or above/below each other. For example, 1
is adjacent to 2
and 4
(and nothing else), while 5
is adjacent to 2
, 4
, 6
, and 8
.
Let's look for phone numbers that are "neighbors" of a given phone number by having any one (and only one) of their digits be off-by-one as a number adjacent to the original.
By this definition, 555-555-5555 has both its original neighbors but also, e.g., 554-555-5555 and 555-555-5558.
Problem
Given a phone number of integer length N
(1 ≤ N
≤ 10) as a number string (e.g. 555-555-5555 would be passed as "5555555555"
), return an array of all phone numbers as number strings that would be considered neighbors of that phone number.
Examples
Given:
"1"
Return:
["2", "4"]
Given:
"8675309"
Return:
["5675309", "7675309", "9675309", "0675309", "8375309", "8575309", "8975309",
"8645309", "8685309", "8672309", "8674309", "8676309", "8678309", "8675209",
"8675609", "8675389", "8675306", "8675308"]
Notes
- Do not wrap around a side of the keypad when finding adjacent numbers. That is, do not consider
6
adjacent to4
nor0
adjacent to2
. - Do not consider numbers that are diagonal to each other adjacent
- Do not worry about invalid characters,
nil
, or anything other than a valid number string being passed in - Do not worry about the order of number strings in the array being returned
Similar Kata:
Stats:
Created | Aug 13, 2019 |
Published | Aug 13, 2019 |
Warriors Trained | 167 |
Total Skips | 22 |
Total Code Submissions | 247 |
Total Times Completed | 52 |
Ruby Completions | 52 |
Total Stars | 6 |
% of votes with a positive feedback rating | 89% of 27 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |