Better a good phone neighbour than a distant friend. With that idea in mind, the editorial officers of the digital experiment Sambal1 attempted to spark some new friendships around Flanders in December 2014. To test the new concept, each Sambal team member sent the following text message to his or her phone neighbours, hoping for a quick response.

phone neighbours
Original text message sent from each Sambal team member to his or her phone neighbours, hoping for a quick response.

But what exactly are your phone neighbours? Well, simple enough, they are the people who have almost the same phone number as yourself, but then one number higher or lower. For example, if your phone number is 0472/91.39.17, then your downstairs neighbour has phone number 0472/91.39.16 and your upstairs neighbour has phone number 0472/91.39.18.

Getting to know your phone neighbours is a two-step process. At first, off course, you send them a text message. If you receive an answer, you take a screenshot of the conversation that follows. The best and funniest screenshots are collected on a temporary Facebook page2.

Assignment

In this assignment, we represent a phone number as a string that contains both digits and other characters. Each phone number contains at least one digit. The other characters are used to format the phone number in some way or another. As an example, the phone number 0472/91.39.17 is formatted using one extra slash and three extra dots. The goal of this assignment is to determine the phone neighbours of a given phone number, and express them in the same format as the original phone number. This is done in the following way:

Example

>>> digits('0472/91.39.17')
'0472913917'
>>> digits('++32 (0)9 264 4779')
'32092644779'

>>> replace('0472/91.39.17', 1234567890)
'1234/56.78.90'
>>> replace('++32 (0)9 264 4779', 123456789)
'++00 (1)2 345 6789'

>>> upstairsNeighbour('0472/91.39.17')
'0472/91.39.18'
>>> upstairsNeighbour('++32 (0)9 264 4779')
'++32 (0)9 264 4780'

>>> downstairsNeighbour('0472/91.39.17')
'0472/91.39.16'
>>> downstairsNeighbour('++32 (0)9 264 4779')
'++32 (0)9 264 4778'