6 May 2005 22:16
[QUIZ] Perl 'Medium' Quiz of the Week #2005-05-06 - Ranges' Lookup
IMPORTANT: Please do not post solutions, hints, or other spoilers until at least 60 hours after the date of this message. Thanks. Well, the previous quiz did not seem to be very popular. Even I started writing it, and then abandoned. I also reached the conclusion that I'd be better off adapting Template Toolkit or whatever for this. In any case here's a fresh new quiz inspired by a question someone asked on the IRC. (Freenode #perl's channel today) You are given a large number of ranges (A[i],B[i]) where B[i] > A[i] for every i, and A[i] and B[i] are real. The ranges are not supplied in any particular order. You are then given a sequence of real numbers X[0], X[1], X[2] one by one. For each number, you have to determine whether it falls inside at least one of the ranges. For bonus points, you need to supply the user with a set of the indices of matching ranges. Phrasing it Perlishly: Write the following functions: 1. my $handle = prepare_ranges_handle($array_ref); $array_ref is an array ref of array refs each containing two elements, being the numbers of the ranges. It returns $handle, which is a reference used for further querying.(Continue reading)
RSS Feed