-3

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)

Mohammed
  • 9
  • 4
  • 5
    Your question is much too broad and you're overcomplicating it. A base 13 numbering system won't help you at all. Internally, everything is binary anyway. – Mad Physicist Mar 09 '20 at 19:01
  • 1
    You can create base anything. Take for example `910` in `base10`, this is really just `9*10**2 + 1*10**1 + 0*10**0` If you encountered `910` in `base13`, you just swap the 10s for 13 like so `9*13**2 + 1*13**1 + 0*13**0`. This is the same way that hex can be calculated, i.e. `0xFF == 15*16**1 + 15*16**0`. – Chrispresso Mar 09 '20 at 19:07
  • 1
    I think you're overcomplicating it. Here's a simple solution in Python3. You need to create the global set `flush={frozenset("A23456789JQK"[i:i+5]) for i in range(8)}`, and then you can a list (or string) of five cards with something like: `frozenset('8J97Q') in flush` – rici Mar 09 '20 at 20:40
  • @MadPhysicist Definite example of https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – btilly Mar 09 '20 at 20:47

1 Answers1

1

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

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I like your function, is there a way to implement it directly in the main() function without the need to call external function? – Mohammed Mar 09 '20 at 19:36