Changes 11/6/14
UMD Programming Contest:
- Realized I had made an incorrect assumption about the data. The first number of each set to check (such as in the table at the bottom of page 4 of the pdf) appears to be number of integers on that line, and not actually a number to be checked for triple-ness.
- This had also caused me to make the incorrect assumption that each number was to be counted only once, which clearly isn't true, because the line 5 13 12 3 4 5 is expected to output both {5 12 13} and {3 4 5}. Since the first five in that set is the number of integers, the second five has to be counted twice.
- After making this assumption, I then wasted valuable time making the program set values it had identified were Pythagorean triples to -1 and adding integer > 0 checks to all the for loops so that values of -1 would be ignored.
- I also feel like the designers were very lazy in their setup of the environment, which leads to problems like this where they have hardcoded the expected length of the line into the file without being explicit about what they are doing.
- To be fair, they did say:
- "The first line in the test data file contains the number of test cases (< 100). After that, each
line contains one test case: the first number is n (3 ≤ n ≤ 50), the size of the sequence, and the
following n numbers are the sequence (not necessarily in any order)"
- However, that's not worded very intuitively, and I either missed that completely or just didn't understand what they were saying. One of the lessons I'm taking away from this problem in particular is to read the prompt and explanation very carefully.
- I eventually got an implementation that worked, although it runs in O( n3 ) since there are three nested for loops.
- Even in victory, I feel defeated, especially because I had to cheat a little and googled the best way to find the b value in a2 + b2 = c2, where a < b < c.
- I found a really simple solution to finding this intermediate value on stackoverflow, which was to add a+b+c and subtract the min and max values, leaving the only value that wasn't an extreme. I wish I could have thought of this on my own, but I just don't have enough practice with this sort of thing yet.
Great work! You're already (after only a few days) approaching the conclusion that I mentioned in yesterday's post - you will soon get much more comfortable with both solving these kinds of problems *and* reading them. It just takes practice - *lots* of practice, so we have no time to waste.
ReplyDelete