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 7706073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:01:31+00:00 2026-06-01T00:01:31+00:00

I am creating a poker system and I am currently streamlining my hand calculator.

  • 0

I am creating a poker system and I am currently streamlining my hand calculator.

The following code works:

public enum CARDS
{
    None = 0,
    Two,
    Three,
    Four,
    Five,
    Six,
    Seven,
    Eight,
    Nine,
    Ten,
    Jack,
    Queen,
    King,
    Ace
};

public enum SUITS
{
    None = 0,
    Diamonds,
    Clubs,
    Hearts,
    Spades
};

public class Card
{
    public CARDS Val { get; set; }
    public SUITS Suit { get; set; }
}

public class IntIndex
{
    public int Count { get; set; }
    public int Index { get; set; }
}

static void Test()
{
    List<Card> cardList = new List<Card>();
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Two });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Four });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Five });
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Spades, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Seven });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Eight });

    // I have a processor that iterates through the above card list and creates
    // the following array based on the Card.Val as an index
    int[] list = new int[] {0,0,0,1,1,2,1,1,0,0,1,0,0,0};
    List<IntIndex> indexList =
        list.Select((item, index) => new IntIndex { Count = item, Index = index })
        .Where(c => c.Count > 0).ToList();

    List<int> newList = (from i in indexList
                         join j in indexList on i.Index equals j.Index + 1
                         where j.Count > 0
                         select i.Index).ToList();

    // Add the previous index since the join only works on n+1
    // Note - Is there a way to include the first comparison card?
    newList.Insert(0, newList[0] - 1);

    // Nice! - got my straight card list
    List<CARDS> cards = (from l in newList
                         select (CARDS)l).ToList();
}

However, I want to make it more compact as in:

static void Test()
{
    List<Card> cardList = new List<Card>();
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Two });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Four });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Five });
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Spades, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Seven });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Eight });

    List<Card> newList1 = (from i in cardList
                           join j in cardList on i.Val equals j.Val + 1
                           select i).ToList();

    // Add the previous index since the join only works on n+1
    // Similar to: newList1.Insert(0, newList1[0] - 1);
    // However, newList1 deals with Card objects so I need
    // To figure how to get the previous, non-duplicate card
    // from the original cardList (unless there is a way to return the
    // missing card!)
}

The problem is that the Sixes are being repeated. Distinct as well as a custom compare function does not work since this will break the n+1 join clause.

Another problem is with the following card list:

    List<Card> cardList = new List<Card>();
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Two });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Three });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Five });
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Spades, Val = CARDS.Six });
    cardList.Add(new Card { Suit = SUITS.Hearts, Val = CARDS.Seven });
    cardList.Add(new Card { Suit = SUITS.Clubs, Val = CARDS.Eight });
    cardList.Add(new Card { Suit = SUITS.Diamonds, Val = CARDS.Jack });

I get a return list of 3Hearts, 6Diamond, 7Hearts, 8Hearts since 2 and 3 are consecutive.

What I really want is a list that returns consecutive cards of 5 or greater, or better yet, the top 5 cards of a continuous sequence. So the above list will return empty since there are no 5 consecutive cards in the input list.

  • 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-01T00:01:32+00:00Added an answer on June 1, 2026 at 12:01 am

    Stupid is as stipid does! Whay was I so worried about using LINQ when the quickest soulution was a simple bit mask:

        List<Card> cardList = new List<Card>();
        cardList.Add(new Card { Suit = SUITS.Diamonds, Val = RANK.Two });
        cardList.Add(new Card { Suit = SUITS.Hearts, Val = RANK.Three });
        cardList.Add(new Card { Suit = SUITS.Clubs, Val = RANK.Five });
        cardList.Add(new Card { Suit = SUITS.Diamonds, Val = RANK.Seven });
        cardList.Add(new Card { Suit = SUITS.Hearts, Val = RANK.Four });
        cardList.Add(new Card { Suit = SUITS.Clubs, Val = RANK.King });
        cardList.Add(new Card { Suit = SUITS.Diamonds, Val = RANK.Ace });
    
        int card = 0;
        foreach (Card c in cardList)
        {
            card |= 1 << (int)c.Val - 1;
        }
    
        bool isStraight = false;
        RANK high = RANK.Five;
        int mask = 0x1F;
        while (mask < card)
        {
            ++high;
    
            if ((mask & card) == mask)
            {
                isStraight = true;
            }
            else if (isStraight)
            {
                --high;
                break;
            }
    
            mask <<= 1;
        }
    
        // Check for Ace low
        if ((!isStraight) && ((0x100F & card) == 0x100F))
        {
            isStraight = true;
            high = RANK.Five;
        }
    
        return card;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a game in Java that simulates the classic 5 cards Poker with
I'm creating a program in C# using System.Speech.Recognition that recognizes voice commands and translates
I have code that looks like this: public class Polynomial { List<Term> term =
When creating system services which must have a high reliability, I often end up
I'm looking into creating a system / site which includes a website. I would
I am creating a scientific application, that communicates with two devices (one via USB,
I'm currently planning out a project involving creating a shell replacement for Windows (based
Iam creating a Flash AS3 based Poker game for my company. Some like zynga
I am creating a simple CLI calculator tool as an exercise. I need to
I was going through Java's HashMap source code when I saw the following //The

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.