Skip to main content
5 of 5
Change link to direct to Wikipedia rather than a now deleted comment
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

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.

Nissa
  • 3.6k
  • 1
  • 18
  • 45