in reply to Re: symbolic increment/decrement of roman numerals
in thread symbolic increment/decrement of roman numerals
Indeed, for decrement the snippet has wrong behaviour for these cases. It can be fixed by extending the regex ruleset slightly, which is left as an exercise to the reader.
Clearly, if the snippet would behave correcting, i.e. dec('IL') should return XLVIII, this would require more "gist".
Basically I tested the inc/dec subs by letting the one increment and the other decrement numbers and checked whether the result remained original. Like so:
use strict; my $roman = 'I'; my $roman2; while(1) { $roman = &inc($roman); # print "$roman\n"; if($roman ne &dec(&inc($roman))) { print "MISMATCH for $roman\n"; print "\t",&inc($roman),"\n"; print "\t",&dec($roman),"\n"; } }
Bye
PetaMem All Perl: MT, NLP, NLU
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: symbolic increment/decrement of roman numerals
by kaif (Friar) on Jun 04, 2005 at 18:12 UTC |