Skip to main content
added 52 characters in body
Source Link
xnor
  • 146.6k
  • 3
  • 93
  • 131

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 3, 3, 3] -> [5, 3, 5, 3, 5, 3, 5, 2, 4, 2]
[4, 4, 4, 4, 4, 4, 4, 5, 5, 5] -> [3, 5, 3, 5, 3, 5, 3, 6, 4, 6]
[1, 1, 2, 4, 6, 7, 7] -> [2, 0, 2, 4, 6, 8, 6]

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 3, 3, 3] -> [5, 3, 5, 3, 5, 3, 5, 2, 4, 2]
[4, 4, 4, 4, 4, 4, 4, 5, 5, 5] -> [3, 5, 3, 5, 3, 5, 3, 6, 4, 6]

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 3, 3, 3] -> [5, 3, 5, 3, 5, 3, 5, 2, 4, 2]
[4, 4, 4, 4, 4, 4, 4, 5, 5, 5] -> [3, 5, 3, 5, 3, 5, 3, 6, 4, 6]
[1, 1, 2, 4, 6, 7, 7] -> [2, 0, 2, 4, 6, 8, 6]
edited body
Source Link
xnor
  • 146.6k
  • 3
  • 93
  • 131

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 43, 3, 3] -> [3, 5[5, 3, 5, 3, 5, 3, 5, 2, 4]4, 2]
[4, 4, 4, 4, 4, 4, 4, 45, 5, 5] -> [5, 3[3, 5, 3, 5, 3, 5, 3, 6, 4]4, 6]

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 4, 3, 3] -> [3, 5, 3, 5, 3, 5, 3, 5, 2, 4]
[4, 4, 4, 4, 4, 4, 4, 4, 5, 5] -> [5, 3, 5, 3, 5, 3, 5, 3, 6, 4]

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 3, 3, 3] -> [5, 3, 5, 3, 5, 3, 5, 2, 4, 2]
[4, 4, 4, 4, 4, 4, 4, 5, 5, 5] -> [3, 5, 3, 5, 3, 5, 3, 6, 4, 6]
added 275 characters in body
Source Link
xnor
  • 146.6k
  • 3
  • 93
  • 131

Give numbers space

SayGiven a list of integers, adjust each number by at most ±1 so that an integer bin the resulting list, each number is close to an integerat least 2 apart from each of its neighbors. That each, each entry an if it's most 1 away, i.e. one ofcan be replaced with an-1, an, or a+1n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. GivenThe output is a list of integers, replace each one with a value close to it so that no two consecutive numbers are close in the resultsame length as the input. There can be more than one way to do

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 4, 3, 3] -> [3, 5, 3, 5, 3, 5, 3, 5, 2, 4]
[4, 4, 4, 4, 4, 4, 4, 4, 5, 5] -> [5, 3, 5, 3, 5, 3, 5, 3, 6, 4]

TODO: Confirm it's always possible. Better test cases.

Give numbers space

Say that an integer b is close to an integer a if it's most 1 away, i.e. one of a-1, a, or a+1. Given a list of integers, replace each one with a value close to it so that no two consecutive numbers are close in the result. There can be more than one way to do this.

Examples:

[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]

TODO: Confirm it's always possible. Better test cases.

Give numbers space

Given a list of integers, adjust each number by at most ±1 so that in the resulting list, each number is at least 2 apart from each of its neighbors. That each, each entry n can be replaced with n-1, n, or n+1, and any two adjacent entries x and y must have abs(x-y) ≥ 2. The output is a list of the same length as the input.

You will not get an input where this is impossible, such as [5, 4, 4, 5]. The input will have at least two elements.

Examples (other outputs are possible):

[-5, -6] -> [-5, -7]
[1, 1, 1] -> [2, 0, 2]
[2, 2, 3, 3] -> [3, 1, 4, 2]
[0, 5, -1] -> [0, 5, -1]
[4, 4, 4, 4, 4, 4, 4, 4, 3, 3] -> [3, 5, 3, 5, 3, 5, 3, 5, 2, 4]
[4, 4, 4, 4, 4, 4, 4, 4, 5, 5] -> [5, 3, 5, 3, 5, 3, 5, 3, 6, 4]
Source Link
xnor
  • 146.6k
  • 3
  • 93
  • 131
Loading