This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Resolving Boolean Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Resolving Boolean Expression" Watch "Resolving Boolean Expression" New topic
Author

Resolving Boolean Expression

Vj Kamath
Greenhorn

Joined: Nov 19, 2004
Posts: 15
Given this input, i have to write a program to generate different possible combinations.
( ( ( A | B | C | D | F | G | E | H | I ) & J ) | ( ( A | D | H ) & L ) | ( ( B | G ) & M ) | ( F & K ) )

result should be
AJ OR BJ OR CJ OR DJ OR EJ OR FJ OR HJ OR IJ
OR
AL OR DL OR HL
OR
BM OR GM
OR
FK

I have found programs that use stacks to convert from infix to postfix ...etc. But this program is different. This needs to resolve the string.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Hmmm....
Sounds like a school assignment..

If this is really about string parsing, then the regexp tools in j2sdk1.4 and up can make short work of this task.

1.) Remove white space.
2.) Split the string into groups on ")|(" (lame but efficient).
3.) For each group, split the groups into pairs on "&".
4.) Remove all non alpha characters (caps in this case).
5.) For each char in the left side of the pair, print
char plus right side of pair.

Like this:


Now, if this is for a "Data Structures" or "Compiler" class as the title suggests, such an approach would probably get you a failing grade. Go back and look a the stack approach.
[ December 31, 2004: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Resolving Boolean Expression
 
Similar Threads
visualizing hierarchy structure
HashMap Iteration
New Mock Exam questions...
Logic with java code
Merging repeted elements in XML