입력으로 3 개의 정수가 제공됩니다. 입력은 서로 다를 수도 있고 다를 수도 있습니다. 세 입력이 모두 다르면 1을 출력하고 입력이 두 번 이상 반복되면 0을 출력해야합니다.
이것은 code-golf 이므로 가능한 한 코드를 짧게 만드십시오!
입력으로 3 개의 정수가 제공됩니다. 입력은 서로 다를 수도 있고 다를 수도 있습니다. 세 입력이 모두 다르면 1을 출력하고 입력이 두 번 이상 반복되면 0을 출력해야합니다.
이것은 code-golf 이므로 가능한 한 코드를 짧게 만드십시오!
답변:
lambda*a:len({*a})//3
1 == True에서 @tsh , 어딘가에 메타 포스트가 있다고 생각합니다
부울 값을 출력 할 수 있으면 마지막 2 바이트를 제거 할 수 있습니다.
a=>new Set(a).size>2&1
동일한 바이트 수의 경우 모든 크기의 배열에서 작동하지만 입력에 a가 포함되지 않고 0출력이 부울 이라고 가정합니다 .
a=>!a[new Set(a).size]
a=>new Set(a).size>2
&122 바이트 만 사용할 수 있습니다 .
ÙQ
설명:
Ù # Uniquify the (implicit) input
Q # Check if it's still equal to the (implicit) input
4예를 들어, 어느 쪽도하지 1않고 0, 나처럼 행동하지 않습니다 1또는 0(같은 True과 False파이썬에서 할). 질문은 아마도 Truthy / Falsey를 요구해야하지만 현재는 그렇지 않습니다.
Boole[E!=##]&
순수한 기능. 세 개의 정수를 입력 및 리턴 0또는 1출력으로 사용합니다. 나는 이것이 David G. Stork의 대답 과 다소 비슷하다는 것을 알고 있지만 SlotSequence(와 비교하여 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 바이트 덕분에 @AdmBorkBork
+!(($args|group).Count-3)
테스트 스크립트 :
$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
설명:
$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)
익명의 암묵적 접두사 기능. 리스트를 인수로 사용합니다.
∪≡⊢
∪ 인수에서 고유 한 요소 집합을 수행합니다.
≡ 시합
⊢ 수정되지 않은 논쟁?
`==#Unique
이것은 연산자의 포크이며 다음 `==과 Unique같습니다.
{ _ == Unique[_] }
{#_=#Unique[_]} (15 바이트)
Any##Same=>Pairs@Sort (21 바이트)
Any@{`=&>_[[0'1,1'2,2'0]]} (26 바이트)
&${not(x=y or y=z or x=z)} (26 바이트)
&${x/=y and y/=z and x/=z} (26 바이트)
{Any!Same=>Chop&2!_[0'1'1'2'2'0]} (33 바이트)
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?