Message Boards Message Boards

0
|
810 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Creating a grid that deducts a sum from a total

Posted 3 years ago

Hello everyone,

I've only been using Mathematica for the past five days, so please bear with me as I fumble about. I've been reading up as much as I can (and still am) and using the introductory videos, but there are some concepts I'm still struggling with.

What I'm trying to do is to create a grid of 150 buttons. Each button has an integer value of 1 to 150). That's the easy part:

Grid[Partition[Button[#, Appearance -> "Palette"] & /@ Range[150], 15], 
 Spacings -> {1, 1}]

The buttons can be depressed, and as I depress the buttons, they stay depressed and sends the corresponding numbers to be added up to a list, then deducted from a 11325. Eg if I press the buttons 1, 5, 10, and 100, it will deduct 1, 5, 10 and 100 and the result would be 11209. I think using delayed values is the key here.

I think the way to this would to assign functions:

a=11325 y=[total of listed numbers] x= a-y

The trouble is, I haven't been able to find an example of how to create the conditions to produce y. I haven't been able to express this in a way that integrates all of these ideas either.

I would very much like to figure this out myself, so instead of asking if you would solve this for me, I would ask if you would point me in the right direction. Math was never my strong point, and I've been looking at using Mathematica to relearn math think computationally. I think a lot of the challenges for me right now comes from not knowing the terms used to express the language.

Thank you for your help!

Tom

POSTED BY: Thomas Choy
2 Replies
Posted 3 years ago

Thank you Rohit! I'll give that a shot!

POSTED BY: Thomas Choy
Posted 3 years ago

Hi Thomas,

Here is one way to show the resulting difference and the values clicked on.

x = 11325;
selected = {};
{Dynamic[x], Dynamic[selected]}

Grid[Partition[Button[#, (x -= #; AppendTo[selected, #]), Appearance -> "Palette"] & /@ Range[150], 15], 
  Spacings -> {1, 1}]

I have not figured out how to modify the button appearance to stay in the pressed state. Try experimenting with setting Appearance to another dynamic variable and changing it when the button is pressed.

POSTED BY: Rohit Namjoshi
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