# 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.
Sep 3, 2018 at 10:11
• Some test cases would be nice.
Sep 3, 2018 at 10:17
• Whoever is downvoting all answers should at least explain why... Sep 3, 2018 at 10:41
• 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. Sep 3, 2018 at 11:02
• its not a duplicate, the small amount of input yields to different solutions. id wager if you asked this to electrical engineers youd get a whole different approach to the answer (primarily due to the small number of inputs).. i realize the golfing languages all have de-dup but there is still something to be said for the 'normal' languages and what people's backgrounds are. Jan 1, 2019 at 0:32

# Jelly, 5 6 bytes

ɠḲQL=3


Try it online!

From 5 to 6 bytes because this is my first time and I messed up (whoops) fixed it now

ɠḲQL=3
^^^^^
||||Is it equal to three?
|||How many unique numbers do we have? (length of unique numbers array)
||Sort By Unique
|Split by Spaces

• Hello and welcome to PPCG. Does your code also work for 3 integers, or is it only functional for three digits? Sep 7, 2018 at 16:58
• @Jonathan Frech Sadly, it only works for three 1 Digit numbers, it does this by sorting the input by unique characters, then testing if the amount of unique characters is the same length as the input. Maybe there is a way to get it to work with any 3 integers, but I think this is a good attempt for me at least! Sep 20, 2018 at 16:00
• The challenge specifies You will be given 3 integers as input. which seems to render your answer invalid. Sep 20, 2018 at 16:43
• @JonathanFrech Fixed it now! Was my first time doing this sort of thing so, I'm not the greatest at it. Sep 23, 2018 at 21:25

# PHP, 38 bytes

echo(4==count(array_unique($argv)))*1;  Called with e.g. php codegolf.php 2 3 4.$argv always contains the filename of the script, hence 3 unique numbers make 4 elements.

# Vyxal, 1 byte

≠


Try it Online!

Easy peasy

# Julia 1.0, 18 11 bytes

~x=x==x∪x


Try it online!

-7 bytes (!!) thanks to MarcMush: replace length(x∪x)>2 with x==x∪x

• I think x∪x==x works Feb 24 at 12:42

# 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, 2018 at 8:46
• Thanks, I had thought about incrementing the pointer but couldn't figure out how to make it as short ! Sep 4, 2018 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. Sep 7, 2018 at 14:31

# Julia 1.0, 24 bytes

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


Try it online!

# 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? Sep 22, 2018 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. Sep 21, 2018 at 23:48 • Also, could you provide an implementation link for Math++? Sep 21, 2018 at 23:49 • @JonathanFrech OK, I just added a link to the esolang page; the article includes a link to the reference implementation. Sep 22, 2018 at 1:30 ## 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. Sep 23, 2018 at 7:26 • @JonathanFrech Updated Sep 23, 2018 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. Sep 21, 2018 at 21:16 • Opposed to equality, inequality is not transitive, so $x\neq y\neq z$ does not imply $x\neq z$. Sep 21, 2018 at 23:45 • Your answer in its current form is invalid. Please either fix or delete it. Sep 23, 2018 at 5:47 • Thank you guys, I really didn't noticed it. Sep 24, 2018 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. Sep 22, 2018 at 14:43 • f(a,b,c){return a-b&&b-a&&a-c;} – l4m2 Mar 22, 2021 at 11:36 • b-a=>b-c mistake from your code – l4m2 Mar 22, 2021 at 11:37 # 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  # Husk, 3 bytes S=U  Try it online! Takes the three numbers in a list. # 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 # Rust, 29 23 bytes |a,b,c|a!=b&&b!=c&&a!=c  Try it online! # Dash, 27 24 bytes $(($1-$2&&$2-$3&&$3-$1))


Try it online!

Sorry for a boring answer; at first if bashism would work, but I could not get out of POSIXism.

The code above evaluates to a string of either 0 or 1.

# Pxem, Filename: 28 bytes + Content: 0 bytes = 28 bytes.

• Filename: ._._._.e.z.c.c.z1.o.d.a.a0.o
• Content: enpty.

Try it online! (with pxem.posixism)

XX.z
# for three times; do push( read integer); done
.a._._._XX.z
# call subroutine
## NOTE. When DOT-e is performed when stack is a,b,c,bottom,
## then subroutine begins with same content of stack
## And when subroutine ends when stack is d,e,f,bottom,
## then previous stack would be d,e,f,a,b,c,bottom
## to continue origimal procedure
## In this program content is empty, so is subroutine
## thus x,y,z,bottom to x,y,z,x,y,z,bottom,
## which duplicates entire stack
.a.eXX.z
# while size < 2 && pop != pop; do
.a.zXX.z
# dup; dup; while size<2 && pop!=pop; do
## this is equal to while stack is empty; do
.a.c.c.zXX.z
# push '1'; putc pop; exit
.a1.o.dXX.z
# done
.a.aXX.z
# done
.a.aXX.z
# push '0'; putc pop; (implicity) exit
.a0.oXX.z
.a


# Factor, 11 bytes

all-unique?


Try it online!

# K (ngn/k), 10 bytes

{(#x)=#?x}


Try it online!

A little bit more interesting answer in my opinion, but still boring. Takes a list of integers as input.

Explanations:

{(#x)=#?x}  Main function. x is input
?    Unique (Remove all duplicated elements)
#     Length
=      Is it equal to
(#x)       The length of x itself


## Pascal, 91 B

This is a complete program conforming to ISO standard 10206 “Extended Pascal” and at 91 bytes certainly more readable than brain****.

program p(input,output);var x,y,z:integer;begin read(x,y,z);write(ord(card([x,y,z])=3))end.


The [x,y,z] denotes a set, thus duplicate values get collapsed. This means, the set literal [4, 4, 4] is identical to [4]. The card function returns the number of distinct elements in the set. Here this will be anything between 1 and 3 inclusive. We test for equality to 3 (… = 3) which evaluates to a Boolean expression (denoted by the built-in constants false and true) and convert this enumeration value into an integer using ord.