• "The Best Number Ever" Review

Hi, CiO friends!

In an earlier article, I talked about the creative writing mission "I love Python". Today I will be looking into another creative writing mission: "The best number ever".

The mission is simple. Write a function that returns any number. But try to describe why your number is the best. For example, Sheldon Cooper from The Big Bang Theory thinks that 73 is the best number ever and he can explain why.

Let's look at what CheckiO players say about their favorite numbers.

And @Amachua opens our article this week with his "Dictionary" solution. He collected an interesting set of names and people, but this solution is still far from completion. So propose your new ideas to the author in the comments and maybe later we will see "The complete Dictionary of the best numbers" by @Amachua.

The next solution, written by @Faibbus, will introduce us to The Most Amazing, Ancient, and Singular Number Wau.

def checkio( *data):
    from math import sqrt, cos, pi
    from random import randrange, seed
    seed("Wau is the best number ever !")
    Wau = 42. / ord('*')  # divide 42 by anything...
    assert Wau == int(Wau), "Your number isn't an integer"
    for i in xrange(1337):
        assert Wau == (Wau**i+Wau)/(sqrt(Wau)-cos(pi*Wau**i)) , "Your number isn't great enough... (%i)"%i
    for i in xrange(13**2):
        assert not (randrange(1337**42)-int(pi**i))%Wau , "Your number lacks randomness... (%i)"%i
    gold_ratio = (sqrt(5) - 1)/2
    for i in xrange(0xB4B3):
        n = Wau /(Wau + n)
    assert abs(n - gold_ratio) < 1e-6 , "Your number doesn't prettify anything... (%f) (%f) (%f)"%(n-gold_ratio, n, gold_ratio)
    But wait, there's even more,
        Wau: The Most Amazing, Ancient, and Singular Number
        see https://www.youtube.com/watch?v=GFLkou8NvJo
    return int(Wau)

@grigoriytretyakov's written an essay with variable names to prove "16 is the best number ever".

def checkio():
    i = 16
    in_hex_has_only_1_and_0 = not bool(set(hex(i)[2:]) - set('01'))
    oct_twice_bigger_than_hex_in_10_radix = int(oct(i)[2:]) / int(hex(i)[2:]) == 2.0
    convert_to_hex_to_str_give_two_in_bin = int(hex(i)[2:], 2)
    count_of_0_in_4_times = bin(i)[2:].count('0') / hex(i)[2:].count('0')
    and_2_in_power_4_give_stil_16 = 2 ** count_of_0_in_4_times
    best_number = (
        in_hex_has_only_1_and_0 and
        oct_twice_bigger_than_hex_in_10_radix and
        convert_to_hex_to_str_give_two_in_bin and
        count_of_0_in_4_times == 4 and
        and_2_in_power_4_give_stil_16 == 16
    if best_number:
        return i

If you're looking for a nice story to read to the kids, then you can take on @Juge_Ti's "Secret Magic Number" short novel. I don't want to spoil it for you, so you'll need to run the code if you want to know the secret number.

@HonzaKral proved Sheldon's version "Inspired by BrainF**k"

OPS = {
    '0': lambda _: 0,
    '+': lambda buf: buf + 1,
    '<': lambda buf: buf * 10
def bf(it):
    buf = None
    for i in it:
        buf = OPS[i](buf)
    return buf
def checkio():
    'And the best number ever is...'
    return bf("0+++++++<+++")

And for dessert, this funny solution comes from @StefanPochmann "I'm sure you'll agree".

checkio=lambda:int('https://www.youtube.com/watch?v=dQw4w9WgXcQ'.split('=')[1], 36)

That's all folks. Tell us about your best numbers in the comments.

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