19
\$\begingroup\$

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!

\$\endgroup\$
8
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Adám
    Sep 3, 2018 at 10:11
  • 1
    \$\begingroup\$ Some test cases would be nice. \$\endgroup\$
    – Adám
    Sep 3, 2018 at 10:17
  • 20
    \$\begingroup\$ Whoever is downvoting all answers should at least explain why... \$\endgroup\$
    – Arnauld
    Sep 3, 2018 at 10:41
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ Sep 3, 2018 at 11:02
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – don bright
    Jan 1, 2019 at 0:32

66 Answers 66

10
\$\begingroup\$

Python 3, 23 21 20 bytes

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

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ OP asked for 1 vs. 0, so maybe you need one more byte: lambda*a:len({*a})//3 \$\endgroup\$
    – tsh
    Sep 4, 2018 at 2:53
  • \$\begingroup\$ @tsh in Python 1 == True, I think there's a meta post about it somewhere \$\endgroup\$
    – Stephen
    Sep 4, 2018 at 4:14
  • 1
    \$\begingroup\$ @tsh - relevant meta "if it quacks like a number, it's a number" - in Python: False * True is 0; False + True is 1; etc... \$\endgroup\$ Sep 4, 2018 at 7:09
  • \$\begingroup\$ 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. \$\endgroup\$
    – G B
    Sep 6, 2018 at 6:39
8
\$\begingroup\$

Perl 6, 7 bytes

*.Set>2

Try it online!

\$\endgroup\$
8
\$\begingroup\$

R, 13 bytes

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

mad(scan())>0

Try it online!

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

R, 24 22 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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ 20 bytes porting the R solution to a very similar question \$\endgroup\$
    – digEmAll
    Sep 4, 2018 at 13:28
  • \$\begingroup\$ 11 bytes - if you are allowed to have any number > 0 as truthey. Otherwise, append >0 for TRUE/FALSE output in 13 bytes. \$\endgroup\$
    – J.Doe
    Sep 5, 2018 at 8:22
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Kirill L.
    Sep 5, 2018 at 8:52
5
\$\begingroup\$

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

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

Ruby, 16 bytes

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

Try it online!

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

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.

\$\endgroup\$
3
  • \$\begingroup\$ 26 bytes \$\endgroup\$
    – Jo King
    Sep 4, 2018 at 12:23
  • \$\begingroup\$ Thanks a lot. I managed to shave off 1 more byte to arrive at 25 bytes in total \$\endgroup\$
    – Luke
    Sep 4, 2018 at 14:52
  • \$\begingroup\$ 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. \$\endgroup\$
    – MickyT
    Sep 4, 2018 at 19:02
3
\$\begingroup\$

05AB1E, 2 bytes

ÙQ

Try it online or verify some more cases.

Explanation:

Ù     # Uniquify the (implicit) input
 Q    # Check if it's still equal to the (implicit) input
\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – Mr. Xcoder
    Sep 3, 2018 at 11:13
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Sep 4, 2018 at 7:24
3
\$\begingroup\$

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).

\$\endgroup\$
0
3
\$\begingroup\$

J, 4 bytes

-:~.

Try it online!

Explanation:

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

\$\endgroup\$
3
\$\begingroup\$

K (oK), 4 bytes

3=#?

Try it online!

Does the count of the distinct elements equal 3?

\$\endgroup\$
2
\$\begingroup\$

Japt -N, 3 bytes

eUâ

Try it


Explanation

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

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 25 26 bytes

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

Try it online!

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

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
]
\$\endgroup\$
2
\$\begingroup\$

Powershell, 27 25 bytes

-2 bytes thanks @AdmBorkBork

+!(($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
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 26 bytes -- +(($args|group).count-eq3) \$\endgroup\$ Sep 10, 2018 at 17:50
2
\$\begingroup\$

Jelly, 2 bytes

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 25 2 bytes

/=

Try it online!

-23 bytes thanks to @ceilingcat!

\$\endgroup\$
0
1
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

Clean, 32 bytes

import Data.List
$l|hasDup l=0=1

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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)

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Why not count it as 43 bytes \$\endgroup\$
    – ASCII-only
    Sep 4, 2018 at 2:06
  • 1
    \$\begingroup\$ 27 bytes: (a,b,c)->a!=b&b!=c&a!=c?1:0. \$\endgroup\$ Sep 4, 2018 at 9:03
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 4, 2018 at 9:11
  • \$\begingroup\$ @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. \$\endgroup\$
    – Quintec
    Sep 4, 2018 at 11:38
1
\$\begingroup\$

Red, 21 bytes

func[b][b = unique b]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 25 24 bytes

READ A,B,C?A-B&&B-C&&C-A
\$\endgroup\$
1
\$\begingroup\$

Ruby, 11 bytes

->a{a==a|a}

Try it online!

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

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

><>, 19 17 bytes

-2 bytes by Jo King.

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

Try it online!

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

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]}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ {1&/0N>':x?x} \$\endgroup\$
    – ngn
    Sep 28, 2018 at 1:39
1
\$\begingroup\$

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.