Easy Tutorial
❮ Python Os Fchown Python Att List Min ❯

Python - Five Men and a Fish

Python3 Examples

A, B, C, D, and E went fishing together one night and were all exhausted by the early morning, so they each found a place to sleep.

When the sun was high, A woke up first and divided the fish into five portions, discarding one extra fish and taking his share.

B woke up next, also divided the fish into five portions, discarded one extra fish, and took his share.

C, D, and E woke up in turn and followed the same method to take their fish.

How many fish did they catch at least?

Example

def main():
    fish = 1
    while True:
        total, enough = fish, True
        for _ in range(5):
            if (total - 1) % 5 == 0:
                total = (total - 1) // 5 * 4
            else:
                enough = False
                break
        if enough:
            print(f'There are a total of {fish} fish')
            break
        fish += 1

if __name__ == '__main__':
    main()

Running Result:

There are a total of 3121 fish

Python3 Examples

❮ Python Os Fchown Python Att List Min ❯