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»


In reply to Incrementing strings revisited: What do i miss? [SOLVED] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.