in reply to Incrementing strings revisited: What do i miss? [SOLVED]

You're thinking about the solution in terms of the letters being the equivalent of digits in a number. B=0, C=1, etc. and your equivalent of "get the next item in the sequence" is to say "current + 1", or "add C". In that system, it doesn't make sense for ZZ+C to be BBB, since BBB=0, and it also makes sense for "BB" (00) to magically become "B" (0).

But that's not the behavior you'd expect from a string: "BB" would stay "BB" and the next item in the sequence is BC, the same way that in the other solutions BBB comes after ZZ - that's just the next combination in a sequence of strings. Another way to think about it: In a sequence of strings, what reason would one have for skipping BBB?

  • Comment on Re: Incrementing strings revisited: What do i miss?

Replies are listed 'Best First'.
Re^2: Incrementing strings revisited: What do i miss?
by karlgoethebier (Abbot) on Feb 13, 2015 at 20:31 UTC
    "...thinking...in terms...letters being the equivalent of digits in a number..."

    Yes. Base 20 in this case.

    "...BBB comes after ZZ..."

    So the sequence should be like this...

    my @seq_01 = qw (B C D F G H J K L M N P Q R S T V X Y Z); my @seq_02 = qw (BB CC DD FF GG HH JJ KK LL MM NN PP QQ RR SS TT VV XX YY ZZ); my @seq_03 = qw (BBB CCC DDD FFF GGG HHH JJJ KKK LLL MMM NNN PPP QQQ RRR SSS TTT +VVV XXX YYY ZZZ); my @merged_seq = (@seq_01, @seq_02, @seq_03);

    D'oh! I didn't recognize the pattern.

    Thank you very much for advice and breaking my mental block.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Maybe I'm not understanding your @merged_seq, but do you mean to say CC will come directly after BB? I don't think that's the intent, BB would still be followed by BC, BD, etc., so in that respect the sequence is still like a counter. The point here is that at ZZ the sequence would roll over to BBB and not CBB, followed by BBC, BBD, etc.

        "...May be I'm not understanding your @merged_seq..."

        No, you don't and it seems like i failed. No, you don't misunderstand my construct but it seems like i failed. I should have dumped it before posting:

        Edit: Added some clarification

        Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»