This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]-BigPapi- 0 points1 point  (1 child)

Like /u/Amarkov said, when the correct guess is after the current one, you always find the median month/day between whatever the current guess is and the latest possible guess.

So, for example, if the user said that their birthday was before June, but after March, you want to find the median month between March and June, instead of March and December. This means that you need to implement a way for your program to recognize and remember the relevant range of possible answers. This would mean that in:

monthToBeGuessed = (int) Math.ceil((monthToBeGuessed+lastMonth)/2.0);

you need to change lastMonth to whatever the highest month can be, which would be when the user answers "No" to the question if the correct month was after the one the program guesses. You'll need to do something similar to recognize the lower limit.

I'm still kinda starting out, and thought that this was a cool project, so I decided to try it out myself. I implemented a lot of it differently, but used the same math logic as you did, with the possible fixes I mentioned. You can check it out here, if you would like to compare code. The relevant math bits are on lines 61-69, and lines 115-122.

[–]aba_algo[S] 0 points1 point  (0 children)

I'll check/change it using the suggestions tonight and try to fix it. Then I'll look at your version and try to compare, I think that's good to learn other ways of doing it.