The range of vision of a digit is equal to its own value. 1 can see one digit to the left and one digit to the right, 2 can see two digits, and so on.
Thus, the loneliness of a digit is the sum of the digits which it can see.
Given a non-negative integer, your function must determine the loneliest number in the string.
Example
number = 34315
digit can see on the left can see on the right loneliness
3 - 4, 3, 1 4 + 3 + 1 = 8
4 3 3, 1, 5 3 + 3 + 1 + 5 = 12
3 3, 4 1, 5 3 + 4 + 1 + 5 = 13
1 3 5 3 + 5 = 8
5 3431 - 3 + 4 + 3 + 1 = 11
1 is the loneliest number, since it has the least friends and the lowest score.
Tests
lonelyNum(23456)
lonelyNum(42435)
Good luck!
This challenge comes from albertogcmr on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!