Introduction
Conditional Code problems change how characters (letters, digits, words) are encoded based on a rule that depends on a condition - for example: vowels vs consonants, odd vs even digits, positions (prime index) or word length.
This pattern is important because many reasoning tests use conditional rules to increase difficulty: you must first classify the input (apply the condition) and then apply the corresponding transform.
Pattern: Conditional Code
Pattern
The key concept is: the encoding depends on a condition - different sub-rules apply to different classes (e.g., vowels → next letter, consonants → previous letter; even digits → add 2, odd digits → subtract 1).
Essentials to check every time:
- Identify the condition: what property splits inputs into two or more groups? (vowel/consonant, odd/even, prime/index, length ≤3, etc.)
- Map each branch: write the transform for each group explicitly (e.g., vowels: +1; consonants: -1).
- Check examples for edge cases: letters at ends (A/Z), digits 0/9, repeated characters, and capitalization effects.
- Verify order independence: confirm whether the rule applies to each character independently or to the whole word/number after classification.
- Always test inverse: reversing the operation (where possible) should recover the original input - this helps confirm correctness.
Step-by-Step Example
Question
In a certain code: vowels are written as the next letter (A→B, E→F, I→J, O→P, U→V) and consonants are written as the previous letter (B→A, C→B, D→C, ...). How is the word NAME written?
Solution
-
Step 1: Identify each letter type
N = consonant, A = vowel, M = consonant, E = vowel. -
Step 2: Apply the conditional rules
- N (consonant) → previous letter = M
- A (vowel) → next letter = B
- M (consonant) → previous letter = L
- E (vowel) → next letter = F
-
Step 3: Combine transformed letters
Result = MBLF. -
Final Answer:
MBLF -
Quick Check:
Reverse rules: M→N (prev→next), B→A (next→prev), L→M, F→E → recovers NAME ✅
Quick Variations
1. Vowel/consonant split with different shifts (vowels +2, consonants -2).
2. Digit conditional: odd digits -1, even digits +2 (watch 0/9 boundaries).
3. Position-based: letters in odd positions apply rule A, even positions rule B.
4. Word-length condition: short words reverse order, long words shift letters.
5. Mixed conditions: e.g., vowels in prime positions use +1, otherwise -1.
Trick to Always Use
- Step 1: Immediately classify each token (vowel/consonant, odd/even, etc.).
- Step 2: Write the transform for one example token from each class to ensure you understood the rule.
- Step 3: Apply transforms consistently and then reverse-check by inverting the operations.
Summary
Summary
- Conditional codes apply different operations to different classes (vowel vs consonant, odd vs even, position-based).
- Always identify the condition and list branch rules explicitly before transforming inputs.
- Watch for boundary cases (A/Z, 0/9) and test reversibility as a final verification step.
