# The Top Ten Elements You Won't BELIEVE Are In This Array

AKA: Generate Clickbait From an Array.

Given an array of integers, generate some cringe-worthy clickbait based on its arrangement and length:

• If it's 20 elements or less, you can make a Top X List. Parameters: length of the array.
• Prime numbers are celebrities, so anytime two of them are next to each other it'll pass as gossip. Parameters: the two adjacent primes in the order they appear in the array.
• If any number appears twice or more in the array, then it's shocking and unbelievable and everyone needs to hear about it. If multiple numbers appear twice, make a news story for each one. Only print this once per unique number. Parameters: occurrence of the number measured by total appearance.
• If you see 3+ elements in sorted monotonically increasing order, followed by a sudden decrease, then tell of how they're sorted and tease about what happens next. Only do this once per straight. Parameters: length of the straight.

These are the respective clickbaits you should use:

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


Remember, you represent a cheap media company, so you'll need to milk this and print every possible title. If there are 2 identical titles, print them both.

For example, if you're given this array…

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


You should output all of these, in arbitrary order:

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


Note the lack of this title:

3 Elements Sort Themselves, Find Out What Comes Next


As code golf, the shortest answer in bytes wins.

• @Arnauld there's no sudden decrease there, so just print the first 3 titles. Apr 22, 2018 at 16:32
• Usually I don't downvote, but -1 for solely creating a challenge just to use a click-bait title and a completely unnecessary output format for a challenge of type "do A, B and C, oh and also D". You should really read Things to avoid when writing challenges. Apr 22, 2018 at 16:42
• @BMO Maybe you should read the sandbox more often. This was on there for a considerable duration, when you might have voiced your opinions. Also, many challenges on this site use clickbait, it's not like this is the only challenge to do so lol Apr 22, 2018 at 16:53
• There are enough edge cases that I suggest you write a reference implementation that demonstrates the exact logic answers should follow.
– Lynn
Apr 22, 2018 at 18:56
• @ConorO'Brien: Probably I should, if I saw it there I'd voiced my opinion there. But I thought I'd give a reason for my downvote because silently downvoting is of no use to anyone. About the click-bait, I think there's a massive difference between a catchy title for a good challenge and a challenge that's only been made for using a click-bait title. Apr 22, 2018 at 20:41

# Jelly, 142 bytes

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


A monadic link accepting a list of integers, returning a list of lists of clickbaits (each of which is a list of characters and integers). For a full program printing line-feed separated clickbaits just add ẎY to the end.

Try it online! (Footer makes a single list of clickbaits and then separates them with new-lines.)
...or see the example given in the question.

### How?

The 99 right-most bytes of this Link form a nilad (a function with zero arguments, i.e. a constant):

“...“...“...“...»ṣ€⁷¤
“...“...“...“...»     - 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)


Let's label these text-parts as X, now the Link is:

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

• Impressive! :P Didn't even use the sentences...wow Apr 22, 2018 at 20:12
• That is because Jelly has the ability to have compressed strings. The sentences are there in the “...“...“...“...» part of the code, with line feeds in place of the numbers -- like this Apr 22, 2018 at 20:15
• That's a whole lotta Jelly... Apr 22, 2018 at 21:19
• Longest jelly golf I've seen. My answer here comes close but still shorter by 16 bytes Apr 22, 2018 at 21:42
• @dylnan I have a few Jelly golfs which are longer, a couple of which I think are more impressive Apr 22, 2018 at 22:07

# Java 10, 467457456 453 bytes

a->{int l=a.length,i=0,p=0,P=0,m[]=new int,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;}


Assumes the input-array will contain values 0 < N < 1000 ([1,999]).

Try it online.

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,  //  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:
//    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;}

• still golfing but help will be much appreciated

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?[]:[The Top ${a.length} Array Elements]] P=(n,i=1)=>n>1&&++i*i>n||n%i&&P(n,i)  Try it online! • Could you save by replacing a single character like '!' with ' Elements ' (or similar)? Apr 22, 2018 at 20:04 • You've failed to correctly handle a right-hand monotonically increasing run with no trailing decrease (the link you give should not output "6 Elements Sort Themselves, Find Out What Comes Next", as there is no "Next") Apr 22, 2018 at 20:08 • Lack The Top * Array Elements – l4m2 Apr 23, 2018 at 1:50 • well this even shorter y code in my origin answer i did it this way. will be fixed. @l4m2 thanks Apr 23, 2018 at 5:04 • I'm not 100% sure, because the sentence in the challenge description can be interpret two ways, but shouldn't [5,10,5,10] output the These 2 Elements Will Blow Your Mind twice? I think the challenge part "Only print this once per unique number." means the numbers 5 and 10, not the number N=2. But perhaps ask OP to verify. If the second, your implementation is correct and the other three answers are incorrect. If the first only your implementation is incorrect. Apr 23, 2018 at 13:13 # JavaScript (Node.js), 351350349 347 bytes 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?'':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


Try it online!