Search code examples
pythonalgorithmencryptioninterpretation

Is there a way to create base13 numbering system in python?


So long story short, I want to make a program that identifies the 13 playing cards in a set and report back if they are a straight flush "from poker". my approach is to create a base13 numbering system and then convert the entered cards to their equivalent decimal values so I will be able to do calculations on them to determine if they satisfy the criteria.

Is there a famous algorithm or methods for such operation? do you think my approach is sound or am I over-complicating it? (consider that I cant't control the format I am receiving the cards data in)


Solution

  • sure, bases are pretty trivial

    alphabet = "A23456789TJQK"
    
    def convert_to_base_13(x):
        q,r = divmod(x,13)
        if q == 0:
           return alphabet[r]
        return convert_to_base_13(q) + alphabet[r] 
    

    now you can represent 146 in base 13 as "Q4"

    Im not really sure how that helps with your cardgame though