所有三个整数都不同吗?


14

您将获得3个整数作为输入。输入可以彼此相同或可以彼此不同。如果所有三个输入都互不相同,则必须输出1;如果任何输入重复多次,则必须输出0。

这是,因此请使您的代码尽可能短!


1
欢迎来到PPCG。不错的第一个挑战。我们对该网站的客观获胜标准非常严格。代码高尔夫球似乎是这里的明显选择,因此我将其添加到您的帖子中。如果我错了纠正我。
亚当

1
一些测试用例会很好。
亚当

19
拒绝所有答案的人至少应解释原因……
Arnauld

1
@Adám我认为更准确的标题是这三个整数是否都不同?
Arnauld

5
我的伪票是一把锤子,但可能重复的“ 确定所有十进制数字是否唯一稍有不同,但大多数答案仍可以移植。
凯文·克鲁伊森

Answers:


10

Python 3中23个 21 20字节

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

在线尝试!


OP要求1对0,所以也许您还需要一个字节:lambda*a:len({*a})//3
tsh

@tsh in Python 1 == True,我认为某处有关于它的meta帖子
Stephen

1
@tsh- 相关的元数据 “如果像数字一样嘎嘎叫,那是一个数字”-在Python中:False * Trueis 0; False + True1; 等等...
乔纳森·艾伦

从相关的meta中:“这不适用于需要精确字符串输出的挑战”,因此我不确定在这里真正适用什么。
GB


8

R,13个字节

@Kirill的不同解决方案,mad()用于非预期目的!

mad(scan())>0

在线尝试!


1
井输入根本没有指定,因此IMO接受3个值作为输入意味着我们可以接受向量
digEmAll

2
R几乎与高尔夫语言竞争!:D
digEmAll

1
我相信高斯mad正是为此目的而发明的。
ngm

5

R24 22 20字节

all(table(scan())<2)

在线尝试!

返回一个布尔值,但是正如人们已经在Python答案上讨论的那样,这应该可以。

感谢digEmAll节省了2个字节。



11个字节 -如果允许您将真值大于0的任何数字。否则,追加>0TRUE/FALSE13个字节输出。
J.Doe '18

1
哇,甚至都不知道这个功能。我建议您将其单独发布(编辑并恢复删除的答案),但是我认为您必须坚持使用13个字节-T / F的确像1/0,而1.48则不然。
Kirill L.

5

JavaScript,22个字节

如果我们可以输出布尔值,那么可以删除最后2个字节。

a=>new Set(a).size>2&1

在线尝试

对于相同的字节数,此方法适用于任何大小的数组,但假定输入将永远不包含a 0并且输出为布尔值。

a=>!a[new Set(a).size]

在线尝试


假设我们可以将输入作为数组并返回布尔值:a=>new Set(a).size>2
Arnauld

@Arnauld,是的,我也有,但是按照目前的规范,它是不允许的-但是,如果规范发生更改,它将进行更新。
毛茸茸的

等一下。我可以&1增加22个字节。
毛茸茸的


4

Cubix55 25字节

-29感谢Jo King

O@O1u|@O@II-!/;I-!/;u^?-p

在线尝试!

It should be possible to golf off quite a few bytes.



Thanks a lot. I managed to shave off 1 more byte to arrive at 25 bytes in total
Luke

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

3

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

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

1
@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

3

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


3

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
]

2

Japt -N, 3 bytes

eUâ

Try it


Explanation

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





2

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

1
26 bytes -- +(($args|group).count-eq3)
AdmBorkBork

great! and thanks
mazzy





1

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)


1

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

1
Why not count it as 43 bytes
ASCII-only

1
27 bytes: (a,b,c)->a!=b&b!=c&a!=c?1:0.
Olivier Grégoire

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

@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


1

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.


1

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.


1

SmileBASIC, 25 24 bytes

READ A,B,C?A-B&&B-C&&C-A



1

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
{1&/0N>':x?x}
ngn


1

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

1
Hello and welcome to PPCG. Does your code also work for 3 integers, or is it only functional for three digits?
Jonathan Frech

@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!
Kitten Hugger

2
The challenge specifies You will be given 3 integers as input. which seems to render your answer invalid.
Jonathan Frech

@JonathanFrech Fixed it now! Was my first time doing this sort of thing so, I'm not the greatest at it.
Kitten Hugger
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.