Counting in Python using a list

0 min read 148 words

So before we begin, let me just tell you that this is a pretty useless thing to do.. But I was playing around with it while waiting for a C++ project to finish compiling, so why not!

The code (click here for the Gist):

magic = 0x616f-0x414f

numbers = [
    (magic/0x186A0),
    (magic/0x3E8/8),
    (magic/0x3E8/4),
    (magic/0o1534-7),
    (magic/0x3E8/2),
    (magic/0o2534-1),
    (magic/0o2544),
    (magic/0o075/19),
    (magic/0o064/19),
    (magic/0o1654)
]

i = c = numbers[0]

while True:
    print('%d%d' % (c, round(numbers[int(i)])))
    i += 1
    if i>len(numbers)-1:
        i = 0
        c += 1

If you ran it, it would look like this!

The numbers list in the code above is just an obfuscated way of writing 0..9.

The only real logic in this is the body of the while loop which prepends a zero each time it hits the end of the range.

This demonstrates the ability to count and not rely on the decimal system for example.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags