您将获得3个整数作为输入。输入可以彼此相同或可以彼此不同。如果所有三个输入都互不相同,则必须输出1;如果任何输入重复多次,则必须输出0。
这是代码高尔夫球,因此请使您的代码尽可能短!
您将获得3个整数作为输入。输入可以彼此相同或可以彼此不同。如果所有三个输入都互不相同,则必须输出1;如果任何输入重复多次,则必须输出0。
这是代码高尔夫球,因此请使您的代码尽可能短!
Answers:
uniq!
-29感谢Jo King
O@O1u|@O@II-!/;I-!/;u^?-p
It should be possible to golf off quite a few bytes.
@
in place of the .
in the 9th spot. Makes it do some funky things for 1 2 2.
Ù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
1
is the only truthy value in 05AB1E, ¢P
works as well as an alternative 2-byter.
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.
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
).
,>,>,[-<-<->>]>>+++++++[>+++++++<-]+<<<<[>]>>[<<<[-<->]<[>]>>->[>.<<<->>-]<+]<+[>>>[>]<-.>]
,>,>, '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 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
+(($args|group).count-eq3)
Anonymous tacit prefix function. Takes list as argument.
∪≡⊢
∪
does the set of unique elements from the argument
≡
match
⊢
the unmodified argument?
`==#Unique
This is a fork of the operator `==
and Unique
, equivalent to:
{ _ == Unique[_] }
{#_=#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)
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
(a,b,c)->a!=b&b!=c&a!=c?1:0
.
==
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.
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.
s{I
Takes input as a list.
Try it here
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.
d?∧1|0
d?
deduplcates input an test if still equal to input(?)
∧1
if true return 1
|0
else return 0
{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&/0N>':x?x}
f=a=>a.map((m,i)=>a.map((n,j)=>m==n&i!=j).every(z=>!z)).every(y=>y)
ɠḲQL=3
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
3 integers
, or is it only functional for three digits?