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

  • Home
  • SEARCH
  • 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 6937637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:23:21+00:00 2026-05-27T12:23:21+00:00

I am trying to write a predicate to analyse common poker hands; for example

  • 0

I am trying to write a predicate to analyse common poker hands; for example given a list of “cards” identify if the player has 4 of a kind; 3 of a kind; pair etc:
My idea was to check for similar rank and remove if not:

this works for fourofakind([“A”,”J”,10,”Q”,”A”,”A”,”A”])

but not all scenarios; any guidance on the logic here?

Thanks

  • 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-05-27T12:23:22+00:00Added an answer on May 27, 2026 at 12:23 pm

    As chac pointed out and to have again the debate we had in this post, you can use append to successfully parse your list once sorted quite easily. Without sorting, you could write :

    fourofakind(Hand, X) :- append([_, [X], _, [X], _, [X], _, [X], _], Hand).
    

    This basically tells prolog : I want my hand to have 4 times the sublist [X] with anything in-between.

    Or, to use what @false describes as a very graphically appealing solution in his reply on the other thread (DCGs) :

    four --> ..., [X], ..., [X], ..., [X], ..., [X], ... .
    
    ... --> [] | [_], ... .
    
    ?- Xs = "bacada", phrase(four, Xs).
    

    You could too avoid using too many built-ins by doing the work with basic recursion :

    three_of_a_kind(Item, [Item|Tail]) :- pair(Item, Tail).
    three_of_a_kind(Item, [_Item|Tail]) :- three_of_a_kind(Item, Tail).
    
    pair(Item, [Item|Tail]) :- one(Item, Tail).
    pair(Item, [_NotItem|Tail]) :- pair(Item, Tail).
    
    one(Item, [Item|_Tail]).
    one(Item, [_NotItem|Tail]) :- one(Item, Tail).
    

    Note that here one/2 is equivalent to the naive definition of member/2. I let you the task of adding four_of_a_kind/1 by looking at how three_of_a_kind/1 and pair/2 work ! Use of cut would be interesting too to remove unused choice points.

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

Sidebar

Related Questions

I'm trying to write a predicate that divides a list into N parts. This
I've been trying to write an extension method to mimic List.RemoveAll(Predicate). So far I've
im trying to write an app that will display a list off lines from
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a predicate to check a specific value in a dictionary
I am trying to write some simple predicate using boost::lambda and I am getting
I'm trying to write a subroutine in Perl that will delete a given node
I'm trying to write predicate function for use with STL algorithms. I see that
I'm stumped trying to write a predicate for Recently Completed tasks, i.e. show the
I'm trying to write a function that will produce the combinations of list elements

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.