Challenge: print only non-repeating integers from an array without embedded loops

Out of curiosity i want to see if there is a more efficient way to print out only non-repeating integers from an array.

Show me what you got, senpai.

Other urls found in this thread:

docs.python.org/3/library/collections.html#collections.Counter
twitter.com/AnonBabble

>non-repeating
you mean those that are in array only once
>[1, 1, 2, 3, 1] => [2, 3]
or just don't repeat on output?
>[1, 1, 2, 3, 1] => [1, 2, 3]

the former, only print those that occur only once

var ary = [1, 1, 2, 3, 1];
var result = {};
ary.forEach(function(x) {
result[x] = true;
})
console.log(Object.keys(result).map(function(x) { return Number(x)}))

def nonrep(arr):
counts = dict()
for i in arr:
counts[i] = counts.get(i, 0) + 1
for i in arr:
if counts[i] == 1:
print(i)

>without embedded loops
is this the state of programmers in 2018?

((1=+/)∘(∘.=⍨)/⊙⊢)
also
((1=+⌿)∘(∘.=∘∪⍨)/⊙∪)
also
∼∘(∼⍦∘∪⍨)⍨

yeah, just one loop

Nice APL code

what eldritch language is this?
wtf does any of this mean?

>a dictionary
isn't there a better way?

dictionary is O(1) lookup and insert, I see no problem with that

>posts ancient runes of a madman as a solution

I was certain it was the right language for this but I lack a math PhD to use it.

>what eldritch language is this?
APL (NARS2000).
>wtf does any of this mean?
The first two are monadic train (point-free style) verbs.
The first computes the matrix for the relationship = (with 1 for "true" and 0 for "false") between the input vector (∘.=, "outer-equals") and itself (⍨, "reflexively"), then sums the rows of the matrix (+/, "add-across") and checks, in parallel for each element, whether or not it equals 1. After that, the resulting binary vector selects (/, "copy-down") which elements of the original vector (⊢, "left") are to be returned.
The second is similar, but acts on the representation of the input as a set (∪, "nub").
The third is quite different: it computes the multiset (or bag) difference (∼⍦, "multi-less") between the input vector and its own (⍨) representation as a set (∪), then it computes the set difference (∼, "less") between the original vector and the previous result (⍨).
Note that these descriptions are semantic, and they do not necessarily represent what the interpreter will actually do. A clever compiler could optimize, lazy-evaluate and change representations as it pleases, so long as the result is the same.

Is this what it's like to be a real computer scientist?

That's what it's like being in Cthulhu's cult.

Not doing your homework for you, OP.

>counts = dict()
for i in arr:
counts[i] = counts.get(i, 0) + 1
Cmon folks, it's Python after all, use the batteries included:
from collections include Counter
counts = Counter(arr)

(xs groupBy(identity) filter {_._2.size==1}) .keys foreach println

>⍨
mfw I read APLel code
>⍦
TMNT

the python standard lib doesn't cease to surprise!

Yup. You can also add, subtract, intersect, union etc multiple Counters. Makes certain tasks trivial. Shame that more languages don't have this one.
docs.python.org/3/library/collections.html#collections.Counter

for val in set(array):
if np.count_nonzero(array == val):
print(val)

arr = sort(arr);
int temp = arr[0];
int[] unique = new int[arr.length];
for(int i = 1; i < arr.length; i++) {
if (arr[i] != temp) { unique.push(temp) }
temp = arr[i]
}
There's no reason not to sort ahead of time because otherwise you're going to be doing repeated lookups across both arrays which is going to give you a larger N coefficient versus some clever algorithm.
>B-B-BUT IT'S STILL O(N)!!!!!
Go take advance algorithms before telling me big O is the only thing that matters.

Shit.

Second line should have == 1

I'm a retard

>new int[
Hello pajeet.

>tfw you are a brainlet and cannot understand ancient magic runes

I should have gone to university as mom wanted ;_;

print(set([1,1,2]))