믿지 못할 10 가지 요소


10

AKA : 어레이에서 클릭 베이트 생성.

정수 배열이 주어지면 배열과 길이에 따라 적절한 클릭 베이트를 생성하십시오.

  • 요소가 20 개 이하이면 Top X List를 만들 수 있습니다. 파라미터 : 배열의 길이
  • 소수는 유명인이므로 두 개가 서로 옆에 있으면 가십으로 전달됩니다. 매개 변수 : 배열에 나타나는 순서대로 인접한 두 소수.
  • 배열에 숫자가 두 번 이상 나타나면 충격적이고 믿을 수 없으며 모든 사람들이 그것에 대해 들어야합니다. 여러 개의 숫자가 두 번 나타나는 경우 각각에 대해 뉴스 기사를 작성하십시오. 고유 번호 당 한 번만 인쇄하십시오. 매개 변수 : 총 모양으로 측정 된 숫자의 발생.
  • 단조 증가 순서 로 정렬 된 3 개 이상의 요소를보고 급격히 감소한 경우, 요소 가 어떻게 정렬되고 다음에 어떤 일이 발생하는지에 대해 애타게 말한다. 이 작업은 스트레이트 당 한 번만 수행하십시오. 매개 변수 : 직선 길이.

다음은 사용해야하는 각 클릭 베이트입니다.

The Top {{N}} Array Elements
{{N1}} And {{N2}} Were Spotted Together, You Won't Believe What They Did
These {{N}} Elements Will Blow Your Mind
{{N}} Elements Sort Themselves, Find Out What Comes Next

저렴한 미디어 회사를 대표한다는 점을 명심하십시오. 따라서이를 짜서 가능한 모든 제목을 인쇄해야합니다. 동일한 제목이 두 개 있으면 모두 인쇄하십시오.

예를 들어,이 배열이 주어진다면…

1,2,3,4,2,1,1,5,6

이 모든 것을 임의의 순서로 출력해야합니다.

The Top 9 Array Elements
2 And 3 Were Spotted Together, You Won't Believe What They Did
These 2 Elements Will Blow Your Mind
These 3 Elements Will Blow Your Mind
4 Elements Sort Themselves, Find Out What Comes Next

이 제목이 없다는 점 에 유의하십시오 .

3 Elements Sort Themselves, Find Out What Comes Next

코드 골프로서 바이트 단위의 최단 답변이 이깁니다.


1
@Arnauld는 급격히 줄어들지 않으므로 처음 3 개의 제목 만 인쇄하십시오.
Nissa

1
일반적으로 다운 보트는 아니지만 클릭 미끼 제목과 "do A, B 및 C, oh 및 D"유형의 챌린지에 대해 완전히 불필요한 출력 형식을 사용하기위한 챌린지를 만들기위한 -1입니다. 과제를 작성할 때 피해야 할 사항을 반드시 읽어야 합니다.
ბიმო

8
@BMO 어쩌면 샌드 박스를 더 자주 읽어야 할 것입니다. 이것은 당신이 당신의 의견을 표명했을 때 상당한 기간 동안 거기에 있었다. 또한이 사이트의 많은 도전 과제는 clickbait을 사용합니다. 이것이 그렇게하는 유일한 도전은 아닙니다
Conor O'Brien

6
정확한 논리 답변을 따라야하는 참조 구현을 작성하는 것이 좋습니다.
Lynn

5
@ ConorO'Brien : 아마 내가 거기에서 그것을 보았을 때 나는 거기에 내 의견을 표명했을 것이다. 그러나 나는 자동으로 downvoting이 아무 소용이 없기 때문에 downvote에 대한 이유를 줄 것이라고 생각했습니다. 클릭 미끼에 대해, 나는 좋은 미끼에 대한 눈에 띄는 제목과 클릭 미끼 제목을 사용하기 위해 만들어진 도전 사이에 큰 차이가 있다고 생각합니다.
ბიმო

답변:


5

젤리 , 142 바이트

I>-ṣ0ṖS€ỊÐḟ‘ɓĠL€ḟ1,ɓ¹ƝÆPẠ$ÐfW;ɓLẋ<¥21W;ż@€"“æƥu®ụ³Km&|°ẓz“ṿ$¥{d3ɓFȤSJẎVḍnṃ*¹0Ḟ¬ȤɲƝċƲạB'ɼɓ.€⁺Ƒ“¢ßUṡʠx\~⁻ḅėʠAƓḳ¶e<“½ė!Ƙ¥Ḍ3]⁷ṀƭȮþċ⁽?ṫĠƁÆȦØ⁾Ż»ṣ€⁷¤

