0
0

Conditional Code

Introduction

Conditional Code प्रश्न उन नियमों के अनुसार अक्षरों (letters), अंकों (digits) या शब्दों को एन्कोड करते हैं जो किसी शर्त पर निर्भर करते हैं - उदाहरण के लिए: vowels बनाम consonants, odd बनाम even digits, positions (prime index) या word length।

यह पैटर्न महत्वपूर्ण है क्योंकि कई reasoning टेस्ट कठिनाई बढ़ाने के लिए conditional नियमों का उपयोग करते हैं: पहले आपको इनपुट को वर्गीकृत करना होगा (शर्त लागू करें) और फिर संबंधित transform लागू करना होगा।

Pattern: Conditional Code

Pattern

मुख्य विचार: एन्कोडिंग किसी शर्त पर निर्भर करती है - अलग-अलग sub-rules अलग-अलग वर्गों पर लागू होते हैं (उदा., vowels → next letter, consonants → previous letter; even digits → add 2, odd digits → subtract 1)।

हर बार जाँच करने के लिए आवश्यक बातें:

  • शर्त की पहचान करें: कौन-सी property इनपुट को समूहों में विभाजित करती है? (vowel/consonant, odd/even, prime/index, length ≤ 3, आदि)
  • हर branch को मैप करें: प्रत्येक समूह के लिए transform स्पष्ट रूप से लिखें (उदा., vowels: +1; consonants: -1)।
  • edge cases की जाँच करें: अक्षरों के किनारों (A/Z), अंकों 0/9, repeated characters, और capitalization प्रभावों के लिए।
  • order independence सत्यापित करें: पुष्टि करें कि नियम प्रत्येक character पर स्वतंत्र रूप से लागू होता है या पूरे शब्द/नंबर पर वर्गीकरण के बाद।
  • हमेशा inverse का परीक्षण करें: जहां संभव हो, ऑपरेशन को उलटने पर मूल इनपुट वापस मिलना चाहिए - यह correctness की जाँच में मदद करता है।

Step-by-Step Example

Question

एक विशेष कोड में: vowels को अगला अक्षर लिखा जाता है (A→B, E→F, I→J, O→P, U→V) और consonants को पिछले अक्षर के रूप में लिखा जाता है (B→A, C→B, D→C, …)। शब्द NAME किस रूप में लिखा जाएगा?

Solution

  1. स्टेप 1: प्रत्येक अक्षर का प्रकार पहचानें

    N = consonant, A = vowel, M = consonant, E = vowel.
  2. स्टेप 2: conditional नियम लागू करें

    • N (consonant) → previous letter = M
    • A (vowel) → next letter = B
    • M (consonant) → previous letter = L
    • E (vowel) → next letter = F
  3. स्टेप 3: परिवर्तित अक्षरों को मिलाएँ

    परिणाम = MBLF.
  4. अंतिम उत्तर:

    MBLF
  5. त्वरित जाँच:

    Reverse rules: M→N (prev→next), B→A (next→prev), L→M, F→E → मूल NAME पुनः प्राप्त होता है ✅

Quick Variations

1. vowels/consonant विभाजन अलग shifts के साथ (vowels +2, consonants -2)।

2. digit conditional: odd digits -1, even digits +2 (0/9 सीमाओं का ध्यान रखें)।

3. position-based: odd positions पर एक नियम, even positions पर दूसरा नियम।

4. word-length condition: छोटे शब्दों को reverse करें, लंबे शब्दों पर shift लागू करें।

5. mixed conditions: उदाहरण- prime positions पर vowels +1 अन्यथा -1।

Trick to Always Use

  • स्टेप 1: तुरंत प्रत्येक token को वर्गीकृत करें (vowel/consonant, odd/even, आदि)।
  • स्टेप 2: प्रत्येक वर्ग से एक example token पर transform लिखकर पुष्टि करें कि आपने नियम सही समझा।
  • स्टेप 3: transforms को लगातार लागू करें और फिर invert करके reverse-check करें।

Summary

Summary

  • Conditional codes अलग-अलग क्लासों (vowel vs consonant, odd vs even, position-based) पर अलग operations लागू करते हैं।
  • हमेशा शर्त की पहचान करें और आवेदन से पहले branch rules स्पष्ट रूप से लिखें।
  • बाउंडरी केसेज़ (A/Z, 0/9) का ध्यान रखें और सत्यापन के लिए reversibility टेस्ट करें।

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