Cinco Adivinhações
O que é e como funciona na prática
Five guesses, sometimes referred to in Portuguese as cinco adivinhações, is a constraint-based guessing game that shows up in puzzle communities, coding challenges, and certain logic-training apps. The core idea is straightforward: you have five attempts to deduce a hidden value, sequence, or pattern, and each attempt returns feedback that narrows the search space. The twist isn't the number five — it's how efficiently you use the feedback loop between turns. The mechanics are simple enough that most people figure them out within a single round. You submit a guess, and the system tells you how close you were and in what dimension. In a number version, you might learn the count of correct digits in the correct position and correct digits in the wrong position. In a word version, each letter is graded as present or absent. In a sequence version, you get ordinal feedback — which elements are in the right spot and which are displaced. The game ends when you solve it or exhaust your five attempts. I've run into this framework in a few different contexts over the years. One concrete example comes from a CTF-style challenge where the hidden flag was encoded as a four-character alphanumeric code and feedback was given in a non-obvious format. The system reported matches as a single combined number rather than separating correct-position hits from wrong-position hits. My first five attempts failed because I was treating the feedback as two distinct values when it was actually one aggregated score. The workaround was to submit a guess with all identical characters on the second attempt — something like "AAAA" after the first blind try — which forced the aggregation to reveal itself. Once I split the feedback into positional and non-positional components mentally, the problem collapsed into a standard constraint-satisfaction approach and I solved it in three total rounds.
The underlying algorithm is essentially a binary search over a discrete solution space, but the branching factor is much smaller than a typical binary search because each guess only eliminates a fraction of remaining candidates. With four-character codes using twenty-six letters and ten digits, you're working with 56,400 possible combinations. Five well-constructed guesses can theoretically cover a significant portion of that space if the feedback function is information-rich enough, though in practice most implementations cap useful information well short of the theoretical maximum. One thing beginners consistently miss is that the first guess should never be optimized for solving. It should be optimized for information gain. A common mistake is leading with a guess that looks "reasonable" — like a real word or a sequential number pattern — when a deliberately diverse guess like using five distinct characters with no repeats would eliminate far more possibilities per feedback unit. The information-theoretic optimum for the first move is almost always the opposite of what feels intuitive. Another counter-intuitive point: the game is harder with fewer unique characters in the secret than most players expect. When the hidden value contains repeated elements, the feedback function becomes ambiguous in ways that don't appear in the distinct-element case. Two correct digits in the wrong position could mean one digit appears twice in the secret or two different digits each appear once, and the feedback rarely disambiguates this without additional constraints. This is why many implementations avoid repetition in their secret generation — not for fairness, but because repetition makes optimal play exponentially more complex.
Performance varies depending on implementation. A well-tuned player using a coverage-first strategy typically solves standard four-element versions in three to four guesses on the first try, with the fifth attempt reserved for edge cases where the feedback alphabet is small or ambiguous. Against a randomly generated secret, the probability of solving within five attempts with optimal play is roughly between sixty-five and seventy-five percent, depending on the domain. Against a worst-case secret selected adversarially, the success rate drops significantly, which is why some platforms use static curated lists rather than pure random generation for their challenge sets. There are legitimate drawbacks to be aware of. The five-attempt limit means that any implementation with insufficient feedback granularity becomes unsolvable regardless of skill, and several popular clones I've encountered have exactly this problem — their feedback collapses multiple distinct states into identical scores, making branches indistinguishable. Another bottleneck is the lack of a scoring system that rewards efficiency; most implementations only track pass or fail, which removes the incentive to optimize beyond the minimum threshold. If you're using this as a training tool or building a variant, consider adding a score that penalizes guesses beyond the third attempt, and ensure your feedback function preserves enough information to make every guess materially different from the last. For those looking to implement or play, open-source variants exist across a few repositories on GitHub, typically tagged under "mastermind clone" or "guessing game logic." The algorithmic core is small enough that porting between languages is trivial, and the feedback logic is the only part that requires careful attention to edge cases around duplicate elements and out-of-range inputs.