How to check if a condition is true for only one element in an array

I can do the following

julia> array = [1,3,4,7,9];

julia> All_numbers_are_positive = all(x->x>0,array)
true

julia> At_least_one_number_is_even = any(iseven,array)
true

But how do I do Only_one_number_is_even ?

count(iseven, array) == 1

6 Likes

How do I do

All_numbers_are_not_the_same

is this homework related?

best performance:

any(!=(ary[1]), ary)

easy to write:

length(unique(ary)) > 1

also this can be improved to:

All_numbers_are_positive = all(>(0),array)
5 Likes

No this is not a homework question

I need it for Monoalphabet Homophon Cryptography decoding program

I need it to look for symbols that appears only once.