250 Point Problem
Write a method count
that, given a matrix and a set of fill values, returns the number of elements in the matrix that make up the fill value set.
Solution.
Unit Tests For Sample Data.
I found the original problem statement for this problem to be very ambiguous. The actual context of the problem is image dithering; the given matrix represents a colored display, and the set of fill values represents dithering colors. The solution objective is to count the number of pixels in the display that are part of a dithered color. The ambiguity is in how to treat a single pixel that is colored with one of the dithering colors, but is surrounded by pixels which are not colored by dithering colors. The sample data for the problems hints that such a pixel should be counted, while my (very basic) understanding of image dithering suggests such a pixel should not be counted. In the end, I designed my algorithm to do the latter.
500 Point Problem
Write a method getPercentages
that, given a time quantity in HH:MM:SS format, returns the number of times a whole percentage would be encountered if a timer were to count up and, each second, compute the ratio of elapsed time to total time. This count of whole percentages should exclude 0% and 100%.
Solution.
Unit Tests For Sample Data.
From a different perspective, this problem is actually asking how many pieces (minus one) a quantity can be divided into, with the stipulations that each piece must represent a whole percentage of the quantity, and that each piece must consist of a whole number of units. Because of the first stipulation, the maximum number of pieces we are interested in is 100. Thus, a simple, brute force solution which tests the two stipulations on 100 pieces, 99 pieces, 98 pieces, etc, works well.
1100 Point Problem
Write a method motorUse
which simulates a motorized vending machine and, when given list of purchases, returns the number of seconds the motor is active.
Solution.
Unit Tests For Sample Data.
This problem was different, in the algorithmic sense, than other TopCoder problems I've seen. The difficulty in it came mostly from having to adhere to the many details in the problem specification. Consequently, the problem seemed more a software engineering puzzle; but, it was still a fun change of pace.
No comments:
Post a Comment