信じられないトップ10の要素がこの配列にあります


10

AKA:配列からクリックベイトを生成します。

整数の配列が与えられた場合、その配置と長さに基づいて、価値のないクリックベイトを生成します。

  • 要素数が20以下の場合、上位Xリストを作成できます。パラメータ:配列の長さ。
  • 素数は有名人なので、2つが隣り合っているときはいつでも、ゴシップとして渡されます。パラメータ:2つの隣接する素数が配列に現れる順序で。
  • 配列に2つ以上の数字が表示される場合、それは衝撃的で信じられないほどであり、誰もがそれについて聞く必要があります。複数の数字が2回表示される場合は、それぞれにニュース記事を作成します。一意の番号ごとに1回だけ印刷してください。パラメータ:総外観によって測定された数の出現。
  • 並べ替えられた 単調に増加する順序で3つ以上の要素が表示され、その後突然減少した場合は、それらがどのように並べ替えられているかを説明し、次に何が起こるかについて説明します。これは、ストレートごとに1回だけ実行してください。パラメータ:ストレートの長さ。

これらは、使用する必要があるそれぞれのクリックベイトです。

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

覚えておいてください。あなたは安いメディア会社を代表しているので、これを搾り出し、考えられるすべてのタイトルを印刷する必要があります。同じタイトルが2つある場合は、両方を印刷します。

たとえば、この配列が与えられた場合…

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サンドボックスをもっと頻繁に読むべきでしょう。これは、あなたがあなたの意見を表明したかもしれないかなりの期間、そこにありました。また、このサイトの多くの課題はクリックベイトを使用しています。これが唯一の課題であるとは限りませんlol
Conor O'Brien

6
十分なエッジケースがあるので、ロジックの答えが従うべき正確な例を示すリファレンス実装を作成することをお勧めします。
リン

5
@ ConorO'Brien:多分私はそうすべきだ、もしそこで見たなら、私はそこに私の意見を表明しただろう。しかし、黙って投票することは誰にとっても役に立たないので、私は私の投票の理由を挙げようと思いました。クリックベイトについては、良いチャレンジのキャッチーなタイトルとクリックベイトのタイトルを使用するためにのみ作られたチャレンジとの間には大きな違いがあると思います。
ბიმო

回答:


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]⁷ṀƭȮþċ⁽?ṫĠƁÆȦØ⁾Ż»ṣ€⁷¤

整数のリストを受け入れ、クリックベイトのリストのリストを返すモナディックリンク(それぞれが文字と整数のリストです)。完全なプログラムを印刷するẎYには、改行で区切られたクリックベイトを最後に追加します。

オンラインでお試しください!(フッターはクリックベイトの単一のリストを作成し、改行でそれらを区切ります。)
...または質問で与えられた例を参照してください。

どうやって?

このリンクの右端の99バイトはニラッド(引数がゼロの関数、つまり定数)を形成します。

“...“...“...“...»ṣ€⁷¤
                    ¤ - 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
これは、Jellyが文字列を圧縮できるためです。文章は“...“...“...“...»コードの一部にあり、数字の代わりに改行が付いています- このように
Jonathan Allan

1
それは完全に
たくさんの

私が見た中で最も長いゼリーゴルフ。ここで私の答えは近づきますが、それでも16バイト短くなります
dylnan

私は@dylnan 持っているいくつかの長いゼリーgolfs、そのカップル私がいると思うより印象的
ジョナサン・アラン

2

Java 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;}

input-arrayに値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
  • まだゴルフをしていますが、助けていただければ幸いです

JavaScript(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 '(または同様の)に置き換えることで保存できますか?
ジョナサンアラン

右単調増加ランを正しく処理できず、後続減少がありません(「次の」がないため、「6 Elements Sort Themselves、Find Out Next Next」が出力されません)
Jonathan Allan

不足The Top * Array Elements
l4m2

私の元の答えのこのさらに短いyコードは、私はこの方法でそれをやった。修正されます。@ l4m2ありがとう
DanielIndie

チャレンジの説明の文は2つの方法で解釈できるため、100%確信はありませんが[5,10,5,10]These 2 Elements Will Blow Your Mind2回出力するべきではありませんか?「ユニークな番号ご​​とに1回だけ印刷する」というチャレンジの部分は、番号510はなく、番号を意味すると思いますN=2。しかし、おそらくOPに確認を依頼してください。2番目の場合、実装は正しく、他の3つの答えは正しくありません。最初の場合のみ、実装が正しくありません。
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.