Sailing the Seven Seas (Python Challenge)

Long before radios and GPS, sailors relied on teamwork, experience and a good rhythm to keep a ship moving. One tradition that became famous around the world was the sea shanty. These songs were sung by crews as they hoisted sails, pulled ropes and weighed anchor, helping everyone work together in time. Many sea shanties also told stories of dangerous storms, distant lands and exciting adventures across the oceans.

Legend tells of a fearless pirate captain who sailed far beyond the known world. Wherever he travelled, his crew could be heard singing their favourite sea shanty, “Sailing the Seven Seas.” The song became so well known that sailors claimed they could recognise the pirate’s ship long before it appeared on the horizon!

According to the legend, when the pirate’s treasure was finally discovered, two mysterious pieces of parchment were found inside the treasure chest. The first parchment contained the lyrics to Sailing the Seven Seas… or so it seemed. Instead of words, it was filled with strange numbers. The second parchment contained a table matching each number to a word or short phrase.

At first, historians thought the pirate had created a secret code to stop rival pirates from stealing his famous song. However, computer scientists looking at the parchments noticed something interesting. Many words and phrases in the shanty were repeated over and over again, such as “Heave ho!”, “Raise the sail!” and “We are sailing the seven seas!”. Rather than writing these long phrases every time, the pirate had simply replaced them with short numbers and kept a lookup table on the second parchment.

Today, computers use a very similar idea when compressing data. Instead of storing the same information repeatedly, common words, patterns or sequences can be stored once and replaced with shorter references. Because the original text can be reconstructed perfectly using the lookup table, this is known as lossless compression.

In this challenge, you’ll become the pirate’s programmer! Your task is to complete the Python code provided to you by writing a function that uses a hash table (dictionary) to replace each number with its corresponding word or phrase, reconstructing the original lyrics to Sailing the Seven Seas. Can you successfully decode the pirate’s legendary sea shanty?

Python Code

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!