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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:17:26+00:00 2026-06-10T12:17:26+00:00

I want to convert a string of playing cards given as in A into

  • 0

I want to convert a string of playing cards given as in A into a form B such that I can produce a result C.

A: "(AK,AQ,(A2:*h*h)):*s*s!AsQs,(JJ:*s*h)"
B: (((AsKs union AsQs union (A2 intersect hand with two hearts)) intersect hand with two spades) less AsQs) union (JJ intersect hand with one spade one heart)
C: AsKs,JsJh

The precedence of operations is

  • 1) parentheses, ‘()’
  • 2) intersect and less (left associative), ‘:!’
  • 3) union, ‘,’

I have the functionality to perform the operations in B, for example Intersect(“AA”, “*s*s”) == “AsAs”, but I need a way to get from the form A into the form B of inputs and associated operations that I can perform in sequence to arrive at C.

I have looked at Irony and some other lexer/parser solutions, but they seem a bit overkill for this problem. Is there a simpler solution?

  • Perhaps recursively splitting the string into a tree with nodes representing operations?
  • Breaking down the string in reverse order of precedence and pushing it onto a stack? If so how (roughly) could this be implemented?

A working example of what I am trying to emulate is given here. You can find a more detailed description of the syntax for A here.

  • 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-10T12:17:27+00:00Added an answer on June 10, 2026 at 12:17 pm

    You could parse A to construct a tree of instructions and then execute them starting from the leaves (as I assume you’d want to execute the contents of the innermost brackets first). For this parsing task, you could use Regexes, or whatever else you want. Off the top of my head, I think you can first look for the parenthesis and operator symbols to figure out the tree structure, then fill in each leaf with the actual elementary instruction and each junction with the operator.

    The data structure storing A can be composed of objects (call them Expression) implementing an interface IOperand; each Expression should have three fields:

    1. A field Operator which is an instance of enum Operations {Union, Intersection, SetDiff}, or just a string, depending on which you prefer.
    2. Two fields Operand1 and Operand2, which can be either something like “Ah” (defining a set of cards), or another Expression. Therefore, they should be declared as instances of IOperand.

    Your class for holding a single set of cards, like “Ah”, should also implement this IOperand. The interface IOperand itself need not actually do anything.

    For matching each given instruction to an operation, you could use a simple switch, or alternatively a Dictionary of string (or enum) to delegate IOperand SetOp(IOperand, IOperand);, and then populate your Dictionary with (anonymous) functions (that would contain the instructions for B).

    In the Dictionary case, you would simply be able to do instructionList[thisExpression.Operation](thisExpression); (this can probably be done a bit more elegantly to avoid referencing thisExpression twice) and the appropriate C# translation of the string input would be executed.

    Proof of Concept

    I have made a basic implementation and a console app to demonstrate usage here: https://bitbucket.org/Superbest/lexer

    If you succeed at progressing through the whole exercise with your sanity intact (the computer will use you as a surrogate parsing and operation library, so good luck with that) then the final step should ask you to evaluate an expression equal to C and then print what you just entered back at you. (When running for the first time, you might want to comply with the program’s directives. I suspect it is very easy to break the code and get lots of exceptions, and confuse yourself very much if you try to think about what happened to your invalid input.)

    If you are running the code as is, try the following sequence of answers (, = Enter):

    n, y, 2, n, n, n, y, 2, n, n, y, n, y, 2, n, n, n, n, alpha, beta, gamma
    

    Your output will be:

    gamma
    

    You should be able to simply update the bodies of methods marked obsolete and have a working program.

    If you wish to add more binary operations, see the TODO in the body of Simplification.Simplification(). The appropriate syntax will be obvious from looking at the three operations I already made; as it is, the code supports only binary operations. If your methods consume strings, you can use the SimplifiedOperand.Symbol field.

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

Sidebar

Related Questions

I want to build a method that can convert a String value to a
I want to convert string from koderesult into object, and then thie obj.result should
I want to convert a string variable into char that char variable will have
I want to convert a string into a series of Keycodes, so that I
i want to convert this string into DateTime. Tue Aug 19 15:05:05 +0000 2008
I want to convert a string like 2012-03-08T00:00:00+01:00 into Date.. I tried to use
I want to convert string Date into Timestamp in java. The following coding i
i want to convert string into array when comma or semicolon is encountered. for
I want to convert string to other type. The problem is that I know
I want to convert an Object into a String in PHP. Specifically, I'm trying

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.