I liked the "any number can differ by 1" approach more - it's a but more work :)
Rust:
pub fn number_neighbors(number: u32) -> Vec<u32> { let len = number.to_string().len() as u32; (0..len) .map(|delta| 10u32.pow(delta)) .flat_map(|delta| vec![number - delta, number + delta]) .collect() }
And a test (I usually omit them from my submissions, but I think they have a place here):
#[test] fn test_number_neighbors() { assert_eq!(vec![221, 223, 212, 232, 122, 322], number_neighbors(222)); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I liked the "any number can differ by 1" approach more - it's a but more work :)
Rust:
And a test (I usually omit them from my submissions, but I think they have a place here):