您不会相信的十大要素


10

又名:从阵列生成Clickbait。

给定一个整数数组,请根据其排列和长度生成一些值得赞扬的clickbait:

  • 如果不超过20个元素,则可以列出“ Top X列表”。参数:数组的长度。
  • 素数是名人,因此每当两个人相邻时,它就会成为八卦。参数:两个相邻素数在数组中出现的顺序。
  • 如果任何数字在数组中出现两次或多次,那么这令人震惊且令人难以置信,每个人都需要听听它。如果多个数字出现两次,则为每个数字制作一个新闻故事。每个唯一编号仅打印一次。参数:出现次数以外观总数表示。
  • 如果你看到3+元素排序 单调递增的顺序,然后突然下降,然后告诉他们如何排序,并了解后续挑逗。每直只做一次。参数:直线的长度。

这些是您应使用的各个Clickbaits:

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那里不会突然减少,因此只需打印前三个标题即可。
妮莎

1
通常我不会投票,但是-1是为了仅使用点击诱饵标题和完全不必要的输出格式来创建挑战的类型,即“做A,B和C,哦,也做D”类型的挑战。在编写挑战时,您应该真正阅读避免使用的东西
ბიმო

8
@BMO也许您应该更经常阅读沙盒。当您可能发表了自己的看法时,它在那里呆了相当长的时间。另外,此网站上的许多挑战都使用clickbait,这并不是这样做的唯一挑战,大声笑
Conor O'Brien

6
我建议您编写一个参考实现,以证明应该遵循的确切逻辑答案是足够的。
林恩

5
@ ConorO'Brien:也许我应该,如果在那儿看到它,我会在那儿表达我的意见。但是我认为我应该给我低票的理由,因为默默地低票对任何人都没有用。关于点击诱饵,我认为好挑战的标题和仅使用点击诱饵标题的挑战之间存在巨大差异。
ბიმო

Answers:


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到末尾。

在线尝试!(Footer列出了一个单独的clickbaits列表,然后用换行符将它们隔开。)
...或参见问题中给出的示例

怎么样?

该链接的最右边的99个字节构成一个nilad(带有零参数的函数,即常量):

“...“...“...“...»ṣ€⁷¤
                    ¤ - 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甚至都没有用过这些句子...哇
NL628 '18

2
这是因为Jelly具有压缩字符串的能力。句子是那里的“...“...“...“...»代码的一部分,换行符到位的数字- 这样
乔纳森·艾伦

1
那真是个果冻……
Khuldraeseth na'Barya

我见过的最长的果冻高尔夫球。我的答案在这里接近,但仍短了16个字节
dylnan

@dylnan我一个果冻了高尔夫这是更长的时间,一对夫妇,其中我认为是更令人印象深刻
乔纳森·艾伦

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

假设输入数组将包含值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个元素排序自己,找出接下来的结果”,因为没有“下一步”)
乔纳森·艾伦

缺失The Top * Array Elements
l4m2

好吧,在我的原始答案中,这甚至更短的y代码我也是这样做的。将被修复。@ l4m2感谢
DanielIndie '18

我不确定100%,因为挑战说明中的句子可以用两种方式解释,但不应该[5,10,5,10]输出These 2 Elements Will Blow Your Mind两次吗?我想挑战的一部分“ 只打印这个每唯一编号一次。 ”指的是数字510,数量不限N=2。但也许请OP进行验证。如果第二个,您的实现是正确的,而其他三个答案是不正确的。如果只有第一个,则您的实现不正确。
凯文·克鲁伊森

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

在线尝试!

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.