
Python 3.12 Release, Advices from Guru and Integer Close Enough to be Perfect Power
Hello, checkiomates🐱👤!
First of all, the newest major release of the Python programming language  3.12  was released on Oct. 2 and it contains many new features and optimizations!
Did you know, that on Easy difficulty, each of the few starting stations is dedicated to a dictinct data type. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
🏁 MISSIONS:
In today's missions you need to flip a lot of ⌛ to count exact amount of ⌚, check integer for being perfect 👌 and play with the Fundamental Theorem of Arithmetic!
Flip of Time by freeman_lex  An hourglass is given as a tuple (upper, lower) for the number of minutes of sand that are currently stored in its upper and lower chambers, both chambers large enough to hold all of the sand in that hourglass.
Given a list of glasses, your task is to find an optimal sequence of moves to measure exactly t minutes, scored as the number of individual hourglass flips performed along the way. Each move consists of two stages: you must first wait for the hourglass that currently holds the lowest non zero amount m of sand in its upper chamber to run out. when that happens, choose any subset of glasses and instantaneously flip this chosen subset.
hourglass_flips([(7, 0), (11, 0)], 15) == 2 hourglass_flips([(4, 0), (6, 0)], 11) == None hourglass_flips([(7, 1), (10, 4), (13, 1), (18, 4)], 28) == 3
Checking Perfect Power by freeman_lex  A positive integer n is a perfect power if it can be expressed as the power be for some two integers b and e that are both greater than one. (Any positive integer n can always be expressed as the trivial power n1, so we don’t care about those.) For example, the integers 32, 125 and 441 are perfect powers since they equal 2^{5}, 5^{3} and 21^{2}, respectively.
This function should determine whether the positive integer n is a perfect power.
perfect_power(42) == False perfect_power(441) == True perfect_power(469097433) == True
Close Enough by freeman_lex  Except when the prime factors of a, b already cooperate, the iron hand of the Fundamental Theorem of Arithmetic dictates that the integer powers a^{pa} and b^{pb} can never be equal for any two positive integer exponents pa and pb. However, in the jovial spirit of “close enough for government work”, we define two such powers to “hit” if their difference abs(a^{pa}b^{pb}) multiplied by the tolerance is at most equal to the smaller of those powers. (This definition intentionally avoids division to keep it both fast and accurate for arbitrarily large integers.) For example, tolerance=100 expects a^{pa} and b^{pb} to be within 1 %.
For given positive integers a, b return the smallest positive integer exponents (pa, pb) that satisfy the tolerance requirement.
list(hitting_powers(2, 4, 100)) == [2, 1] list(hitting_powers(2, 7, 100)) == [73, 26] list(hitting_powers(3, 6, 100)) == [137, 84]
💡ARTICLES:
Advices for beginners from Ned Batchelder's, new features in Puthon 3.12 and advantages from wrapping your code into functions!
Advice to beginners  Ned Batchelder's tips about how to learn technology in general.
Python 3.12: Cool New Features for You to Try  As usual, the new version comes out in October after lots of effort by volunteers worldwide. In this tutorial, you’ll learn about new features and improvements, like: Better error messages with helpful suggestions and guidance More expressive fstrings that are backed by Python’s PEG parser Optimizations, including inlined comprehensions, for a faster Python A new syntax for type variables that you use to annotate generics Support for the powerful perf profiler on Linux
Why does Python Code Run Faster in a Function?  Python is not necessarily known for its speed, but there are certain things that can help you squeeze out a bit more performance from your code. Surprisingly, one of these practices is running code in a function rather than in the global scope. In this article, we'll see why Python code runs faster in a function and how Python code execution works.
Don't forget to comment your code!😈
🙌 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