• Discover How To Break Out From Nested Loops And Find Captain's Share Of Gold

Hello, checkiomates🐱‍👤!

Read a short lifehack article about breaking nested loops and try to divide gold among pirates and their captain withot blood (this time).

💡TIP

We allow users to assign hotkeys to "Run Code", "Check Solution" and stop code. You may see current combinations on buttons and change them in editor menu. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!

🏁MISSION

Divide Gold by freeman_lex -

Captain Red Eye and his sailors found a chest containing a large number of identical gold coins. To divide up the coins, everyone agreed to the Captain's suggestion: each sailor except the Captain should receive exactly the same number of coins; the captain should receive twice as many coins as a sailor. Given the number of coins in the chest and the number of sailors, write a program to determine how many coins Captain Red Eye received.

captain_share(15, 1) == 10
captain_share(28, 2) == 14
captain_share(54, 4) == 18

📖ARTICLE

Breaking out of nested loops with generators -

Have you ever had the situation where you’ve got a nested loop and need to break out of the outer one? You can use generators to simplify nested loops and make it easier to break out of them. This post shows you how.

👩‍💻CODE SHOT

How do you think, what the following code does?

def ??????????(s):
    return sum(s.count(x) * y for x, y in
               (('I', 1), ('V', 5), ('X', 10), ('L', 50), ('C', 100), ('D', 500), ('M', 1000),
                ('IV', -2), ('IX', -2), ('XL', -20), ('XC', -20), ('CD', -200), ('CM', -200)))

🙌 Thanks for your attention! Hope to meet you at CheckiO, as well as at our Instagram and Twitter! We are really interested in your thoughts! Please, leave a comment below! ⤵

Welcome to CheckiO - games for coders where you can improve your codings skills.

The main idea behind these games is to give you the opportunity to learn by exchanging experience with the rest of the community. Every day we are trying to find interesting solutions for you to help you become a better coder.

Join the Game