0
0

Conditional Code

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

  1. Step 1: Identify each letter type

    N = consonant, A = vowel, M = consonant, E = vowel.
  2. 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
  3. Step 3: Combine transformed letters

    Result = MBLF.
  4. Final Answer:

    MBLF
  5. 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.

Practice

(1/5)
1. Rule: vowels → next letter (A→B, E→F, I→J, O→P, U→V). Consonants → previous letter (B→A, C→B, D→C, ...). How is the word 'GAME' written in this code?
easy
A. FBLF
B. HBLF
C. FCLF
D. FBLG

Solution

  1. Step 1: Identify each letter type

    G = consonant, A = vowel, M = consonant, E = vowel.
  2. Step 2: Apply the conditional rules

    • G (consonant) → previous letter = F
    • A (vowel) → next letter = B
    • M (consonant) → previous letter = L
    • E (vowel) → next letter = F
  3. Step 3: Combine transformed letters

    Result = FBLF.
  4. Final Answer:

    FBLF → Option A
  5. Quick Check:

    Reverse rules (F→G, B→A, L→M, F→E) recover GAME ✅
Hint: Classify each letter (vowel/consonant) first, then apply the respective shift.
Common Mistakes: Applying the wrong direction (e.g., shifting vowels backward or consonants forward).
2. Rule: For digits - odd digits add 1, even digits subtract 1. What is the code for the number 476?
easy
A. 385
B. 367
C. 3850
D. 387

Solution

  1. Step 1: Classify each digit

    4 = even, 7 = odd, 6 = even.
  2. Step 2: Apply the conditional rule

    • 4 (even) → 4 - 1 = 3
    • 7 (odd) → 7 + 1 = 8
    • 6 (even) → 6 - 1 = 5
  3. Step 3: Combine results

    Result = 385.
  4. Final Answer:

    385 → Option A
  5. Quick Check:

    Check examples: even→-1, odd→+1; mapping applied consistently ✅
Hint: Remember: odd → +1, even → -1; process digits independently left→right.
Common Mistakes: Forgetting to treat each digit independently or mishandling 0 (not present here).
3. Rule: letters in odd positions (1st, 3rd, ...) are shifted +2; letters in even positions (2nd, 4th, ...) are shifted -1. How is the word 'POWER' encoded?
easy
A. RNYDT
B. RNXDT
C. QNYDS
D. RMYDT

Solution

  1. Step 1: Number positions and list letters

    1:P, 2:O, 3:W, 4:E, 5:R.
  2. Step 2: Apply conditional shifts

    • Pos1 P → +2 → P→R
    • Pos2 O → -1 → O→N
    • Pos3 W → +2 → W→Y
    • Pos4 E → -1 → E→D
    • Pos5 R → +2 → R→T
  3. Step 3: Combine transformed letters

    Result = RNYDT.
  4. Final Answer:

    RNYDT → Option A
  5. Quick Check:

    Reverse: R→P (-2), N→O (+1), Y→W (-2), D→E (+1), T→R (-2) → recovers POWER ✅
Hint: Mark positions first (odd/even) - then apply +2 or -1 accordingly.
Common Mistakes: Shifting in the wrong direction for odd/even positions.
4. Rule: If a letter is a vowel, replace it with its position number (A=1, E=5, I=9, O=15, U=21). If a letter is a consonant, replace it with its next letter (B→C, C→D, Z→A). What is the code for 'BAT'?
medium
A. C1U
B. C1S
C. C1V
D. C2U

Solution

  1. Step 1: Classify each letter

    B = consonant, A = vowel, T = consonant.
  2. Step 2: Apply conditional rules

    • B (consonant) → next letter → C
    • A (vowel) → replace with position number → 1
    • T (consonant) → next letter → U
  3. Step 3: Combine results

    Result = C1U.
  4. Final Answer:

    C1U → Option A
  5. Quick Check:

    Consonants shifted +1 → B→C, T→U; vowel A→1 ✅
Hint: Vowels become numbers, consonants move forward by one letter.
Common Mistakes: Using previous letter for consonants instead of next.
5. Rule: If the word length is even → reverse the word; if odd → shift every letter +1. How is the word 'NOTE' encoded?
medium
A. OPUF
B. ETON
C. OPUE
D. ETNO

Solution

  1. Step 1: Check word length

    'NOTE' has 4 letters → even.
  2. Step 2: Apply the even-word rule

    Even → reverse the word. 'NOTE' reversed → ETON.
  3. Final Answer:

    ETON → Option B
  4. Quick Check:

    If the word were odd (e.g., 'NOT'), rule would shift letters: N→O, O→P, T→U → 'OPU' ✅
Hint: Determine word length first - even means reverse, odd means shift +1.
Common Mistakes: Applying the wrong rule for word length.

Mock Test

Ready for a challenge?

Take a 10-minute AI-powered test with 10 questions (Easy-Medium-Hard mix) and get instant SWOT analysis of your performance!

10 Questions
5 Minutes