14
\$\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
  • 19
    \$\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

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\$
  • 1
    \$\begingroup\$ 41 bytes \$\endgroup\$ – G B Sep 4 '18 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 '18 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\$
  • \$\begingroup\$ Your current answer is a snippet; either put a wrapper around it or call your language Swift REPL. \$\endgroup\$ – Jonathan Frech Sep 7 '18 at 14:31
0
\$\begingroup\$

Julia 1.0, 24 bytes

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

Try it online!

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

Ruby, 11 bytes

->a{a==a|a}

Try it online!

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

\$\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\$
  • 2
    \$\begingroup\$ I don't think this works, can you provide an example on how your function is used? \$\endgroup\$ – flawr Sep 22 '18 at 15:51
0
\$\begingroup\$

Math++, 40 29 bytes

?>a
?>b
?>c
(a-b)&(b-c)&(a-c)
\$\endgroup\$
  • 1
    \$\begingroup\$ I think the non-competing rule is a thing of the past. \$\endgroup\$ – Jonathan Frech Sep 21 '18 at 23:48
  • 1
    \$\begingroup\$ Also, could you provide an implementation link for Math++? \$\endgroup\$ – Jonathan Frech Sep 21 '18 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\$ – SuperJedi224 Sep 22 '18 at 1:30
0
\$\begingroup\$

Rust, 29 bytes

|a,b,c|(a!=b&&b!=c&&a!=c)as _

as _ means casting to a type determined by type inference. The function result needs to be assigned to a variable declared to store integers.

Try it online!

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

Lua, 38 bytes

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

Try it online!

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

C (clang), 32 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ The integers 0, 1, 2 are distinct, yet 0&... = 0. \$\endgroup\$ – Jonathan Frech Sep 22 '18 at 14:43
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\$

[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\$
-1
\$\begingroup\$

Python 2

def e(a,b,c):return 1 if len(set([a,b,c]))>2 else 0

...could be shortened to

def e(a,b,c):return len(set([a,b,c]))>2
\$\endgroup\$
  • 2
    \$\begingroup\$ I'm afraid you misunderstood the task. Your code should check whether all 3 integers are distinct not identical. \$\endgroup\$ – manatwork Sep 19 '18 at 14:08
  • \$\begingroup\$ what if a==b but a!=c? \$\endgroup\$ – Jo King Sep 19 '18 at 14:15
  • 1
    \$\begingroup\$ I'm afraid that is not all. Now it says correctly that 1,1,1 is false (not all distinct) and 1,2,3 is true (all distinct), but for 1,2,2 gives also true, though they are not all distinct. \$\endgroup\$ – manatwork Sep 19 '18 at 14:17
  • \$\begingroup\$ Fixed it with a set. Should be working correctly now. \$\endgroup\$ – Milbrae Sep 19 '18 at 14:24
  • \$\begingroup\$ @Milbrae I think your ternary if is nigh a no-op. \$\endgroup\$ – Jonathan Frech Sep 19 '18 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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