13
\$\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\$
  • 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 '18 at 10:11
  • 1
    \$\begingroup\$ Some test cases would be nice. \$\endgroup\$ – Adám Sep 3 '18 at 10:17
  • 18
    \$\begingroup\$ Whoever is downvoting all answers should at least explain why... \$\endgroup\$ – Arnauld Sep 3 '18 at 10:41
  • 1
    \$\begingroup\$ @Adám I think a more accurate title would be Are all three integers distinct? \$\endgroup\$ – Arnauld Sep 3 '18 at 10:45
  • 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\$ – Kevin Cruijssen Sep 3 '18 at 11:02

52 Answers 52

9
\$\begingroup\$

Python 3, 23 21 20 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ OP asked for 1 vs. 0, so maybe you need one more byte: lambda*a:len({*a})//3 \$\endgroup\$ – tsh Sep 4 '18 at 2:53
  • \$\begingroup\$ @tsh in Python 1 == True, I think there's a meta post about it somewhere \$\endgroup\$ – Stephen Sep 4 '18 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\$ – Jonathan Allan Sep 4 '18 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 '18 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\$
  • 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 '18 at 10:14
  • 2
    \$\begingroup\$ R almost competing with golf languages ! :D \$\endgroup\$ – digEmAll Sep 5 '18 at 15:59
  • 1
    \$\begingroup\$ I believe Gauss invented mad exactly for this purpose. \$\endgroup\$ – ngm Sep 7 '18 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\$
  • 2
    \$\begingroup\$ 20 bytes porting the R solution to a very similar question \$\endgroup\$ – digEmAll Sep 4 '18 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 '18 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 '18 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\$
  • \$\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 '18 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 '18 at 10:46
  • \$\begingroup\$ Oh, wait. I can just tack on &1 for 22 bytes. \$\endgroup\$ – Shaggy Sep 3 '18 at 10:48
4
\$\begingroup\$

Ruby, 16 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ -3 bytes with uniq! \$\endgroup\$ – benj2240 Sep 7 '18 at 21:11
  • \$\begingroup\$ Boolean and Integer are different types in Ruby. \$\endgroup\$ – G B Sep 10 '18 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 '18 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\$
  • \$\begingroup\$ 26 bytes \$\endgroup\$ – Jo King Sep 4 '18 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 '18 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 '18 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\$
  • \$\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 '18 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\$ – Jonathan Allan Sep 4 '18 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\$
3
\$\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\$

Japt -N, 3 bytes

eUâ

Try it


Explanation

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

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

J, 4 bytes

-:~.

Try it online!

Explanation:

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

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

C (gcc), 25 26 bytes

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

Try it online!

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

K (oK), 4 bytes

3=#?

Try it online!

Does the count of the distinct elements equal 3?

\$\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
    \$\begingroup\$ 26 bytes -- +(($args|group).count-eq3) \$\endgroup\$ – AdmBorkBork Sep 10 '18 at 17:50
  • \$\begingroup\$ great! and thanks \$\endgroup\$ – mazzy Sep 10 '18 at 17:53
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\$
  • \$\begingroup\$ Thanks, @ceilingcat, I've updated the answer! \$\endgroup\$ – Renzo Sep 22 '18 at 13:06
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\$
  • 1
    \$\begingroup\$ Why not count it as 43 bytes \$\endgroup\$ – ASCII-only Sep 4 '18 at 2:06
  • 1
    \$\begingroup\$ 27 bytes: (a,b,c)->a!=b&b!=c&a!=c?1:0. \$\endgroup\$ – Olivier Grégoire Sep 4 '18 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\$ – Olivier Grégoire Sep 4 '18 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 '18 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\$

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\$
  • \$\begingroup\$ 17 bytes \$\endgroup\$ – Jo King Sep 4 '18 at 12:13
  • \$\begingroup\$ I should have definitely caught that, thanks! \$\endgroup\$ – PidgeyUsedGust Sep 6 '18 at 12:36
  • \$\begingroup\$ @RushabhMehta Please do not golf other user's posts using other user's golfing suggestions. \$\endgroup\$ – Jonathan Frech Sep 6 '18 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
    \$\begingroup\$ {1&/0N>':x?x} \$\endgroup\$ – ngn Sep 28 '18 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\$
  • \$\begingroup\$ Sorry, but J answer is already here and the code is exactly the same. \$\endgroup\$ – Bubbler Sep 21 '18 at 6:21
  • \$\begingroup\$ my bad @Bubbler didn't see that coming. \$\endgroup\$ – user58120 Sep 21 '18 at 6:36
  • \$\begingroup\$ changed to JS answer \$\endgroup\$ – user58120 Sep 21 '18 at 9:14
  • \$\begingroup\$ @Bubbler Duplicate entries are not disallowed. \$\endgroup\$ – Jonathan Frech Sep 21 '18 at 23:51
1
\$\begingroup\$

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
Read Input
\$\endgroup\$
  • 1
    \$\begingroup\$ Hello and welcome to PPCG. Does your code also work for 3 integers, or is it only functional for three digits? \$\endgroup\$ – Jonathan Frech Sep 7 '18 at 16:58
  • \$\begingroup\$ @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! \$\endgroup\$ – Kitten Hugger Sep 20 '18 at 16:00
  • 2
    \$\begingroup\$ The challenge specifies You will be given 3 integers as input. which seems to render your answer invalid. \$\endgroup\$ – Jonathan Frech Sep 20 '18 at 16:43
  • \$\begingroup\$ @JonathanFrech Fixed it now! Was my first time doing this sort of thing so, I'm not the greatest at it. \$\endgroup\$ – Kitten Hugger Sep 23 '18 at 21:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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