Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:23:20+00:00 2026-06-04T11:23:20+00:00

I am attempting to generate a potential card ‘plays’ list from a predetermined hand

  • 0

I am attempting to generate a potential card ‘plays’ list from a predetermined hand of straights (in this game a straight is defined as 3+ cards – e.g. [3,4,5]). The difficlty lies in finding a way to take a list of identified straights (which may include multiple unconnected straights – ['2D','3D','4D','5D','6D','8D','9D','10D']) and appending them and their sub-straights contained within them to a plays list(for the given hand the output would ideally be [['2D','3D','4D'],['3D','4D','5D'],['4D','5D','6D'],['2D','3D','4D','5D'],['3D','4D','5D','6D'],['8D','9D','10D']])

Below is the current attempt being made;

seq = ['1D','2D','3D','4D', '6D', '7D','8D', '10D', '11D', '12D']
plays = []
for card in seq:
    ind = seq.index(card)+1
    try:
        if int(seq[ind][0:len(seq[ind])-1]) - int(card[0:len(card)-1]) == 2:
            for num in xrange(len(seq[0:ind])):
                if len(seq[0:(ind-num)]) > 3:
                    plays.append(seq[0:(ind-num)])
                    plays.append(seq[num+1:ind])
                elif len(seq[0:(ind-num)]) == 3:
                    plays.append(seq[0:(ind-num)])
            print plays #debug
except IndexError:
    print 'error'
    #append from the last appended chunk up until last element?
    #arises from final element

[[‘1D’, ‘2D’, ‘3D’, ‘4D’], [‘2D’, ‘3D’, ‘4D’], [‘1D’, ‘2D’, ‘3D’]]

[[‘1D’, ‘2D’, ‘3D’, ‘4D’], [‘2D’, ‘3D’, ‘4D’], [‘1D’, ‘2D’, ‘3D’], [‘1D’, ‘2D’, ‘3D’, ‘4D’, ‘6D’, ‘7D’, ‘8D’], [‘2D’, ‘3D’, ‘4D’, ‘6D’, ‘7D’, ‘8D’], [‘1D’, ‘2D’, ‘3D’, ‘4D’, ‘6D’, ‘7D’], [‘3D’, ‘4D’, ‘6D’, ‘7D’, ‘8D’], [‘1D’, ‘2D’, ‘3D’, ‘4D’, ‘6D’], [‘4D’, ‘6D’, ‘7D’, ‘8D’]**, [‘1D’, ‘2D’, ‘3D’, ‘4D‘], [‘6D’, ‘7D’, ‘8D’], [‘1D’, ‘2D’, ‘3D’]]

error

The ouput in bold indicates unwanted elements (duplicates or conjunction of separate straights).
Thanks for the input!

edit 1: added lines 10-12

edit 2: added solution provided by @Steve Tjoa

(Given that cards is a series of ints)
cards = [1, 2, 3, 4, 6, 7, 8, 10, 11, 12]

def f(cards):
    for i in range(len(cards)):
        for j in range(i+3, len(cards)+1):
            if cards[i:j] == range(cards[i], cards[i]+j-i):
                plays.append(cards[i:j])
            print plays
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:23:21+00:00Added an answer on June 4, 2026 at 11:23 am

    Does this help?

    In [34]: def f(cards):
       ....:     return [cards[i:j]
       ....:             for i in range(len(cards))
       ....:             for j in range(i+3, len(cards)+1)
       ....:             if cards[i:j] == range(cards[i], cards[i]+j-i)]
       ....: 
    
    In [35]: f([1, 2, 3, 4, 6, 7, 8, 10, 11, 12])
    Out[35]: [[1, 2, 3], [1, 2, 3, 4], [2, 3, 4], [6, 7, 8], [10, 11, 12]]
    
    In [36]: f([2, 3, 4, 5, 6, 8, 9, 10])
    Out[36]: 
    [[2, 3, 4],
     [2, 3, 4, 5],
     [2, 3, 4, 5, 6],
     [3, 4, 5],
     [3, 4, 5, 6],
     [4, 5, 6],
     [8, 9, 10]]
    

    Reasoning: cards[i] is the first card of the straight; cards[j-1] is the last card. range returns consecutive integers. j-i is the length of the straight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to generate datamatrix barcodes from within itext. This works fine for
I am attempting to generate a list (from four tables) of products, classid, optionid,
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to generate the body of an email in Outlook 2007 from
I'm attempting to generate a grid of divs five elements wide from the objects
I am attempting to generate an ADO RecordSet programmatically within .Net. This will be
While attempting to generate a list of subsets that exist within two sets, I
I'm attempting to use svcutil.exe to generate -only- the service contracts (interfaces) from a
I am attempting to grab a date supplied via POST, then generate a list
I am attempting to generate a BitmapFrame that is based on a UIElement .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.