In this challenge you will be tasked with implementing a sequence of natural numbers such that:
- Each number appears a natural number of times
- No two numbers appear the same number of times
- No two numbers appear in the sequence next to each other more than once.
For some examples, the sequence
1,2,3,1,4,5,1,6,7,1,8,9,1,10,11,1,...
Is not valid because 1
appears an infinite number of times.
The sequence:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,...
Is also not valid because every number appears exactly once, but different numbers must appear a distinct number of times.
The sequence:
1,1,2,2,3,2,4,3,5,3,6,3,7,4,8,4,9,4,10,4,11,5,...
meets the first two criteria but 2
occurs next to 3
two different times (2,3,2
).
One sequence that meets all the criteria is:
1,1,2,2,3,4,2,5,6,3,7,8,3,9,10,3,11,12,4,13,14,4,15,16,4,17,18,4,19,20,5,21,22,5,23,24,5,25,26,5,...
You may use any option available in the default sequence rules. You should assume natural numbers include 0. You may assume they don't, but it won't do you any help.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
1,2,2,3,3,3,4,4,4,4,5,5,5,5,5...
valid? every number n just appearing in order n times? \$\endgroup\$