## Fourth Assignment

Wambolo
Computerversteher
Beiträge: 381
Registriert: 18. Okt 2007 11:36

Hi,

reagrding test5b [(2, 20), (2, 25), (3, 35), (5, 50), (7, 70)] is the correct computation of (mergeLists ($$k1, v1) (k2, v2) -> k1 < k2) [[(2, 20), (5, 50), (7, 70)], [(2, 25), (3, 35)]]) Why shouldn't [(2,25), (2,20),...] be correct too. Have I overlooked some implicit specifications? olg Sonntagsinformatiker Beiträge: 297 Registriert: 1. Okt 2008 19:24 ### Re: Fourth Assignment I've come across the same issue. The test either works with <= as the operator of k1,k2 , or with (2,20),(2,25) replaced in the solution. "To Perl, or not to Perl, that is the kvetching." ~Larry Wall nt4u Mausschubser Beiträge: 50 Registriert: 16. Apr 2009 15:02 ### Re: Fourth Assignment I think the tests assume stability. olg Sonntagsinformatiker Beiträge: 297 Registriert: 1. Okt 2008 19:24 ### Re: Fourth Assignment In order to provide stability, shouldn't the comparator function be as follows (in order to provide EQ for stability) ? a -> a -> Ordering In the current implementation, the function (\(k1, v1) (k2, v2) -> k1 < k2) obviously returns false for (2,20)(2,25) and thus indicates that the pairs should indeed are not sorted. Using Ordering, we can distinguish this special case, and ignore the switch. "To Perl, or not to Perl, that is the kvetching." ~Larry Wall DanielSchoepe Mausschubser Beiträge: 49 Registriert: 28. Sep 2009 11:39 ### Re: Fourth Assignment olg hat geschrieben:In order to provide stability, shouldn't the comparator function be as follows (in order to provide EQ for stability) ? a -> a -> Ordering In the current implementation, the function (\(k1, v1) (k2, v2) -> k1 < k2) obviously returns false for (2,20)(2,25) and thus indicates that the pairs should indeed are not sorted. Using Ordering, we can distinguish this special case, and ignore the switch. You can already achieve the same result with the given function (assuming that it decides a total ordering) by considering op y x. If that doesn't hold, you know that \(\neg (y < x)$$ and thus $$y \ge x$$; if it does hold, we have $$y < x$$, which should give you enough information to decide how to order x and y (with "<" being the thing op decides, not integer comparison) in a stable manner.

doemel
Mausschubser
Beiträge: 75
Registriert: 23. Okt 2010 11:45
Kontaktdaten:

### Re: Fourth Assignment

grml ... hat sich erledigt

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Re: Fourth Assignment

doemel hat geschrieben:grml ... hat sich erledigt
What was the problem with map? (Please don't delete your orignal post; maybe others can learn from your experience.)

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten: