Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Looking for devious one or two liner solutions to a problem

At my workplace, we have a given problem we give potential engineers to see how their
programming and thought process skills are; it's a relatively simple problem:

   Given a version string of the form a.b.c.d (e.g. and an index of 0-3
   (representing the position of a given number in the version string, zero-based),
   write a function that will take the two as parameters and return a new version
   string which has the number in the index position given incremented by one and
   all successive numbers set to 0.  Examples:, 0  ->  1  ->  3  ->

In Perl, I was able to come up with the very simple function below:

   sub bump_version {
       my ($vers, $ind) = @_;

       @vers = split /\./, $vers;
       $vers[$ind] += 1;
       for ($i = $ind + 1; $i < 4; $i++) {
           $vers[$i] = 0;

       return join '.', @vers;

I've come up with something very similar in zsh, but I'm extremely curious;
is there anyone out there who knows zsh well enough to create a highly compressed
version of this function that would fit on a single 80 character line (or perhaps
two such lines)?  While I've been using zsh for many years, I haven't delved deep
enough into it to be able to figure anything out, but if someone else could, I'd
be very appreciative to see it!


Ken Lareau

Messages sorted by: Reverse Date, Date, Thread, Author