정수 목록을 허용하고 클릭 베이트 목록 (각각 문자 및 정수 목록) 목록을 리턴하는 모나드 링크. 전체 프로그램 인쇄 라인 피드로 분리 된 clickbaits ẎY는 끝에 추가 하십시오.

온라인으로 사용해보십시오! (바닥 글은 단일 클릭 베이트 목록을 만든 다음 줄 바꿈으로 구분합니다.)
... 또는질문에 제공된 예를 참조하십시오.

어떻게?

이 링크의 맨 오른쪽 99 바이트는 nilad (인수가 0 인 함수, 즉 상수)를 형성합니다.

“...“...“...“...»ṣ€⁷¤
                    ¤ - nilad followed by link(s) as a nilad:
“...“...“...“...»     - list of compressed strings (the four clickbait-texts with the
                      -   integers replaced with line-feed characters)
                   ⁷  - literal line-feed character
                 ṣ€   - split-at for €ach (read to interweave with the integers)

이 텍스트 부분에 레이블을 X붙입니다. 이제 링크는 다음과 같습니다.

I>-ṣ0ṖS€ỊÐḟ‘ɓĠL€ḟ1,ɓ¹ƝÆPẠ$ÐfW;ɓLẋ<¥21W;ż@€"X - Link: list of integers Z
                                             - # get the monotonically increasing runs:
I                                            - incremental differences of Z
 >-                                          - greater than -1 (vectorises)
   ṣ0                                        - split at zeros
     Ṗ                                       - pop (discard final run)
      S€                                     - sum each (length - 1 for all runs)
         Ðḟ                                  - filter discard if:
        Ị                                    -   insignificant (discard any 0s or 1s)
           ‘                                 - increment (yielding all run-lengths >= 3)
            ɓ                                - new dyadic chain with that on the right
                                             - # get the multiplicities:
             Ġ                               - group indices of Z by value
              L€                             - length of €ach
                ḟ1                           - filter discard 1s
                  ,                          - pair with right (the run-lengths)
                   ɓ                         - new dyadic chain with that on the right
                                             - # get the prime-pairs
                     Ɲ                       - for each pair in Z
                    ¹                        -   identity (do nothing)
                          Ðf                 - filter keep if:
                         $                   -   last two links as a monad:
                      ÆP                     -     is prime? (vectorises)
                        Ạ                    -     all?
                            W                - wrap in a list
                             ;               - concatenate with right ([multiplicities,runs])
                              ɓ              - new dyadic chain with that on the right
                                             - # get top count as a list
                               L             - length
                                   21        - literal 21
                                  ¥          - last two links as a dyad
                                 <           -   less than? (1 if 20 or less, else 0)
                                ẋ            -   repeat ([length] if 20 or less, else [])
                                     W       - wrap in a list (i.e. [[length]] or [[]])
                                      ;      - concatenate with right ([[prime pairs],[multiplicities],[run-lengths]])
                                             - ...now we have [[length],[prime pairs],[multiplicities],[run-lengths]]
                                          "X - zip with X (the text-parts)
                                         €   -   for each (item in the current list):
                                       ż@    -     interleave with swapped arguments

감동적인! : P 문장조차 사용하지 않았다 ... wow
NL628

2
젤리는 압축 된 문자열을 가지고 있기 때문입니다. 문장은 거기에있는 “...“...“...“...»숫자 대신에 라인 피드로, 코드의 일부 - 같은
조나단 앨런

1
그것은 전체
로또

내가 본 것 중 가장 긴 젤리 골프. 내 대답은 여기에 가깝지만 여전히 16 바이트 짧습니다
dylnan

@dylnan 나는 이상 젤리 골프를 친다, 그 중 몇 내가 생각하는 더 인상적
조나단 앨런

2

자바 10, 467 457 456 453 바이트

a->{int l=a.length,i=0,p=0,P=0,m[]=new int[999],t;String e=" Elements ",r=l<21?"The Top "+l+" Array"+e+"\n":"";for(;i<l;r+=i>0&&p(p)>1&p(t=a[i-1])>1?p+" And "+t+" Were Spotted Together, You Won't Believe What They Did\n":"",m[a[i++]]++)if(p<(p=a[i]))P++;else{r+=P>2?P+e+"Sort Themselves, Find Out What Comes Next\n":"";P=1;}for(;l-->0;r+=m[l]>1?"These "+m[l]+e+"Will Blow Your Mind\n":"");return r;}int p(int n){for(int i=2;i<n;n=n%i++<1?0:n);return n;}

입력 배열이 값 0 < N < 1000( [1,999]) 을 포함한다고 가정합니다 .

온라인으로 사용해보십시오.

