Post image
Playing with Morse Code, Dice and Knapsack in Hexagonal Grid

Hello, checkiomates🐱‍👤!

Did you know, that at every mission page, under the editor window, there is a terminal window.. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!

🏁 MISSIONS:

As seen from the title, today's missions are about counting number of variants to decode Morse code in a specific way, optimal knapsack packing and the final position of a dice after rolling. Meet them below:

Count Morse by freeman_lex - When Python introduced the match statement, many people were confused and thought of it strictly as a switch statement. Instead of just showing you lots of working correct examples, I’m going to show you a few mistakes first so you can be familiar with errors you could see.

assert count_morse("-------.", "omg") == 2
assert count_morse(".....-.-----", "morse") == 4
assert count_morse("-..----.......-..-.", "xtmisuf") == 4

Knapsack Problem by freeman_lex - You are given a list of kinds of items items, that you want to put into knapsack. Item of each kind is a tuple of its value, weight and maximum amount (optional). You need to find a subset of items, such that: the total value of the items in subset is as large as possible; the total weight of items in subset is at most weight, that is capacity of the knapsack; for each kind of items you can select at most given amount items. If its not given - there is no restriction for amount.

assert knapsack(5, [(4, 2, 1), (5, 2, 1), (2, 1, 1), (8, 3, 1)]) == 13
assert knapsack(8, [(4, 2), (5, 2), (2, 1), (8, 3)]) == 21
assert knapsack(8, [(10, 10, 3)]) == 0
assert knapsack(8, [(4, 3, 2), (2, 1, 1), (1, 2, 4), (3, 2, 2)]) == 12

Rolling 🎲! by freeman_lex - There is a standard 6-sided 🎲, which looks and placed as shown below. It may be rolled in four cardinal directions: North, South, West, East. For the mission you are given a string moves with directions. You need to find out, what side of 🎲 is on top after rolling.

assert rolling_dice("SN") == 1
assert rolling_dice("") == 1
assert rolling_dice("EESWN") == 6
assert rolling_dice("NWSNWEESNW") == 3

💡ARTICLES:

Look, what we have prepared for you to read! A usefull tutorial about hexagonal grid properties, fast and searchable Python (and other languages) documentation and match statement explanation.

Hexagonal Grids - At CheckiO you will find missions, that demand knowing of prorerties of hexagonal grid. This is a very usefull database, which covers various ways to make hexagonal grids, the relationships between different approaches, and common formulas and algorithms.

Database of programming languages documentations - DevDocs combines documentations of different programming languages in one place in a fast, organized, and searchable interface.

A Gentle Introduction to the Python Match Statement - When Python introduced the match statement, many people were confused and thought of it strictly as a switch statement. In this article the author shows a few mistakes first so you can be familiar with errors you could see.

A bit of humor!

🙌 Thanks for your attention! Hope to meet you at CheckiO. We are really interested in your thoughts! Please, leave a comment below! ⤵

Created: May 2, 2023, 6:28 a.m.
2
40
User avatar
freeman_lex