The Top Ten Elements You Won't BELIEVE Are In This Array
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):
“...“...“...“...»ṣ€⁷¤
¤ - 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)
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
¥ - 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
Java 10, 467 457 456 453 bytes
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;}
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[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;}