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

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\$
4
  • 1
    \$\begingroup\$ Hello and welcome to PPCG. Does your code also work for 3 integers, or is it only functional for three digits? \$\endgroup\$ Sep 7, 2018 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\$ Sep 20, 2018 at 16:00
  • 2
    \$\begingroup\$ The challenge specifies You will be given 3 integers as input. which seems to render your answer invalid. \$\endgroup\$ Sep 20, 2018 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\$ Sep 23, 2018 at 21:25
1
\$\begingroup\$

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.

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

Vyxal, 1 byte

Try it Online!

Easy peasy

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

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think x∪x==x works \$\endgroup\$
    – MarcMush
    Feb 24 at 12:42
0
\$\begingroup\$

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.
\$\endgroup\$
0
\$\begingroup\$

Charcoal, 14 bytes

≔E³NθI¬⊖⌈Eθ№θι

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:

≔E³Nθ

Input 3 numbers and make a list.

I¬⊖⌈Eθ№θι

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.

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

PHP, 30 bytes

<?=array_unique($argv)==$argv;

takes input from command line arguments; prints 1 for truthy, empty string for falsy

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

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 41 bytes \$\endgroup\$
    – G B
    Sep 4, 2018 at 8:46
  • \$\begingroup\$ Thanks, I had thought about incrementing the pointer but couldn't figure out how to make it as short ! \$\endgroup\$
    – etene
    Sep 4, 2018 at 9:24
0
\$\begingroup\$

Flobnar, 25 bytes

$-<*\\\!!@
::*<&&&
-$$>
$

Try it online!

Given integers a,b,c, evaluates !!((c-b)*(b-a)*(c-a))

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

SWIFT 37 Bytes

Set(Array(readLine()!)).count==3 ?1:0
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Your current answer is a snippet; either put a wrapper around it or call your language Swift REPL. \$\endgroup\$ Sep 7, 2018 at 14:31
0
\$\begingroup\$

Julia 1.0, 24 bytes

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

Try it online!

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

Pari/GP, 12 bytes

a->#Set(a)>2

Try it online!

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

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.

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

Haskell, 26 bytes

g a b c=and$map(==)[a,b,c]
\$\endgroup\$
1
  • 2
    \$\begingroup\$ I don't think this works, can you provide an example on how your function is used? \$\endgroup\$
    – flawr
    Sep 22, 2018 at 15:51
0
\$\begingroup\$

Math++, 40 29 bytes

?>a
?>b
?>c
(a-b)&(b-c)&(a-c)
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I think the non-competing rule is a thing of the past. \$\endgroup\$ Sep 21, 2018 at 23:48
  • 1
    \$\begingroup\$ Also, could you provide an implementation link for Math++? \$\endgroup\$ Sep 21, 2018 at 23:49
  • \$\begingroup\$ @JonathanFrech OK, I just added a link to the esolang page; the article includes a link to the reference implementation. \$\endgroup\$ Sep 22, 2018 at 1:30
0
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can pull the 1^ inside the parentheses, changing == to != and | to & and then remove said parentheses to save four bytes. \$\endgroup\$ Sep 23, 2018 at 7:26
  • \$\begingroup\$ @JonathanFrech Updated \$\endgroup\$ Sep 23, 2018 at 14:58
0
\$\begingroup\$

Lua, 38 bytes

x,y,z=...print(x~=y and x~=z and y~=z)

Try it online!

\$\endgroup\$
4
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – DLosc
    Sep 21, 2018 at 21:16
  • \$\begingroup\$ Opposed to equality, inequality is not transitive, so \$x\neq y\neq z\$ does not imply \$x\neq z\$. \$\endgroup\$ Sep 21, 2018 at 23:45
  • \$\begingroup\$ Your answer in its current form is invalid. Please either fix or delete it. \$\endgroup\$ Sep 23, 2018 at 5:47
  • \$\begingroup\$ Thank you guys, I really didn't noticed it. \$\endgroup\$ Sep 24, 2018 at 16:15
0
\$\begingroup\$

C (clang), 32 bytes

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

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ The integers 0, 1, 2 are distinct, yet 0&... = 0. \$\endgroup\$ Sep 22, 2018 at 14:43
  • \$\begingroup\$ f(a,b,c){return a-b&&b-a&&a-c;} \$\endgroup\$
    – l4m2
    Mar 22, 2021 at 11:36
  • \$\begingroup\$ b-a=>b-c mistake from your code \$\endgroup\$
    – l4m2
    Mar 22, 2021 at 11:37
0
\$\begingroup\$

Braingolf, 5 bytes

ul3-n

Try it online!

Edit: fixed from identical -> distinct

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

Pepe, 85 77 bytes

rEeEREeErrEEEEEeRrEeErrEEEEEerEEEEEEERerEEEEEerRrEEEEEEeErREEREEEEErEeReeReEE

Try it online! Input is a,b,c. Change the "separated by" box to , to make it work!

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

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.

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

MathGolf, 2 bytes

▀=

Try it online!

Explanation

▀    Get unique elements
 =   Check if equal to the input
\$\endgroup\$
0
\$\begingroup\$

Husk, 3 bytes

S=U

Try it online! Takes the three numbers in a list.

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

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

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

Rust, 29 23 bytes

|a,b,c|a!=b&&b!=c&&a!=c

Try it online!

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

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.

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

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)

With comments

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

Factor, 11 bytes

all-unique?

Try it online!

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

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

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.

\$\endgroup\$

Your Answer

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

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