Skip to content
Codewilds

Lesson 12 of 34 · Methods

Boss: The Echoing Hydra

Boss battlehard100 XP2 min read

The Echoing Hydra blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.

Deep in the flooded vaults beneath the Citadel lurks the Echoing Hydra. Its heads repeat every spell cast at them, and when one is struck down, its echo returns. Only a precise warrior — one who has mastered methods — can break its rhythm. Every method you complete silences one of its heads.

Battle plan

This fight combines every tool from Chapter 2: recursive methods, overloads, optional and named parameters, and out parameters.

  • The Hydra's heads attack in synchronised waves. The greatest common divisor of their rhythms tells you when they all strike together. Euclid found the recursive rule 2,300 years ago: gcd(a, 0) = a and gcd(a, b) = gcd(b, a % b).
  • Each head follows the Collatz pattern: if its strength n is even it halves, if it is odd it becomes 3n + 1. Every head eventually reaches 1 — count how many steps it takes.
  • Strike orders arrive as text like "neck:25" — a target and a damage value separated by a colon.

Assignment

Complete the methods in Program:

  1. Gcd(a, b) returns the greatest common divisor of two non-negative numbers, recursively: Gcd(12, 18) is 6, Gcd(17, 5) is 1 and Gcd(0, 9) is 9.
  2. An overload Gcd(a, b, c) returns the GCD of three numbers by reusing the first one: Gcd(24, 36, 60) is 12.
  3. CollatzSteps(n) returns the number of steps until n (≥ 1) reaches 1, recursively: CollatzSteps(1) is 0, CollatzSteps(6) is 8.
  4. Damage(baseDamage, combo = 1, critical = false) returns baseDamage * combo, doubled when critical is true: Damage(10) is 10, Damage(10, combo: 3) is 30, Damage(10, critical: true) is 20.
  5. TryParseStrike(text, out target, out damage) parses "neck:25" into target = "neck" and damage = 25 and returns true. Text without a colon, with an empty target or with a damage that is not a positive whole number returns false with target = "" and damage = 0.
  6. FormatHeads(count) returns "1 head" for one and "<count> heads" otherwise ("0 heads", "9 heads").

Premium lesson

Unlock the full Learn C# course

  • All 34 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 8 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.

Keep learning

Need a quick reminder? The C# cheat sheet has every topic of Learn C# on one page.

Lesson last updated on .

Write code ↓
C#+100 XP

Lesson 12 is part of the full course. The first 8 lessons are free.

Premium lesson

Unlock the full Learn C# course

  • All 34 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 8 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.