# Are all three integers distinct?

You will be given 3 integers as input. The inputs may or may not be different from each other. You have to output 1 if all three inputs are different from each other, and 0 if any input is repeated more than once.

This is , so make your code as short as possible!

• Welcome to PPCG. Nice first challenge. We are quite strict about objective winning criteria on this site. code-golf seems to be the obvious choice here, so I will add that to your post. Correct me if I'm wrong. – Adám Sep 3 '18 at 10:11
• Some test cases would be nice. – Adám Sep 3 '18 at 10:17
• Whoever is downvoting all answers should at least explain why... – Arnauld Sep 3 '18 at 10:41
• @Adám I think a more accurate title would be Are all three integers distinct? – Arnauld Sep 3 '18 at 10:45
• My dupe-vote is a hammer, but Possible duplicate of "Determine if all decimal digits are unique" Slightly different, but most answers can still be ported. – Kevin Cruijssen Sep 3 '18 at 11:02

# Triangularity, 17 bytes

..i..
.MiC.
}u)3=


Try it online!

### How it works

Excluding the mandatory triangular padding, we're left with:

iMiC}u)3=


Which can minimally be explained as: Push all STDIN as an array of strings (representing each line of input), count the occurrences of all of STDIN's elements in itself (which, in case all are distinct, should yield [1, 1, 1]), sum, then check whether the sum is equal to 3. There are 2 tricks here (which together save no less than 14 bytes):

• Using i and treating the inputs as strings rather than integers – which is quite uncommon, as )IE is frequently used instead, taking input as a list.
• Instead of checking whether they all are equal to 1 and then taking the product – or equivalently, taking the product and checking whether it is equal to 1 – this takes the sum and compares it with 3. Proving the validity of this method is obviously trivial: [1, 1, 1] is the only valid way to partition 3 into 3 positive integers summing to it and the contents of this list are always positive, as every element of a collection must occur at least once in it :P.

# Charcoal, 14 bytes

≔Ｅ³ＮθＩ¬⊖⌈Ｅθ№θι


Try it online! Link is to verbose version of code. 5 bytes could be saved by using a slightly non-standard input format [[x, y, z]]. Explanation:

≔Ｅ³Ｎθ


Input 3 numbers and make a list.

Ｉ¬⊖⌈Ｅθ№θι


Count the number of occurrences of each number in the list. Take the maximum, subtract 1, take the logical not, then cast to string for implicit print.

# PHP, 30 bytes

<?=array_unique($argv)==$argv;


takes input from command line arguments; prints 1 for truthy, empty string for falsy

# C (gcc), 50 41 bytes

-9 bytes thanks to GB !

m(int*a){a=*a==a[2]^*a==*++a^*a==*++a^1;}


Try it online!

No built-in sets in C, and iterating is too long, but at least i can shave off a few bytes by taking advantage of the fact that *a == a[0] ...

• 41 bytes – G B Sep 4 '18 at 8:46
• Thanks, I had thought about incrementing the pointer but couldn't figure out how to make it as short ! – etene Sep 4 '18 at 9:24

# Flobnar, 25 bytes

$-<*\\\!!@ ::*<&&& -$$>$


Try it online!

Given integers a,b,c, evaluates !!((c-b)*(b-a)*(c-a))

SWIFT 37 Bytes

Set(Array(readLine()!)).count==3 ?1:0

• Your current answer is a snippet; either put a wrapper around it or call your language Swift REPL. – Jonathan Frech Sep 7 '18 at 14:31

# Julia 1.0, 24 bytes

f(x...)=length(Set(x))>2


Try it online!

# Ruby, 11 bytes

->a{a==a|a}


Try it online!

Assuming we can return a boolean. Which everyone is doing nowadays.

# Pari/GP, 12 bytes

a->#Set(a)>2


Try it online!

# Stax, 3 bytes

ä▼Z


Run and debug it

Explanation

ux=         #Full program, unpacked, implicit input as array
u           #Keep only unique elements in array, maintaining first order of appearance
x=         #Copy original input onto stack, is it equal to unique-ified array.


Short and sweet. Wish Stax would implicitly check against "X" register if there was nothing to check against, but it works out regardless.

