Distinct Sieves
MATL, 7 6 4 bytes
1 byte saved thanks to @Luis
2 bytes saved thanks to @Dennis
&=Rs
We define 1
to be truthy and all other values as falsey
Try it Online
All test cases
Explanation
% Implicitly grab input array
&= % 2D array of equality comparisons
R % Get the upper triangular portion
s % Sum down the columns
% Implicitly display the result
Jelly, 4 bytes
ĠṪ€Ṭ
Favors last occurrences. Try it online! or verify all test cases.
How it works
ĠṪ€Ṭ Main link. Argument: A (array)
Ġ Group; paritition the indices of A according to their corresponding values.
Ṫ€ Tail each; select the last index of each group.
Ṭ Untruth; generate a Boolean array with 1's at the specified indices.
Python 3, 47 35 39 36 bytes
lambda n:[n.pop(0)in n for x in n*1]
Pops the first item from the list, checks if it exists elsewhere in the list, and inserts True
or False
into a new list.
For this function, False
indicates a distinct value, and True
is otherwise (True=0
and False=1
)
Thanks to Dennis for a ton of bytes
Original, 47 bytes:
lambda n:[(1,0)[n.pop()in n]for x in[1]*len(n)]
Try it