Skip to main content
Tweeted twitter.com/StackCodeGolf/status/995794166818004992
clarified from comments
Source Link
Erik the Outgolfer
  • 40.6k
  • 5
  • 45
  • 122

Challenge

Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers (integers with absolute difference 1) are next to each other.

Examples

  • 4[1, 3, 0, 2]
  • 5[0, 2, 4, 1, 3]
  • 6[0, 2, 4, 1, 3, 5]
  • 7[0, 2, 4, 1, 5, 3, 6]

You may use 1-indexing instead (using integers [1, n] instead of [0, n-1]).

Your code must run in polynomial time in n, so you can't try all permutations and test each one.

Challenge

Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other.

Examples

  • 4[1, 3, 0, 2]
  • 5[0, 2, 4, 1, 3]
  • 6[0, 2, 4, 1, 3, 5]
  • 7[0, 2, 4, 1, 5, 3, 6]

You may use 1-indexing instead (using integers [1, n] instead of [0, n-1]).

Your code must run in polynomial time in n, so you can't try all permutations and test each one.

Challenge

Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers (integers with absolute difference 1) are next to each other.

Examples

  • 4[1, 3, 0, 2]
  • 5[0, 2, 4, 1, 3]
  • 6[0, 2, 4, 1, 3, 5]
  • 7[0, 2, 4, 1, 5, 3, 6]

You may use 1-indexing instead (using integers [1, n] instead of [0, n-1]).

Your code must run in polynomial time in n, so you can't try all permutations and test each one.

edited title
Link
user202729
  • 17.4k
  • 2
  • 37
  • 70

Give a permutatationpermutation with no two consecutive integers next to each other

deleted 119 characters in body
Source Link
Esolanging Fruit
  • 15.5k
  • 4
  • 49
  • 92

Challenge

Given an integer nn ≥ 4, output a permutation of the integers 0 to n - 1[0, n-1] with the property that no two consecutive integers are next to each other. You can assume n >= 4.

Examples

  • For n = 4.4 (1, 3, 0, 2)[1, 3, 0, 2]
  • For n = 5.5 (0, 2, 4, 1, 3)[0, 2, 4, 1, 3]
  • For n = 6.6 (0, 2, 4, 1, 3, 5)[0, 2, 4, 1, 3, 5]
  • For n = 7.7 (0, 2, 4, 1, 5, 3, 6)[0, 2, 4, 1, 5, 3, 6]

You may use 1-indexing instead (using integers 1 to n,[1, n] instead of 0 to n-1[0, n-1]).

Your code must run in polynomial time in n. For this who don't speak computational complexityn, so you can take this rule to mean that your code can't try all permutations and test each one.

Challenge

Given an integer n, output a permutation of the integers 0 to n - 1 with the property that no two consecutive integers are next to each other. You can assume n >= 4.

Examples

  • For n = 4. (1, 3, 0, 2)
  • For n = 5. (0, 2, 4, 1, 3)
  • For n = 6. (0, 2, 4, 1, 3, 5)
  • For n = 7. (0, 2, 4, 1, 5, 3, 6)

You may use 1-indexing instead (using integers 1 to n, instead of 0 to n-1).

Your code must run in polynomial time in n. For this who don't speak computational complexity, you can take this rule to mean that your code can't try all permutations and test each one.

Challenge

Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other.

Examples

  • 4 [1, 3, 0, 2]
  • 5 [0, 2, 4, 1, 3]
  • 6 [0, 2, 4, 1, 3, 5]
  • 7 [0, 2, 4, 1, 5, 3, 6]

You may use 1-indexing instead (using integers [1, n] instead of [0, n-1]).

Your code must run in polynomial time in n, so you can't try all permutations and test each one.

added 80 characters in body
Source Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Loading
added 73 characters in body
Source Link
user9207
user9207
Loading
Source Link
user9207
user9207
Loading