a->{                     // Method with integer-array parameter and String return-type
  int l=a.length,        //  Length of the input-array
      i=0,               //  Index-integer
      p=0,               //  Previous item, starting at 0
      P=0,               //  Sequence-counter, starting at 0
      m[]=new int[999],  //  Element-counter array, starting filled with 0s
      t;                 //  Temp-integer to reduce the byte-count
  String e=" Elements ", //  Temp-String " Elements " to reduce byte-count
         r=l<21?         //  If the size of the input-array is 20 or less:
            "The Top "+l+" Array"+e+"\n"
                         //    Start the result-String with 'length' gossip-line
           :             //   Else:
            "";          //    Start the result-String empty
  for(;i<l               //  Loop over the input-array
      ;                  //    After every iteration:
       r+=i>0&&          //     If this is not the first item,
           p(p)>1&p(t=a[i-1])>1?
                         //     and the current and previous items are both primes:
             p+" And "+t+" Were Spotted Together, You Won't Believe What They Did\n":"",
                         //      Append the 'two primes' gossip-line
       m[a[i++]]++)      //     Increase the counter of the current value by 1
    if(p<(p=a[i])        //   If the previous item is smaller than the current:
      P++;               //    Increase the sequence-counter by 1
    else{                //   Else:
      r+=P>2             //    If the sequence-counter is 3 or larger:
          P+e+"Sort Themselves, Find Out What Comes Next\n":"";
                         //     Append the 'sequence' gossip-line
      P=1;}              //    Reset the sequence-counter to 1
  for(;l-->0;            //  Loop over the Element-counter array
      r+=m[l]>1?         //   If this element occurred at least two times:
          "These "+m[l]+e+"Will Blow Your Mind\n":"");
                         //    Append the 'occurrence' gossip-line
  return r;}             //  Return the result

// Separated method to check if the given number is a prime
// If `n` is a prime, it remains the same; if not: either 1 or 0 is returned
int p(int n){for(int i=2;i<n;n=n%i++<1?0:n);return n;}

1
  • 여전히 골프장이지만 도움을 많이 주시면 감사하겠습니다.

자바 스크립트 (Node.js) , 397 바이트

a=>a.map(x=>(l<=x?s++:(s>2&&r.push(s+" Elements Sort Themselves, Find Out What Comes Next"),s=1),P(x)&&P(l)&&r.push(l+` And ${x} Were Spotted Together, You Won't Believe What They Did`),c[l=x]=-~c[x]),c=[s=l=r=[]])&&c.map((x,i)=>x>1&&c.indexOf(x)==i&&r.push(`These ${x} Elements Will Blow Your Mind`))&&[...r,...a[20]?[]:[`The Top ${a.length} Array Elements`]]
P=(n,i=1)=>n>1&&++i*i>n||n%i&&P(n,i)

온라인으로 사용해보십시오!


단일 문자 '!'' Elements '(또는 비슷한) 문자로 바꾸어 저장할 수 있습니까?
Jonathan Allan

후행 감소없이 오른쪽 단조 증가하는 실행을 올바르게 처리하지 못했습니다 ( "다음"이 없으므로 "6 요소 정렬, 다음에 나오는 내용 찾기"를 출력하지 않아야 함)
Jonathan Allan

부족The Top * Array Elements
l4m2

글쎄,이 원산지 답변 에서이 짧은 y 코드조차도 이렇게했습니다. 고정됩니다. @ l4m2 감사합니다
DanielIndie

챌린지 설명의 문장이 두 가지 방법으로 해석 될 수 있지만 두 번 [5,10,5,10]출력 해서는 안되기 때문에 100 % 확실하지 않습니다 These 2 Elements Will Blow Your Mind. 나는 도전 부분은 "생각 만 고유 번호 당 한 번만이 작업을 인쇄 할 수 있습니다. "이 숫자를 의미 5하고 10,하지 수를 N=2. 그러나 OP에게 확인을 요청하십시오. 두 번째 경우 구현이 정확하고 다른 세 가지 대답이 올바르지 않습니다. 첫 번째 경우에만 구현이 올바르지 않습니다.
Kevin Cruijssen

1

JavaScript (Node.js) , 351 350 349 347 바이트

a=>a.map((x,i)=>c[s=x>=l?-~s:++s>2&&(t+=s+` Elements Sort Themselves, Find Out What Comes Next
`),P(x)&P(l)&&(t+=l+` And ${x} Were Spotted Together, You Won't Believe What They Did
`),l=x]=-~c[x],t=a[20]?'':`The Top ${a.length} Array Elements
`,c=[s=l=P=(n,i=n)=>n%--i?P(n,i):1/i])+c.map(x=>x>1&&(t+=`These ${x} Elements Will Blow Your Mind
`))&&t

온라인으로 사용해보십시오!

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.