Samurai Code Formatter

Par 5
Question 53intermediateSheet 1750822302

Deep Breath

A martial arts philosopher converted code formatting to follow Bushido principles. They committed seppuku after finding a memory leak, leaving behind perfectly indented code and a haiku about proper variable naming. Format code according to the way of the warrior with honor-based style guidelines. Proper spacing shows respect, consistent indentation shows discipline. Your task: Format code like a samurai—honor intact, linter satisfied, and every else handled with the grace of a death poem.

Why You're Doing This

This tests code style enforcement, pattern matching, and systematic text transformation. You're building a formatter that applies consistent rules—essential for any system that processes and standardizes input according to predefined patterns.

Take the W

  • Applies consistent indentation rules
  • Adds proper spacing around operators and braces
  • Returns honor rating based on formatting discipline

Hard L

  • Corrupts code syntax while formatting
  • Produces inconsistent indentation levels
  • Fails to handle edge cases gracefully

Edge Cases

  • Code with existing perfect formatting
  • Nested structures requiring complex indentation
  • Mixed tabs and spaces in original code
  • Code with syntax errors
Input Format:
Raw code string requiring samurai formatting treatment
Expected Output:
Structured object with formatted code and honor metrics
Example:
if(x>0){return true;}else{return false;} → {"formatted": "if (x > 0) {\\n    return true;\\n} else {\\n    return false;\\n}", "honor_rating": "respectful"}
Hints
  • 💡 Proper spacing shows respect, consistent indentation shows discipline
  • 💡 Honor ratings: shameful, acceptable, respectful, honorable, legendary
  • 💡 Think of code formatting as a martial art requiring precision