FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Computer Programming(Java Intro help) Logic Question.

   
Author Topic: Computer Programming(Java Intro help) Logic Question.
Lanfear
Member
Member # 7776

 - posted      Profile for Lanfear   Email Lanfear         Edit/Delete Post 
So I'm not asking for anyone to do my homework, because that wouldn't be the way I learn how to program, but I'm having trouble with the logic behind this. If anyone could give some insight I would love it..

"a Java program which prompts the user to select (but not disclose) a number between 0 and 31, and then poses exactly five questions to the user to determine the number the user has selected. Each of the five questions is posed by presenting four lines containing a program-generated group of sixteen numbers, asking if the user's selected number is in the group. The program then determines and announces the user's number"

So, I need to have a set of 16 numbers between 0 and 31. They click yes or no. Then it displays 16 more numbers. Yes or No. You get five questions and then I have to announce the number they picked.

So i don't need help with the actual coding of this thing. I need to figure out the logic behind the this number "game"

Anything you could do to steer me in the right direction would be great

http://img.skitch.com/20080211-f98n2ww27mkk66hreshbchitid.jpg

Posts: 332 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
MEC
Member
Member # 2968

 - posted      Profile for MEC   Email MEC         Edit/Delete Post 
Think of it as in binary - 11111 = 31, make it so that each question eliminates half of the numbers and you will have the result.
Posts: 2489 | Registered: Jan 2002  |  IP: Logged | Report this post to a Moderator
Lanfear
Member
Member # 7776

 - posted      Profile for Lanfear   Email Lanfear         Edit/Delete Post 
Ha. one of the hints is "he key to this assignment is the secret of binary. The sets of numbers are generated by fixing the appropriate binary digit at 1."

So I managed to not think of it in binary , but still get it done in five questions.

But I want to be able to think of it in binary. Anyone who can explain further, it would be great.

Posts: 332 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
It sort of looks like a game of "higher/lower" with some added junk in the question.

A higher/lower game that picks the middle number I think can guess the number in 4 questions.

Some examples:

quote:

For instance, if the number picked was 1:

Is the number higher/lower than 16? Lower
Is the number higher/lower than 8? Lower
Is the number higher/lower than 4? Lower
Is the number higher/lower than 2? Lower

Your number is 1.

quote:

For instance, if the number picked was 31:

Is the number higher/lower than 16? Higher
Is the number higher/lower than 24? Higher
Is the number higher/lower than 28? Higher
Is the number higher/lower than 30? Higher

Your number is 31.

quote:

For instance, if the number picked was 7:

Is the number higher/lower than 16? Lower
Is the number higher/lower than 8? Lower
Is the number higher/lower than 4? Higher
Is the number higher/lower than 6? Higher

Your number is 7.

Seems like you could do this program here pretty easily, and display some crap numbers in to pad the question to 16 numbers each display.

I may be misinterpreting the assignment, however.

Sort of looks like they are trying to teach you binary search algorithms in a strange way.

Edit: This little program above was actually the first program I've ever written. I was bored in math class one day so I wrote it on my graphing calculator.

[ February 11, 2008, 01:34 PM: Message edited by: Xavier ]

Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
MEC told you what you need to know.

There are four binary digits in all possible numbers between 0 and 31 (or 0000 to 1111). If you can determine what these digits are, you'll know what the number is.

Also important to remember, fixing one binary digit gives you exactly one half the numbers in the original sample set. Say for 0 to 7 (000 to 111), you've got 8 possibilities. If you hold the center (2^1) digit to 1, you now have 4 possibilities (2 - 010, 3 - 011, 6 - 110, and 7 -111).

Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Lanfear
Member
Member # 7776

 - posted      Profile for Lanfear   Email Lanfear         Edit/Delete Post 
This is my first computer science class and im struggling. But I think its starting to click.
because 0000 and 1111 is 0 to 31.

So that means I could ask the same set of questions no matter what they answer to them?

because the first question would show all the numbers that have a 0... and determine whether the the first column is 0 or 1

then it will go to .0..

then ..0.
then...0

and then once you know all four places you know the number.

I could be missing something entirely. I'm sorry if i'm being oblivious

Posts: 332 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
No, you got it completely. That's really great.

edit: Incidentally, I'd be surprised if the asking the same questions wasn't supposed to be part of the assignment. Otherwise, the insistence of having 16 numbers each time doesn't make that much sense. It would just be stupid padding, like Xavier said.

Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Lanfear
Member
Member # 7776

 - posted      Profile for Lanfear   Email Lanfear         Edit/Delete Post 
i feel like im bugging now.
but im trying to just make my own binary table with their corresponding regular numbers

isn't 1111 15?
so 31 would be 11111?

Posts: 332 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
Sure would be. The quoted portion of the assignment specifies 5 questions though. You have enough.
Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Lanfear
Member
Member # 7776

 - posted      Profile for Lanfear   Email Lanfear         Edit/Delete Post 
Thanks guys. It's been very very helpful.
Posts: 332 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
Oh yeah, sorry. Don't know what I was thinking.
Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2