• Mutable and Immutable Types, De-duplicating and Beautifying a List and playing Puzzles

Hello, checkiomates🐱‍👤!

Did you know, that If you find an iteresting solution, you may add it to your bookmarks by clicking the flag near solutiuon title. You can find all your bookmarked solution by clicking your nickame and than "Bookmarks"! If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!

This week CheckiO team prepared for you three new missions. Two of which are about such games as chess and 15-puzzle and the third one is dedicated to list view beautifying. We hope, you'll enjoy them a lot! 🎉 So, here they are:


Peaceable Queens by freeman_lex - You are given a chessboard of custom dimension: size * size. Your goal is to put there as many ♕ and ♛ as possible with these rules of placement: only equal numbers of Queens are allowed; ♕ must not attack ♛ and visa verse (but they may be under "attack" of the same color Queens). Your function should return the maximum number of opposite Queens pairs, you could put on the given chessboard according to the restrictions.

peaceable_queens(2) == 0
peaceable_queens(3) == 1
peaceable_queens(4) == 2

15-puzzle Solvability by freeman_lex - 15-puzzle is a quite old and famous puzzle, which had its own peak of interest! In this mission you are given a position of tiles - a list of 4 lists of equal length with all integers from 1 to 16 incl. in arbitrary order (but number 16 always stands for empty place!). Your function should return a boolean value, if this combination of tiles is solvable (may be transformed by valid moves to "normal" order) or not, as True or False respectively.

fifteen_puzzle([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == True
fifteen_puzzle([[15, 14, 13, 12], [11, 10, 9, 8], [7, 6, 5, 4], [3, 2, 1, 16]]) == False
fifteen_puzzle([[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]]) == True

List Beautify by freeman_lex - Let's assume, you are given a list of lists of positive/negative integer/float numbers, for example - [[1, 2, 10, 150], [10, 2, 1000, 2], [1, 120, 1, 1000]]. It's always correctly filled: has at least one non-empty inner list. Your function should return improved printing view: a single string (multiline if more than one inner list), where numbers in columns should be right-aligned. There must be exactly one whitespace between the longest number in a column incl. minus (if present) and the previous comma in a row. All rows of the same length, wrapped together in the list brackets.

list_beautify([[1, 2, 10, 150], [10, 2, 1000, 2], [1, 120, 1, 1000]]) == "[[ 1,   2,   10,  150],\n [10,   2, 1000,    2],\n [ 1, 120,    1, 1000]]"
list_beautify([[1, 10, 100, -1000]]) == "[[1, 10, 100, -1000]]"
list_beautify([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == "[[1, 1, 1, 1, 1],\n [1, 1, 1, 1, 1],\n [1, 1, 1, 1, 1]]"

We have also found some articles, which we consider interesting. They are about mutable and immutable data types, removing duplicates from a list and Python Julia interoperability.


Julia and Python better together - Have you heard about Julia programming language? Many data scientists like Julia, but there are some functionalities in Python that they like and would want to keep using. But from Julia you have all Julia and all Python packages available to use in your projects! This article provides you with exact recipes to do it.

Python's Mutable vs Immutable Types: What's the Difference? - As a Python developer, you’ll have to deal with mutable and immutable objects sooner or later. Mutable objects are those that allow you to change their value or data in place without affecting the object’s identity. In contrast, immutable objects don’t allow this kind of operation. You’ll just have the option of creating new objects of the same type with different values. In Python, mutability is a characteristic that may profoundly influence your decision when choosing which data type to use in solving a given programming problem. Therefore, you need to know how mutable and immutable objects work in Python.

How to de-duplicate a list in Python - Need to de-duplicate a list of items? This article gives you two approach for de-duplicating: one when we don't care about the order of our items and one when we do. And don't use new list + for loop...

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! ⤵

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