Fourth Assignment

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

Fourth Assignment

Beitrag von Wambolo »

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?

Benutzeravatar
olg
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

Re: Fourth Assignment

Beitrag von olg »

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
Mausschubser
Beiträge: 50
Registriert: 16. Apr 2009 15:02

Re: Fourth Assignment

Beitrag von nt4u »

I think the tests assume stability.

Benutzeravatar
olg
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

Re: Fourth Assignment

Beitrag von olg »

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
Mausschubser
Beiträge: 49
Registriert: 28. Sep 2009 11:39

Re: Fourth Assignment

Beitrag von DanielSchoepe »

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
Mausschubser
Beiträge: 75
Registriert: 23. Okt 2010 11:45
Kontaktdaten:

Re: Fourth Assignment

Beitrag von doemel »

grml ... hat sich erledigt

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

Re: Fourth Assignment

Beitrag von sewe »

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.)

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

Re: Fourth Assignment

Beitrag von sewe »


Antworten

Zurück zu „Archiv“