• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using specific numbers and operators to reach a target number.

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For my assignment, I have to allow the player to select 6 numbers from two different lists as they please.



After they have selected their numbers say [100, 3, 5, 6, 9, 5] they then generate a target number of lets say for example 299 and they then can only use the numbers selected as a means of reaching the target using ONLY multiplication, addition, subtraction and division. So they could input for instance, 100 * 3 + 5 - 6 to reach the 299 target and this would be checked and scored appropriately.

Unfortunately I don't really have much to go on and I'm a bit confused on how to go about even starting to do that, I'm not looking for a straight up answer, maybe some pointers or external help would be much appreciated.
 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't sound like you have a Java problem (yet), it seems more like you are not clear what you need to do.

Take the information that you have been provided, and think-about how you and a friend would play this game using just pencil and paper. Go through the process of trying it out, identifying any issue, and making changes until you are sure that it is correct and complete. After that, think-about how you might perform each of the steps with Java.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Ron McLeod
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Take the information that you have been provided, and think-about how you and a friend would play this game using just pencil and paper.


For example:

You: Present the large list ask your friend to pick a single number from the list.

Friend: Picks a number and tells you.

You: Verify that the number was in the list that you presented.
You: Write the number down for use later.
You: Present the small list ask your friend to pick 5 numbers number from the list.

Friend: Picks 5 numbers and tells you.

You: Verify that the numbers were in the list that you presented, and that each number was only selected once.
You: Write the numbers down for use later.
You: Calculate a target number which could be generated using the numbers that your friend picked using only +-*/.
You: Present the target number, and ask your friend to use the numbers that they picked and the +-*/ operators to equal the target number.

Friend: Works-out an answer and tells you.

You: Verify that only the picked numbers were used in the answer.
You: Evaluate the answer and verify that it is correct.
You: Adjust your friend's score.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic