Hi all,
I read Algorithm for "Incrementing" strings and tried to solve the problem for learning - following the recommendation by tye to use Math::Fleximal.
The specs as provided by ibm1620:
$val = 'BB'; incr($val); ==> 'BC' $val = 'BZ'; incr($val); ==> 'CB'; $val = 'ZZ'; incr($val) ==> 'BBB';
I think that "ZZ" should be incremented to "CBB".
I tried this:
#!/usr/bin/env perl use strict; use warnings; use Math::Fleximal; # use Data::Dump; use feature qw (say); my @consonants = qw (B C D F G H J K L M N P Q R S T V X Y Z); my $number = Math::Fleximal->new( "BB", \@consonants ); say $number->to_str(); say $number->base_10(); $number = $number->add("C"); say $number->to_str(); say $number->base_10(); say qq(--); $number = $number->set_value("BZ"); say $number->to_str(); say $number->base_10(); $number = $number->add("C"); say $number->to_str(); say $number->base_10(); say qq(--); $number = $number->set_value("ZZ"); say $number->to_str(); say $number->base_10(); $number = $number->add("C"); say $number->to_str(); say $number->base_10(); __END__ karls-mac-mini:monks karl$ ./fleximal.pl B 0 C 1 -- Z 19 CB 20 -- ZZ 399 CBB 400
Seems like it works as designed (or i hope so).
But in the solutions provided by other monks "ZZ" is incremented to "BBB".
What do i miss?
Update: Thank you very much to all who helped.
Update2: Reset state to [UNSOLVED]
Update3: Set state to [SOLVED]. Thanks again to all for help and patience.
Thank you very much for any hint and best regards, Karl
P.S.: Sorry, i'm pretty bad in even essential math.
«The Crux of the Biscuit is the Apostrophe»
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |