zsh-users
 help / color / mirror / code / Atom feed
* Looking for devious one or two liner solutions to a problem
@ 2007-10-10 23:37 Kenneth Lareau
  2007-10-11  2:45 ` Clint Adams
  2007-10-11  3:35 ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Kenneth Lareau @ 2007-10-10 23:37 UTC (permalink / raw)
  To: zsh-users

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. 5.3.20.4) 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:

        5.3.20.4, 0  ->  6.0.0.0
        8.14.0.5  1  ->  8.15.0.0
        3.9.42.6  3  ->  3.9.42.7

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

-- 
Ken Lareau
elessar@numenor.org


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-10-11  9:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-10 23:37 Looking for devious one or two liner solutions to a problem Kenneth Lareau
2007-10-11  2:45 ` Clint Adams
2007-10-11  3:01   ` Atom Smasher
2007-10-11  3:35 ` Bart Schaefer
2007-10-11  3:42   ` Bart Schaefer
2007-10-11  9:02     ` Peter Stephenson
2007-10-11  4:03   ` Kenneth Lareau
2007-10-11  6:13   ` Kenneth Lareau

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).