g a b c=and\$map(==)[a,b,c]

• I don't think this works, can you provide an example on how your function is used? – flawr Sep 22 '18 at 15:51

# Math++, 40 29 bytes

?>a
?>b
?>c
(a-b)&(b-c)&(a-c)

• I think the non-competing rule is a thing of the past. – Jonathan Frech Sep 21 '18 at 23:48
• Also, could you provide an implementation link for Math++? – Jonathan Frech Sep 21 '18 at 23:49
• @JonathanFrech OK, I just added a link to the esolang page; the article includes a link to the reference implementation. – SuperJedi224 Sep 22 '18 at 1:30

# Rust, 29 bytes

|a,b,c|(a!=b&&b!=c&&a!=c)as _


as _ means casting to a type determined by type inference. The function result needs to be assigned to a variable declared to store integers.

Try it online!

## JavaScript, 25 24 28 27 23 bytes

Using bitwise, comparison and logical operators Try it online!

(4 bytes saved courtesy of Jonathan Frech)

(a,b,c)=>a!=b&a!=c&b!=c

• You can pull the 1^ inside the parentheses, changing == to != and | to & and then remove said parentheses to save four bytes. – Jonathan Frech Sep 23 '18 at 7:26
• @JonathanFrech Updated – guest271314 Sep 23 '18 at 14:58

# Lua, 38 bytes

x,y,z=...print(x~=y and x~=z and y~=z)


### Try it online!

• Unfortunately, this doesn't work for the case when y==z (returns true, should be false). You'll need to add a third test to check for that possibility. – DLosc Sep 21 '18 at 21:16
• Opposed to equality, inequality is not transitive, so $x\neq y\neq z$ does not imply $x\neq z$. – Jonathan Frech Sep 21 '18 at 23:45
• Your answer in its current form is invalid. Please either fix or delete it. – Jonathan Frech Sep 23 '18 at 5:47
• Thank you guys, I really didn't noticed it. – Marcio Medeiros Sep 24 '18 at 16:15

# C (clang), 32 bytes

f(a,b,c){return a!=b&b!=a&a!=c;}


Try it online!

• The integers 0, 1, 2 are distinct, yet 0&... = 0. – Jonathan Frech Sep 22 '18 at 14:43

# Braingolf, 5 bytes

ul3-n


Try it online!

Edit: fixed from identical -> distinct

# Pepe, 85 77 bytes

rEeEREeErrEEEEEeRrEeErrEEEEEerEEEEEEERerEEEEEerRrEEEEEEeErREEREEEEErEeReeReEE


Try it online! Input is a,b,c. Change the "separated by" box to , to make it work!

# Pyth, 5 bytes

s<2l{


Try it online!

Looks like someone already did pyth but I didn't know about the I for testing invariants.

# MathGolf, 2 bytes

▀=


Try it online!

## Explanation

▀    Get unique elements
=   Check if equal to the input


# [Rust], 17 bytes

Anything XORd with itself yields zero. So. Any language with multiplication and XOR can do this:

(a^b)*(b^c)*(a^c)


Since input specifics were rather vague I chose a liberal interpretation. Or if you want to be more strict, we can define it as a closure (kind of like a lambda function),

24 bytes

|a,b,c|(a^b)*(b^c)*(a^c)


Try it on the Rust Playground

Python 2

def e(a,b,c):return 1 if len(set([a,b,c]))>2 else 0


...could be shortened to

def e(a,b,c):return len(set([a,b,c]))>2

• I'm afraid you misunderstood the task. Your code should check whether all 3 integers are distinct not identical. – manatwork Sep 19 '18 at 14:08
• what if a==b but a!=c? – Jo King Sep 19 '18 at 14:15
• I'm afraid that is not all. Now it says correctly that 1,1,1 is false (not all distinct) and 1,2,3 is true (all distinct), but for 1,2,2 gives also true, though they are not all distinct. – manatwork Sep 19 '18 at 14:17
• Fixed it with a set. Should be working correctly now. – Milbrae Sep 19 '18 at 14:24
• @Milbrae I think your ternary if is nigh a no-op. – Jonathan Frech Sep 19 '18 at 14:25