Reputation: 956 Master
- Active Posts:
- 3,355 (1.52 per day)
- 12-May 09
- Profile Views:
- Last Active:
- 3 minutes ago
- Viewing Topic: I am getting an error message wh...
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
- Expert In:
- Ruby, Java
24 May 2015 - 20:22
20 May 2015 - 07:26
18 May 2015 - 16:05
06 May 2015 - 10:08
03 May 2015 - 06:49
15 Mar 2015 - 07:26
03 Mar 2015 - 12:04
03 Mar 2015 - 11:29
26 Feb 2015 - 18:02
24 Feb 2015 - 11:27
Posts I've Made
Posted 26 May 2015Do you by any chance have the source code that is literally referred to by the stack trace?
Posted 24 May 2015Please don't open multiple threads on the same topic.
Discussion should take place here: http://www.dreaminco...k-it-up-to-php/
Posted 24 May 2015Right. So does this experiment tell you more about what you need to do? You need to put more logic around how you calculate these two counts.
Why do you try to do this in two different loops? You could get more accurate by doing it in one:
0.upto(guess.length) do |index| if answer[index] == guess[index] positionCorrect++ else if answer.contains(guess[index]) colorCorrect++ end end
Takes care of the fact that the variables aren't wholly independent, for example.
Posted 24 May 2015That's not what I meant.
For #1, I mean after the loop, adjust your correctColor value by subtracting the correctPosition value from it.
Posted 24 May 2015Thanks, that sample output is immensely helpful.
So I think you've actually encoded your partial guesses differently than you specified it. Here, you say that the second number should be the number of partial guesses.
Your code, however, calculates for the number the number of characters which appear in both the guess and the answer, regardless of position and separate from the number that are totally correct.
I could see two approaches working out here:
1) You could probably subtract the number of items that were totally correct from the number that were partially correct to get the actual number that were partially correct.
2) You could also condense your for loops into one, and do a more elaborate if statement to decide which number to increment.
- Member Title:
- I wrote you an code
- 26 years old
- June 23, 1988
- Boston, MA
- Forum Leader:
- Years Programming:
- Programming Languages:
Professionally interested in: Elm, Scala|OCaml|Haskell, Rust, Ceylon
Academically interested in: Prolog, Erlang, Forth, Idris, Smalltalk
Abandoned: C, C++, Pascal, BASIC
- Click here to e-mail me