Message Boards Message Boards

0
|
8710 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How to use checkboxes to define a list?

Posted 11 years ago
Hi all:

I'm working on a program to generate fraction arithmetic problems, in particular where the student can choose which operation(s) they'd like to focus on.  Right now I have a pulldown menu with each of the four arithmetic operations selectable, and then an "all" selection where the program will use any of the four arithmetic operations at random.  What I'd like to do is have checkboxes for addition, multiplication, etc. in the manipulate pane, and then have the checked boxes define which operations the program "allows" when it build problems.  I can think of a couple of "brute force" ways to do this, like listing every possibility of checked boxes in a Which command, but I feel like there must be a better way...

Hoping someone out there has a good suggestion!

Thanks,

Rob
POSTED BY: Rob Holman
tl;dr  Use the Pick command

I'm not sure if I exactly understand the problem. Here is my example which probably isn't the best code. Note that I make the numbers into strings to prevent evaluation, which is a bit of a hack:
makeRdnProb[operations_] :=
     With[{rndInt := ToString@RandomInteger[{0, 50}],          
           rndOperation := RandomChoice@operations},   

         rndInt ~ rndOperation ~ rndInt ~ rndOperation ~ rndInt 
    ]
 This function takes a list of operations like {Times, Plus, Subtract} , produces three random integers and inserts a random operation inbetween them. I've used the infix notation using the tilde (~)  which might be a bit confusing if you haven't seen it before.

Note I wrote this function and tested it before writing any user interface. For most projects, don't worry about the user interface until you have functions that do the calculations you want.  This separates your programming problem up into easier parts. 

Once I had this function, I wrote a Manipulate like this:

Manipulate[ 
    makeRdnProb[Pick[{Plus, Subtract}, {addition, subtraction}]],
   
    {addition, {True, False}}, {subtraction, {True, False}}
]

The function doesn't handle the case where it is given an empty list. That would still need to be written for example. 
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract