Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Generate a truth table from input string

by psini (Deacon)
on May 13, 2008 at 15:09 UTC ( [id://686291]=note: print w/replies, xml ) Need Help??


in reply to Generate a truth table from input string

Quick&dirty solution:

Use a regualr expression to extract all the variables (assuming a form of \w+), store them in an hash along with an auto-generated variable name (eg $a,$b..).

Use another regexp to replace all variables with the new names and replace the operators with the corresponding perl operator (eg s/\*/ && /g).

Perform a series of nested loops, one for each variable, and eval the expression.

Note that this is probably not what your teacher wants from you!

Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://686291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-26 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found