# Daily Challenge - Character Battle (Advice

**URL:** <https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870>\
**Category:** I Built This\
**Created:** [August 24, 2025, 8:34pm UTC](https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870 "2025-08-24T20:34:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![altuser91](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/altuser91/32/379328_2.png) [@altuser91](https://forum.freecodecamp.org/u/altuser91)\
**Post date:** [August 24, 2025, 8:34pm UTC](https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870/1 "2025-08-24T20:34:32Z")

</div>

Instead of writing bad code that works, I’ve been trying to write more readable code. However sometimes is it not necessary or doing ‘too much’? Additionally how do programmers read the problem and create an efficient solution without simply spamming for loops?

```auto
import string

def battle(my_army, opposing_army) -> str:
    if len(my_army) != len(opposing_army):
        return retreat(my_army, opposing_army)

    win_count = 0
    my_list = list(map(strength, my_army))
    opposing_list = list(map(strength, opposing_army))

    battle_result = list(map(lambda x, y: x-y, my_list, opposing_list))

    win_count += sum((result > 0) - (result < 0) for result in battle_result)

    if win_count > 0:
        return "We won"
    elif win_count < 0:
        return "We lost"
    else:
        return "It was a tie"

def strength(char: str) -> int:
    ALPHABET: str = "$" + string.ascii_letters
    DIGITS: str = string.digits

    if char in ALPHABET:
        return ALPHABET.index(char)
    elif char in DIGITS:
        return DIGITS.index(char)
    else:
         return 0

def retreat(my_string: str, opposing_string: str) -> str:
    len_my_string = len(my_string)
    len_opposing_string = len(opposing_string)

    if len_my_string > len_opposing_string:
        return "Opponent retreated"
    elif len_my_string < len_opposing_string:
        return "We retreated"

print(battle("Hello", "World"))

```

---

<div class="post-metadata">

**Author:** ![nickrg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nickrg/32/401390_2.png) [@nickrg](https://forum.freecodecamp.org/u/nickrg)\
**Post date:** [August 25, 2025, 12:29pm UTC](https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870/2 "2025-08-25T12:29:13Z")

</div>

I mean, this is a pretty wide question. It’s a coder’s lifelong mission to get better and better at elegant, readable solutions to problems. Nothing can replace practice, of course. Just keep doing exactly what you’re doing: solving the problems as efficiently and elegantly as you can at your current skill level and you’ll get better faster than you realize!

Happy coding!

---

<div class="post-metadata">

**Author:** ![archana115](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@archana115](https://forum.freecodecamp.org/u/archana115)\
**Post date:** [September 20, 2025, 1:35am UTC](https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870/3 "2025-09-20T01:35:35Z")

</div>

> [@altuser91](#):
>
> Instead of writing bad code that works, I’ve been trying to write more readable code. However sometimes is it not necessary or doing ‘too much’? Additionally how do programmers read the problem and create an efficient solution without simply spamming for loops?

Writing readable, maintainable code is almost always worth it — because you’re not just coding for the computer, you’re coding for the future you (and your teammates). Sometimes, yes, you can over-engineer or abstract too much, but in practice beginners lean more toward _not enough structure_ rather than _too much_. So it’s a good instinct to aim for clarity. A simple rule: if a future reader can understand what your code is doing in one pass without mental gymnastics, you’re in a good place.

“Too much” is usually when your solution introduces layers of abstraction, helper functions, or patterns that don’t actually make the problem easier to solve or the code easier to read. For example, making five helper functions for a tiny three-line algorithm might be overkill. On the other hand, pulling repeated logic into a helper is usually a win.

---

<div class="post-metadata">

**Author:** ![Naomi](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/naomi/32/422181_2.png) [@Naomi](https://forum.freecodecamp.org/u/Naomi)\
**Post date:** [January 13, 2026, 7:01pm UTC](https://forum.freecodecamp.org/t/daily-challenge-character-battle-advice/759870/4 "2026-01-13T19:01:13Z")

</div>

Closed on January 13, 2026, 7:01pm UTC


