# 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

# Python 3, 2321 20 bytes

lambda*a:len({*a})>2


Try it online!

• OP asked for 1 vs. 0, so maybe you need one more byte: lambda*a:len({*a})//3
– tsh
Sep 4, 2018 at 2:53
• @tsh in Python 1 == True, I think there's a meta post about it somewhere Sep 4, 2018 at 4:14
• @tsh - relevant meta "if it quacks like a number, it's a number" - in Python: False * True is 0; False + True is 1; etc... Sep 4, 2018 at 7:09
• From the relevant meta: "this does not apply to challenges where an exact string output is required", so I'm not sure what really applies here.
– G B
Sep 6, 2018 at 6:39

# Perl 6, 7 bytes

*.Set>2


Try it online!

# R, 13 bytes

A different solution to @Kirill by using mad() for an unintended purpose!

mad(scan())>0


Try it online!

• Well input is not specified at all, so IMO accepting 3 values as input means we can accept a vector Sep 4, 2018 at 10:14
• R almost competing with golf languages ! :D Sep 5, 2018 at 15:59
• I believe Gauss invented mad exactly for this purpose.
– ngm
Sep 7, 2018 at 14:21

# R, 2422 20 bytes

all(table(scan())<2)


Try it online!

Returns a boolean, but as folks have already discussed on the Python answer, this should be OK.

Thanks to digEmAll for saving 2 bytes.

• Sep 4, 2018 at 13:28
• 11 bytes - if you are allowed to have any number > 0 as truthey. Otherwise, append >0 for TRUE/FALSE output in 13 bytes. Sep 5, 2018 at 8:22
• Wow, didn't even know about this function. I'd suggest you post it separately (edit and revive your deleted answer), but I think you have to stick with 13 bytes - while T/F indeed acts like 1/0, 1.48 doesn't. Sep 5, 2018 at 8:52

# JavaScript, 22 bytes

If we can output boolean values then the last 2 bytes can be removed.

a=>new Set(a).size>2&1


Try it online

For the same byte count, this works on arrays of any size but assumes the input will never contain a 0 and output is a boolean.

a=>!a[new Set(a).size]


Try it online

• Assuming that we can take the input as an array and return a Boolean: a=>new Set(a).size>2 Sep 3, 2018 at 10:42
• @Arnauld, yeah I had that too but as it stands the spec won't allow it - will be updating if the spec changes, though. Sep 3, 2018 at 10:46
• Oh, wait. I can just tack on &1 for 22 bytes. Sep 3, 2018 at 10:48

# Ruby, 16 bytes

->a{1-(a<=>a|a)}


Try it online!

• -3 bytes with uniq! Sep 7, 2018 at 21:11
• Boolean and Integer are different types in Ruby.
– G B
Sep 10, 2018 at 10:11
• Ah, you're right. I didn't read the challenge closely enough, and assumed a truthy/falsey output would suffice. Sep 10, 2018 at 16:16

# Cubix, 55 25 bytes

-29 thanks to Jo King

O@O1u|@O@II-!/;I-!/;u^?-p


Try it online!

It should be possible to golf off quite a few bytes.

• 26 bytes
– Jo King
Sep 4, 2018 at 12:23
• Thanks a lot. I managed to shave off 1 more byte to arrive at 25 bytes in total
– Luke
Sep 4, 2018 at 14:52
• I think you might be missing a @ in place of the . in the 9th spot. Makes it do some funky things for 1 2 2. Sep 4, 2018 at 19:02

# 05AB1E, 2 bytes

ÙQ


Explanation:

Ù     # Uniquify the (implicit) input
Q    # Check if it's still equal to the (implicit) input

• Using standard truthy/falsy rules for decision-problem, keeping in mind that 1 is the only truthy value in 05AB1E, ¢P works as well as an alternative 2-byter. Sep 3, 2018 at 11:13
• @Mr.Xcoder I'm not sure that's actually currently valid - the question asks for outputs 1 and 0 - 4, for example, is neither 1 nor 0, nor does not act like 1 or 0 (like True and False do in Python). The question should probably ask for Truthy/Falsey but at present it does not. Sep 4, 2018 at 7:24

# Mathematica, 13 bytes

Boole[E!=##]&


Pure function. Takes three integers as input and returns 0 or 1 as output. I know that this is rather similar to David G. Stork's answer, but it exploits SlotSequence to shave off a byte (as compared to Boole@*Unequal).

# Japt -N, 3 bytes

eUâ


Try it

## Explanation

Uâ deduplicates the input and e tests if it's equal to the original.

# J, 4 bytes

-:~.


Try it online!

## Explanation:

Is the argument equal -: to itself after removing the duplicates ~.

# C (gcc), 25 26 bytes

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


Try it online!

• Fails on [4,2,3]
– G B
Sep 5, 2018 at 8:17
• @GB Quite right! Sep 5, 2018 at 13:53

# K (oK), 4 bytes

3=#?


Try it online!

Does the count of the distinct elements equal 3?

# brainfuck, 91 bytes

,>,>,[-<-<->>]>>+++++++[>+++++++<-]+<<<<[>]>>[<<<[-<->]<[>]>>->[>.<<<->>-]<+]<+[>>>[>]<-.>]


Try it online!

### How it works

,>,>,                   'read input as A, B, and C
[-<-<->>]>>+            'compute A-C, B-C
++++++[>+++++++<-]+     'prepare output
<<<<[>]>>               'if A-C != 0 && B-C != 0
[
<<<[-<->]           'compute A-B
<[>]>>->            'if A-B != 0
[>.<<<->>-]         'print 1
<+
]
<+
[                       'else (this else is for both of the if statements, even though they are nested... wierd, I know)
>>>[>]
<-.>                'print 0
]


# Powershell, 27 25 bytes

+!(($args|group).Count-3)  Test script: $f = {
+!(($args|group).Count-3) } &$f 1 2 3
&$f 3 2 1 &$f 2 1 3
&$f 2 2 3 &$f 2 1 1
&$f 2 1 2  Explanation: $args|group           # Group arguments
(           ).Count    # Count of groups
(                   -3) # is 0 if inputed integers are unique
!                        # operator not converts int to boolean: true if integers are unique
+                         # converts boolean to int: 1 if integers are unique, otherwise 0

• 26 bytes -- +(($args|group).count-eq3) Sep 10, 2018 at 17:50 • great! and thanks Sep 10, 2018 at 17:53 # Jelly, 2 bytes QƑ  Try it online! # Common Lisp, 25 2 bytes /=  Try it online! -23 bytes thanks to @ceilingcat! # APL (Dyalog Unicode), 3 bytesSBCS Anonymous tacit prefix function. Takes list as argument. ∪≡⊢  Try it online! ∪ does the set of unique elements from the argument ≡ match ⊢ the unmodified argument? # Clean, 32 bytes import Data.List$l|hasDup l=0=1


Try it online!

# Attache, 10 bytes

==#Unique


Try it online!

This is a fork of the operator == and Unique, equivalent to:

{ _ == Unique[_] }


## Alternatives

{#_=#Unique[_]} (15 bytes)

Any##Same=>Pairs@Sort (21 bytes)

Any@{=&>_[[0'1,1'2,2'0]]} (26 bytes)

&${not(x=y or y=z or x=z)} (26 bytes) &${x/=y and y/=z and x/=z} (26 bytes)

{Any!Same=>Chop&2!_[0'1'1'2'2'0]} (33 bytes)

# Java 9, 43 27 bytes

thanks to @Olivier Grégoire

(a,b,c)->a!=b&b!=c&a!=c?1:0


Previous attempt:

(a)->a[0]==a[1]||a[0]==a[2]||a[1]==a[2]?0:1

• Why not count it as 43 bytes Sep 4, 2018 at 2:06
• 27 bytes: (a,b,c)->a!=b&b!=c&a!=c?1:0. Sep 4, 2018 at 9:03
• Also, the first code (100 bytes) doesn't compile and uses == which is not applicable on String without issues which you encounter here (after compilation fix), and in the second code, Set.of method will throw IllegalArgumentException if any duplicate is provided. I'm tempted to -1 for not testing at all. Sep 4, 2018 at 9:11
• @olivier Apologies-it was late and I mixed up a few different ideas in my head. As for Set.of, I was just experimenting with Java 9 kinks and don’t have Java 9 myself. I should’ve read the documentation more carefully, sorry about that. I’ll edit once I get on my computer. Sep 4, 2018 at 11:38

# Red, 21 bytes

func[b][b = unique b]


Try it online!

# T-SQL, 39 bytes

SELECT IIF(a=b OR b=c OR c=a,0,1)FROM s


Input is taken as separate columns a, b, c from a pre-existing table s, per our IO standards.

Tried a variation using COUNT DISTINCT from input taken as separate rows, but that was a couple bytes longer.

# Pyth, 3 bytes

s{I


Takes input as a list.
Try it here

### Explanation

s{I
{IQ     Check if the (implicit) input is invariant under deduplication.
s        Cast to int.


If we're allowed to treat True and False as 1 and 0 (which they are under the hood in Pyth), we can drop the s to get down to 2 bytes.

# SmileBASIC, 25 24 bytes

READ A,B,C?A-B&&B-C&&C-A


# Brachylog, 6 bytes

d?∧1|0


Try it online!

# short explanation

d? deduplcates input an test if still equal to input(?)

∧1 if true return 1

|0 else return 0

# ><>, 19 17 bytes

-2 bytes by Jo King.

:{:{:{=}=}=++0=n;


Try it online!

• 17 bytes
– Jo King
Sep 4, 2018 at 12:13
• I should have definitely caught that, thanks! Sep 6, 2018 at 12:36
• @RushabhMehta Please do not golf other user's posts using other user's golfing suggestions. Sep 6, 2018 at 16:20

# q 14 bytes

{x~distinct x}


Technically this solution will return '1b' or '0b', which is the way a boolean value is distinguished from a numeric type, though it retains all arithmetic functionality, and so is in essence a 1 or 0:

q)1b +35
36


To return 1 or 0 non-boolean you have the below, which takes the byte count to 21

{\$[x~distinct x;1;0]}

• {1&/0N>':x?x}
– ngn
Sep 28, 2018 at 1:39

# JavaScript (Node.js), 67 bytes

f=a=>a.map((m,i)=>a.map((n,j)=>m==n&i!=j).every(z=>!z)).every(y=>y)


Try it online!

• Sorry, but J answer is already here and the code is exactly the same. Sep 21, 2018 at 6:21
• my bad @Bubbler didn't see that coming.
– user58120
Sep 21, 2018 at 6:36
– user58120
Sep 21, 2018 at 9:14
• @Bubbler Duplicate entries are not disallowed. Sep 21, 2018 at 23:51

# 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