Brain Out ยท Level 190

Brain Out Level 190

๐Ÿ“ Walkthrough

Overview

Level 190 shows a Java-style selection-sort method on screen, with the question "a=?" at the top. The code declares var a, b, c;, then inside the outer loop sets int m = i; b = 10;, and inside the inner loop says if (number[j] < number[m]) a = b;. Most players try to trace the whole sort, tracking the array and every swap, but the Brain Out trick is to ignore the algorithm. The only assignment that touches a is a = b, and b is hard-coded to 10. So whenever a gets assigned, it gets 10. The answer to type is 10.

  • Difficulty: Regular
  • Estimated moves: 2

Step-by-Step Solution

  1. Read the question at the top: it asks "a=?" You are not being asked to run the sort or output the array; you are being asked for the value of variable a.
  2. Scan the code from top to bottom. The declaration var a, b, c; introduces the variables but does not initialize them.
  3. Find every place where a is assigned. There is exactly one such line: a = b; inside the if (number[j] < number[m]) block.
  4. Find every place where b is assigned. There is exactly one such line: b = 10; at the top of the outer loop.
  5. Since a = b and b = 10, the value written into a is 10. The rest of the sort logic, the m variable, and the swap call do not affect a.
  6. Tap the yellow Enter field and type the digit 10. Tap the blue OK button. The level-complete pop-up appears with the line "Don't be tricked!" Tap Next to continue.
  7. The code on the screen assigns b equal to ten, and a is equal to b. Therefore a equals ten.

Strategy & Reasoning

The puzzle is a code-reading trick. The selection-sort body looks complex on purpose, with nested loops, an index variable m, and a swap call. A normal programmer would start tracing the array and tracking comparisons, but the question only asks about a. The shortest path is to follow the data flow backward from a to its only assignment.

Variable a is never initialized at declaration. It is only written in one place, inside the if. At that place, the right-hand side is b, and b is assigned 10 at the start of every outer iteration. So no matter how many times the if runs, a receives 10 each time. The rest of the algorithm is noise.

The congratulatory line "Don't be tricked!" is the game laughing at the people who tried to simulate the sort. The lesson is to read the specific variable being asked about rather than diving into the whole routine. Brain Out's code puzzles are almost always solved by tracing one variable to its literal value, not by executing the algorithm.

Tips & Common Mistakes

  • Trying to simulate the selection sort by hand. You do not need the array contents; only the assignment to a matters.
  • Entering 0 or null because a is uninitialized. The if block assigns a = b, so once the code runs, a holds 10.
  • Confusing b = 10 with a typo or a loop counter. b is a plain variable set to 10, and a copies it.

Popular Levels