[jane street] insight program OA

Secret Code Matches

Problem Setup

We are playing a game. In this game, there are two players: a "guesser" and a "codemaker." The codemaker begins by selecting a secret code consisting of a sequence of four colors chosen from:

  • Red (R)
  • Orange (O)
  • Green (G)
  • Blue (B)
  • Yellow (Y)

Examples of a secret code:

  • RGBY
  • GGGO
  • YOYO

Rules:

During each round, the guesser tries to guess the secret code. They will receive a response indicating the following:

  1. Exact matches: The number of colors that are both in the correct position and the correct color.
  2. Color matches: The number of correctly guessed colors that are in the wrong position.

Possible Secret Codes Left

Problem Setup

Now we want to think in the "guesser’s" shoes about how we would play the game as a "smart guesser." Probably, as we make guesses to the secret code, we would want to think about the set of "possible secret codes" that are left: that is, the set of codes that are consistent with the guesses we have been making and the responses that we have received back.

Example:

Say that the first guess we made was RGBY and we received a response of [0, 0]. This means that the remaining secret codes can only be made up of P and O, since there were no color matches with RGBY.

If we then guessed PPPP and received [3, 0], we know the set of possible results looks like:
["OPPP", "POPP", "PPOP", "PPPO"]

These are all the codes left that don’t match RGBY at all and have 3 exact matches with PPPP.


Cheating Codemaker

Problem Setup

Now, we want to consider ourselves in the codemaker’s shoes and think about how we could “cheat” at the game.

If we are the codemaker, we decide how to respond to any given guess in each round of the game. In the normal version of the game, at the very start, we decide on a single 4-color code and “commit” to it—only responding to guesses in a way that’s consistent with that code.

However, one possible cheating strategy is not selecting a single secret code at the beginning, but instead responding to each guess in a way that leaves the highest number of possible secret codes.

The response must also be consistent with previous guesses, for example:
If we responded with 0 exact and color matches to the guess RGBY, we couldn’t respond with any matches for the guess YBGR (since none of those colors should be present in the secret code).

Therefore, we only have to commit to a code when there’s no other possibilities left that are consistent with all the past guesses and responses.

Function Description

Your task is to implement a function that takes a guess and all previous guesses and responses. The function should output a response that maximizes the number of possible secret codes left after the response is given.


Beating the Cheater (Idea Generation)

Now that we know the codemaker is cheating, briefly describe (in a few sentences) an algorithm we could write to determine the best guess to make, given that the codemaker will respond in the worst way possible. Please give enough information to understand your algorithm, but you don’t need to specify it too in-depth—just the overall algorithm you could use to make the best guess.

Prompt:
Please provide your answer in the following editor.


我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *