# 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

# 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 '18 at 2:53
• @tsh in Python 1 == True, I think there's a meta post about it somewhere – Stephen Sep 4 '18 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... – Jonathan Allan Sep 4 '18 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 '18 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 – digEmAll Sep 4 '18 at 10:14
• R almost competing with golf languages ! :D – digEmAll Sep 5 '18 at 15:59
• I believe Gauss invented mad exactly for this purpose. – ngm Sep 7 '18 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.

• – digEmAll Sep 4 '18 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. – J.Doe Sep 5 '18 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. – Kirill L. Sep 5 '18 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 – Arnauld Sep 3 '18 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. – Shaggy Sep 3 '18 at 10:46
• Oh, wait. I can just tack on &1 for 22 bytes. – Shaggy Sep 3 '18 at 10:48

# Ruby, 16 bytes

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


Try it online!

• -3 bytes with uniq! – benj2240 Sep 7 '18 at 21:11
• Boolean and Integer are different types in Ruby. – G B Sep 10 '18 at 10:11
• Ah, you're right. I didn't read the challenge closely enough, and assumed a truthy/falsey output would suffice. – benj2240 Sep 10 '18 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 '18 at 12:23
• Thanks a lot. I managed to shave off 1 more byte to arrive at 25 bytes in total – Luke Sep 4 '18 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. – MickyT Sep 4 '18 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. – Mr. Xcoder Sep 3 '18 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. – Jonathan Allan Sep 4 '18 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).

# 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
]


# 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 '18 at 8:17
• @GB Quite right! – gastropner Sep 5 '18 at 13:53

# K (oK), 4 bytes

3=#?


Try it online!

Does the count of the distinct elements equal 3?

# 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) – AdmBorkBork Sep 10 '18 at 17:50 • great! and thanks – mazzy Sep 10 '18 at 17:53 # Jelly, 2 bytes QƑ  Try it online! # Common Lisp, 25 2 bytes /=  Try it online! -23 bytes thanks to @ceilingcat! • Thanks, @ceilingcat, I've updated the answer! – Renzo Sep 22 '18 at 13:06 # 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 – ASCII-only Sep 4 '18 at 2:06
• 27 bytes: (a,b,c)->a!=b&b!=c&a!=c?1:0. – Olivier Grégoire Sep 4 '18 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. – Olivier Grégoire Sep 4 '18 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. – Quintec Sep 4 '18 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 '18 at 12:13
• I should have definitely caught that, thanks! – PidgeyUsedGust Sep 6 '18 at 12:36
• @RushabhMehta Please do not golf other user's posts using other user's golfing suggestions. – Jonathan Frech Sep 6 '18 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 '18 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. – Bubbler Sep 21 '18 at 6:21
• my bad @Bubbler didn't see that coming. – user58120 Sep 21 '18 at 6:36
• changed to JS answer – user58120 Sep 21 '18 at 9:14
• @Bubbler Duplicate entries are not disallowed. – Jonathan Frech Sep 21 '18 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? – Jonathan Frech Sep 7 '18 at 16:58