Generate lists in which every sublist has a unique element The problem is defined as follows:
Create a function that takes an integer and returns a list of integers, with the following properties:

Given a positive integer input, n, it produces a list containing n integers ≥ 1.
Any sublist of the output must contain at least one unique element, which is different from all other elements from the same sublist. Sublist refers to a contiguous section of the original list; for example, [1,2,3] has sublists [1], [2], [3], [1,2], [2,3], and [1,2,3].
The list returned must be the lexicographically smallest list possible.

There is only one valid such list for every input. The first few are:
f(2) = [1,2]         2 numbers used
f(3) = [1,2,1]       2 numbers used
f(4) = [1,2,1,3]     3 numbers used
GolfScript (20 18 chars)

{,{.)^2base,}%}:f;


This is a simple binary ruler function, A001511.

Equivalently

{,{).~)&amp;2base,}%}:f;
{,{~.~)&amp;2base,}%}:f;
{,{).(~&amp;2base,}%}:f;
{,{{1&amp;}{2/}/,)}%}:f;


Thanks for primo for saving 2 chars.