DEV Community

Matt Ellen-Tsivintzeli
Matt Ellen-Tsivintzeli

Posted on

1 2

Turkey detector: awful answers only

It's turkey season in many places, especially for those of you in the United States of America.

And we all know what a turkey is, right? Yes, that's right. In ten pin bowling a turkey is when you get three strikes in a row.

I'm not sure why this time of year is dedicated to that, but there you have it. Traditions don't always make sense.

So, today's challenge is to find turkeys in people's bowling scores.

The function you write will need to take an array of arrays. The array will hold up to ten sub arrays. The first 9 sub arrays will always have 2 integers, from 0 to 10, and the 10th sub array will hold either 2 or 3 integers, from 0 to 10.

A strike for the first 9 sub arrays a strike is this sub array: [10,0].

For the 10th frame there can be up to 3 strikes:

  • single strikes: [10, 0, x], [x, 10-x, 10]
  • double strikes: [10, 10, x]
  • turkey: [10, 10, 10]

Where x is any integer from 0 to 9.

Examples:

hasTurkey([[0,10],[1,5]]) //false
hasTurkey([[10,0],[10,0],[10,0]]) //true
hasTurkey([[10,0],[10,0],[0,10]]) //false
hasTurkey([[10,0],[10,0],[0,10],[9,1],[10,0]]) //false
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[10,0],[10,0],[10,0],[0,10,4]]) //true
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[10,0],[10,0],[9,1],[0,10,4]]) //false
hasTurkey([[0,10],[1,5],[2,1],[0,4],[8,1],[8,0],[1,0],[1,0],[10,0],[10,10,4]]) //true
Enter fullscreen mode Exit fullscreen mode

I want to see your worst implementations. Exponential time. Exponential space. Convoluted code. All of it. Roast the CPU like a turkey.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay