[Question]
  [
As code-golfers, we're not used to releasing (*surely*). We're gonna need a few tools to help us do that.
Of course, to help marketing a new release, we need a nice and shiny Release Version. Who doesn't get excited when they hear about version 3.0.0?
### Task
Your task will be to write a program/routine/... to increment a version number.
You need to increment the version number and reset the "less important" ones (i.e. patch version).
You get two arguments: the current version (ex "1.0.3") as a string, and an index to know which one to update (0 or 1-indexed).
Example, 0-indexed:
```
next-version("1.0.3", 0) # 2.0.0
next-version("1.2.3.4.5", 2) # 1.2.4.0.0
next-version("10.0", 0) # 11.0
next-version("3", 0) # 4
next-version("1", 7) # ERROR
next-version("01", 0) # ERROR
```
The version is a string, each part is a number, separated with a dot. There can be no leading, no trailing or no consecutive dots (and nothing outside of numbers/dots). There is no limit to the size of the version string.
`^[1-9]\d*(\.[1-9]\d*)*$`
The error case (last two examples) is undefined behavior. What happens in case of wrong inputs is of no relevance to this challenge.
As usual, standard loopholes are forbidden. You're allowed to print or return the string.
  
[Answer]
# Japt, ~~16~~ 11 bytes
```
¡V«´V+ÂX}'.
```
[Test it online!](http://ethproductions.github.io/japt/?v=master&code=oVartFYrwlh9Jy4=&input=IjEuMi4zIiAy) Input number is 1-indexed.
Based on my JavaScript answer. This takes advantage of one of Japt's most helpful features: splitting one string on another before mapping each item, then joining on that string again after mapping.
### Ungolfed and explanation
```
¡  V«  ´ V+Â X}'.
Um@V&&!--V+~~X}'.
                   Implicit: U = input string, V = input number
Um@           }'.  Split U at periods, then map each item X by this function:
   V&&               If V is 0, return V.
      !--V+~~X       Otherwise, decrement V and return X + !V (increments X iff V was 1).
               '.  Re-join the result with periods.
                   Implicit: output last expression
```
[Answer]
# Vim ~~20~~ 25 bytes
I unfortunately realized that it didn't handle the case of updating the last number, so I had to add bytes. This is 1-indexed.
```
DJA.0@"t.qq2wcw0@qq@qx
```
[TryItOnline](http://v.tryitonline.net/#code=REpBLhswQCJ0LgFxcTJ3Y3cwG0BxcUBxeA&input=NQoxLjIuMy40LjU)
Unprintables:
```
DJA.^[0@"t.^Aqq2wcw0^[@qq@qx
```
This takes the arguments in reverse order, as separate lines:
```
3
1.2.3.4.5
```
Explanation:
```
DJ                           # Delete the input argument, and join lines
  A.^[0                      # Add a period to the end
       @"t.                  # Move to the "Copy register"th period
           ^A                # Increment the number under the cursor
             qq       @qq@q  # Until an error
               2w            # Move the cursor forward to the next number
                 cw0^[       # Change the number to 0
                           x # Delete the last '.'
```
[Answer]
# [V](http://github.com/DJMcMayhem/V), ~~13~~, 12 bytes
```
Àñf.ñò2wcw0
```
[Try it online!](http://v.tryitonline.net/#code=w4DDsWYuw7EBw7Iyd2N3MA&input=MS4yLjMuNC41&args=MQ)
This is 0-indexed.
There is a `ctrl-a` (ASCII 0x01) in there, so here is a readable version:
```
Àñf.ñ<C-a>ò2wcw0
```
Explanation:
```
À                   " 'arg1' times
 ñ  ñ               " Repeat the following:
  f.                "   Move to the next '.' character
     <C-a>          " Increment the next number
          ò         " Recursively:
           2w       "   Move two words forward
              cw    "   Change this word
                0   "   to a '0'
```
[Answer]
# JavaScript (ES6), ~~44~~ ~~42~~ ~~40~~ 37 bytes
*Saved 3 bytes thanks to @Neil*
```
x=>i=>x.replace(/\d+/g,n=>i&&+n+!--i)
```
Input number is 1-indexed.
### Test snippet
```
f = x=>i=>x.replace(/\d+/g,n=>i&&+n+!--i)
console.log(f("1.0.3")(1))
console.log(f("1.2.3.4.5")(3))
console.log(f("10.0")(1))
console.log(f("1")(8))
```
[Answer]
# Perl, ~~40~~ ~~37~~ 34 + 1 = 35 bytes
-2 bytes thanks to @Dada. -3 bytes thanks to an idea I got from reading @ETHproductions's Japt code.
Run with the `-p` flag.
```
$a=<>;s/\d+/$a--<0?0:$&+!($a+1)/ge
```
[Try it online!](https://tio.run/nexus/perl#@6@SaGtjZ12sH5Oira@SqKtrY2BvYKWipq2ooZKobaipn576/7@hnoGeMZcBl6GekZ6xnomeKZcRl6GBngFIiMv8v24BAA "Perl – TIO Nexus")
### Breakdown of the code
```
-p          #Wraps the program in a while(<>){ ... print$_} statement.
            #Input is read into the $_ variable
$a=<>;s/\d+/$a--<0?0:$&+!($a+1)/ge
$a=<>;                              #Reads the version update into $a
      s/   /                   /ge  #Substitution regex:
                                g   #Repeats the substitution after first match
                                 e  #Interprets replacement as Perl code
       \d+                          #Matches 1 or more digits, and stores match in $&
                  ? :               #Ternary operation
            $a--<0                  #Checks if $a is negative and then decrements $a
                  ?0                #If negative, we've passed our match; print 0 instead
                    :$&+!($a+1)     #Otherwise, we're either printing $& + 0 (if $a was positive) or $& + 1 (if $a was 0).
#Since substitution implicitly modifies $_, and -p prints $_, it prints our answer
```
[Answer]
# C# ~~116~~ 104 Bytes
```
using System.Linq;(v,i)=>string.Join(".",v.Split('.').Select(int.Parse).Select((x,n)=>n==i?x+1:n>i?0:x));
```
## Explanation
```
using System.Linq;(v,i)=>   //Anonymous function and mandatory using
    string.Join(".",                    //Recreate the version string with the new values
        v.Split('.')                    //Get individual pieces
            .Select(int.Parse)          //Convert to integers
                .Select(            
                    (x,n)=>             //Lambda with x being the part of the version and n being the index in the collection
                        n==i                    
                            ?x+1        //If n is the index to update increment x
                            :n>i        //Else if n is greater than index to update
                                ?0      //Set to zero
                                :x));   //Otherwise return x
```
[Try it here](https://dotnetfiddle.net/f2t5oZ)
[Answer]
# Python 2, 84 Bytes
I feel like this could really be shorter.. Might need a way to have a non-enumerate option.
```
lambda s,n:'.'.join(str([-~int(x)*(i==n),x][i<n])for i,x in enumerate(s.split('.')))
```
If we were able to take the version as a list of strings, there's a 75-byte solution:
```
g=lambda s,n:(str(-~int(s[0]))+'.0'*~-len(s))*(n<1)or s[0]+'.'+g(s[1:],n-1)
```
Furthermore, if both the input and output were lists of numbers, there's a 64-byte solution:
```
g=lambda s,n:([-~s[0]]+[0]*~-len(s))*(n<1)or [s[0]]+g(s[1:],n-1)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~19~~ 17 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ṣ”.V€‘⁹¦µJ’<⁹×j”.
```
1-indexed.
**[TryItOnline!](http://jelly.tryitonline.net/#code=4bmj4oCdLlbigqzigJjigbnCpjBK4bmr4oG54oCYJMKlwqZq4oCdLg&input=&args=IjEzLjEyLjExLjEwLjkuOC43LjYi+NQ)**
### How?
```
ṣ”.V€‘⁹¦µJ’<⁹×j”. - Main link: currentVersion, theIndex
ṣ”.               - ṣplit left (currentVersion) at occurences of '.'
   V€             - eVal €ach (creates a list of integers)
      ⁹           - right argument (theIndex)
       ¦          - apply to given index(es)
     ‘            -    increment
        µ         - monadic chain separation (call the above result z)
         J        - range(length(z))  i.e. ([1,2,3,...,length])
          ’       - decrement         i.e. ([0,1,2,...,length-1])
            ⁹     - right argument (theIndex)
           <      - less than?        i.e. ([1,1,...,(1 at theIndex),0...,0,0,0]
             ×    - multiply by z (vectortises) - zeros out all of z after theIndex
              j”. - join with '.'
```
[Answer]
# **MATLAB, 85 bytes**
```
function f(s,j);a=split(s,'.');a(j)=string(double(a(j))+1);a(j+1:end)='0';join(a,'.')
```
One based, and first attempt at golf!
[Answer]
# V ~~14~~ 20 bytes
Again, I had to add code for the corner case of incrementing the final digit.
(1-indexed)
```
DJA.0@"t.ò2wcw0òx
```
[TryItOnline](http://v.tryitonline.net/#code=REpBLhswQCJ0LgHDsjJ3Y3cwG8OyeA&input=NQoxLjIuMy40LjU)
Unprintables:
```
DJA.^[0@"t.^Aò2wcw0^[òx
```
This takes the arguments in reverse order, as separate lines:
```
3
1.2.3.4.5
```
[Answer]
## Batch, 119 bytes
```
@set s=%1
@set i=%2
@set t=
@for %%i in (%s:.=,%)do @set/an=!!i*(%%i+!(i-=!!i))&call set t=%%t%%.%%n%%
@echo %t:~1%
```
1-indexed.
[Answer]
# Perl 6, 67 bytes, 0-indexed
```
->$v,$i {$v.split('.').map({++$>$i??($++??0!!$_+1)!!$_}).join: '.'}
```
Explanation:
```
->$v,$i {$v.split('.').map({++$>$i??($++??0!!$_+1)!!$_}).join: '.'}
->$v,$i {                                                         } # function taking version/index to increment
         $v.split('.')                                              # split by dot
                      .map({                          })            # for each version number
                            ++$>$i??                                # if an anonymous variable ($), incremented,
                                                                    #  is greater than $i (index to increment)
                                    ($++??       )                  # if it's not the first time we've been over $i
                                                                    # (using another anonymous value, which gets default-init'd to 0)
                                          0                         # then 0 (reset lower version numbers)
                                           !!$_+1                   # otherwise, increment the number at $i
                                                  !!$_              # otherwise return the number part
                                                        .join: '.'  # join with a dot
```
[Answer]
# PowerShell 3+, ~~75~~ 74 bytes
```
($args[0]-split'\.'|%{$m=!$b;$b=$b-or$args[1]-eq$i++;(+$b+$_)*$m})-join'.'
```
### Ungolfed
```
(
    $args[0] -split '\.' | 
        ForEach-Object -Process {
            $m= -not $b
            $b = $b -or ($args[1] -eq $i++)
            (([int]$b) + $_) * $m
        }
) -join '.'
```
### Explanation
Parameters are accepted using the `$args` array.
1. Split the version string on `.`, then for each element:
	1. `$m` is set to be `-not $b`. On first run, `$b` will be undefined which will be coalesced to `$false`, so `$m` will start as `$true`. `$m` is intended to be a multiplier that's always `0` or `1` and it will be used later. `$m` must be evaluated here because we want it to be based on the last iteration's `$b` value.
	2. `$b` is set to itself `-or` the result of comparing an iterator `$i` with `$args[1]` (the index parameter). This means `$b` will be set to `$true` here once we're on the element that is to be incremented. Additionally, it will be `$true` in every subsequent iteration because the conditional is `-or`'d with its current value.
	3. `$b` is converted to a number using unary `+` (`$false` => `0`, `$true` => `1`), then added to the current version element `$_` which is a `[string]`, but PowerShell always tries to coalesce the argument on the right to the type on the left, so arithmetic will be performed, not string concatenation. Then this value will be multiplied by `$m`, which is still `[bool]` but will be implicitly coalesced.
2. Re-join the resulting array with `.`.
So, the first iteration where `$b` becomes `$true`, `$b` would have been `$false` when `$m` was evaluated, making `$m` equal `$true`, which will keep the multiplier at `1`.
During that run `$b` becomes `$true` and is added to the version element (as `1`), thereby incrementing it, and since the multiplier is still `1`, that will be the end result.
So on the next iteration, `$b` will already be `$true`, making `$m` equal `$false`, which will make the multiplier `0`. Since `$b` will forever be `$true` now, the multiplier will always be `0`, so every element returned will be `0` too.
[Answer]
# PHP, 81 bytes
awfully long. At least: the Elephpant still beats the Python.
```
foreach(explode(".",$argv[1])as$i=>$v)echo"."[!$i],($i<=$n=$argv[2])*$v+($i==$n);
```
loops through first argument split by dots: `"."[!$i]` is empty for the first and a dot for every other element;
`($i<=$n)` and `($i==$n)` are implicitly cast to integer `0` or `1` for integer arithmetics.
[Answer]
# R, ~~100~~ ~~95~~ ~~92~~ 86 bytes
Unusually for R, this uses 0-indexing. Anonymous function with two arguments (a string and an integer). Likely can be golfed down a tad.
```
function(v,i)cat((x=scan(t=el(strsplit(v,"\\."))))+c(rep(0,i),1,-x[-(0:i+1)]),sep=".")
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 22 bytes
```
'.¡vy²N‹i0*}²NQi>})'.ý
```
[Try it online!](http://05ab1e.tryitonline.net/#code=Jy7CoXZ5wrJO4oC5aTAqfcKyTlFpPn0pJy7DvQ&input=MS4wLjAuMC4zCjA)
I don't know how to do if-else in 05AB1E, so this is longer than it should be.
[Answer]
# Coffee-script: 77 67 Bytes
```
f=(p,i)->((z<i&&v||z==i&&~~v+1||0)for v,z in p.split '.').join '.'
```
Woot! Time for cake and coffee for the beta release.
Thanks to @ven and @Cyoce I shaved 10 Bytes!
[Answer]
# Python 3, ~~89~~ 86 bytes
```
lambda v,c:'.'.join((str((int(x)+1)*(i==c)),x)[i<c]for i,x in enumerate(v.split('.')))
```
very naive way of getting things done
Edit: rewritten the conditional by referring to @kade
[Answer]
# JavaScript (ES6), ~~57~~ 55 bytes
```
(s,x)=>s.split`.`.map((j,i)=>i==x?+j+1:i>x?0:j).join`.`
```
Examples:
```
n=(s,x)=>s.split`.`.map((j,i)=>i==x?+j+1:i>x?0:j).join`.`
console.log(n('1.0.3', 0))
console.log(n('1.2.3.4.5', 2))
console.log(n('10.0', 0))
console.log(n('3', 0))
console.log(n('1', 7))
```
Not the best JS implementation but it's fairly simple and follows the logic you'd expect.
[Answer]
## Powershell, ~~80~~ ~~100~~ ~~95~~ 92 Bytes
Saved 5 bytes by using a const for the `-1..if`
Saved 3 bytes by using `!$b` instead of `$b-eq0`
```
filter x($a,$b){[int[]]$y=$a.Split('.');-1..((-$b,-1)[!$b])|%{$y[$_]=0};$y[$b]++;$y-join'.'}
```
Explanation:
```
filter x($a,$b){
    [int[]]$y=$a.Split('.') #Split input into integer array
    $y[$b]++ #Increment 'major' version no. ($b) by one
    -1..((-$b,-1)[!$b])|%{$y[$_]=0} #Set all trailing numbers to 0, now also checks for $b=0 cases.
    $y-join'.' #Join back into '.' seperated Array
}
```
Test Cases:
```
x "1.0.3" 0
x "1.2.3.4.5" 2
x "10.0" 0
x "1" 7
2.0.0
1.2.4.0.0
11.0
Index was outside the bounds of the array.
```
[Answer]
**Objective-C 531 Bytes**
```
#import<Foundation/Foundation.h>
int main(int argc,const char *argv[]){@autoreleasepool{NSString *s=[NSString stringWithUTF8String:argv[1]];NSInteger n=strtol(argv[2],NULL,0);NSArray *c=[s componentsSeparatedByString:@"."];if(c.count<=n)NSLog(@"ERROR");else{int i=0;NSMutableString *v=[[NSMutableString alloc]init];for(;i<n;++i)[v appendFormat:@"%@.",[c objectAtIndex:i]];[v appendFormat:@"%li", strtol(((NSString *)[c objectAtIndex:i++]).UTF8String,NULL,0)+1l];for(;i<c.count;++i)[v appendString:@".0"];NSLog(@"%@",v);}}return 0;}
```
compile:
```
clang -fobjc-arc -Os main.m -o main
```
usage:
```
./main 1.2.3 1
```
[Answer]
# Javascript ES6: 60 bytes
```
n.split(".").map((n,r)=>{return r>i?n=0:n}).join("."),n[i]++}
```
[Answer]
# R, 75 bytes
```
f=function(a,b){n=scan(t=a,se=".");m=-n;m[b]=1;m[1:b-1]=0;cat(n+m,sep=".")}
```
Indexing is 1-based. You can play with it online [here](http://www.r-fiddle.org/#/fiddle?id=Dl6usKXg&version=1).
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 31 bytes
Requires `⎕IO←0` (**I**ndex **O**rigin 0), which is default on many systems. Full program body; prompts for text input (version) and then numeric input (index).
```
' '⎕R'.'⍕⎕(⊢∘≢↑↑,1+⊃)⊃⌽'.'⎕VFI⍞
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862vNSK0riy1KLijPz8/6rK6gDJYPU9dQf9U4FsjQedS161DHjUeeiR20TgUjHUPtRV7MmED/q2QtS1Tc1zM3zUe@8/0CT/iuAAbKBXIZ6BnrGXAZcWKWM9Iz1TPRMuYywShvoGWDXiMM8A0Mc9nCZAwA "APL (Dyalog Unicode) – Try It Online")
`⍞` prompt for text input
`'.'⎕VFI` **V**erify and **F**ix **I**nput using period as field separator (fields' validities, fields' values)
`⌽` reverse (to put the values in front)
`⊃` pick the first (the values)
`⎕(`...`)` apply the following tacit function to that, using evaluated input as left argument:
To explain the non-tacit equivalents of each function application we will now use `⍺` to indicate the left argument (the index) and `⍵` to indicate the right argument (the list of individual numbers of the originally inputted current version number).
 `⊃` equivalent to `(⍺⊃⍵)` use `⍺` to pick an element from `⍵`
 `1+` add one to that 
 `↑,` equivalent to `(⍺↑⍵),` prepend `⍺` numbers taken from `⍵`
 `⊢∘≢↑` equivalent to `(⍺⊢∘≢⍵)↑` equivalent to `(≢⍵)↑` take as many numbers from that as there are elements in `⍵`, padding with zeros if necessary
`⍕` format (stringify with one space between each number)
`' '⎕R'.'` PCRE **R**eplace spaces with periods
[Answer]
# Java 8, 130 bytes
```
s->n->{String r="",a[]=s.split("\\.");for(int l=a.length,i=-1;++i<l;)r+=(i>n?0:new Long(a[i])+(i<n?0:1))+(i<l-1?".":"");return r;}
```
**Explanation:**
[Try it here.](https://tio.run/##lVDBbsIwDL3zFVZOidpaLWwXSstt0qTtxBF6yErowoJbJSkTQv32Lgy0y6SJST7Yz@/Zft7Lo0zaTtF@@zHWRjoHr1LTeQLgvPS6hn1gYO@1wV1Ptdct4dMtWay81dTEf3KeyatG2Riu5LKEGgoYXVJSUp6vINiCsViuq8Kh64z2nG02yES@ay3X5MEUEo2ixr/HukiyPIr0wuTCRgXXJS3TOalPeGmp4XKtKxFxvbigmfhOTZItGbI5CxOt8r0lsPkw5sFkiK5/M8Hnze6x1Vs4hBfw62nrCqS4vANgdXJeHbDtPXah5Q3xGmXXmRNnGaY4Y@JWpkLkd0imOMMHfPyRTe@SpZj@b9Gvu4bJMH4B)
```
s->n->{                 // Method with String and Integer parameters and String return-type
  String r="",          //  Result-String
  a[]=s.split("\\.");   //  String-array split by the dots
  for(int l=a.length,   //  Length of the array
      i=-1;++i<l;)      //  Loop from 0 to `l` (exclusive)
    r+=                 //   Append the result-String with:
       (i>n?            //    If index `i` is beyond input `n`:
        0               //     Append a zero
       :                //    Else:
        new Long(a[i])  //     Convert the current String to a number
        +(i<n?          //     If index `i` is before input `n`
           0            //      Leave the number the same by adding 0
          :             //     Else:
           1))          //      Add 1 to raise the version at index `n`
       +(i<l-1?         //    If we've haven't reached the last iteration yet:
          "."           //     Append a dot
         :              //    Else:
          ""            //     Append nothing
   );                   //  End of loop
   return r;            //  Return the result-String
}                       // End of method
```
[Answer]
# LiveScript, ~~53~~ 52 bytes
```
->(for e,i in it/\.
 [+e+1;0;e][(i>&1)+2*(i<&1)])*\.
```
-1 byte thanks to @ASCII-only!
Old Explanation:
```
(a,b)->x=a/\.;x[b]++;(x[to b] ++ [0]*(x.length-1-b))*\.
(a,b)->                                                 # a function taking a and b (version and index)
       x=a/\.;                                          # split a on dot, store in x
              x[b]++;                                   # increment at the given index
                     (x[to b]                           # slice be from 0 to the index
                              ++                        # concat (both spaces are necessary so it's not interpreted as an increment operator
                                 [0]*(x.length-1-b))    # with enough zeros to fill the array back to its original size (x's size)
                                                    *\. # join on dot
```
Another self-answer... Not that anyone golfes in LiveScript anyway. :P
I was working on another version:
```
(a,b)->(a/\.=>..[b]++;..[b to *]=0)*\.
```
But `*` is too overloaded to be recognized in a splicing index, thus `=0` will try to access `0[0]`. So you need to write something like `..[b to ..length- b]=[0]*(..length-1-b)` and it's longer in the end.
[Answer]
# [Haskell](https://www.haskell.org/), ~~136~~ 129 bytes
```
import Data.List.Split
import Data.List
f s n|(x,z:y)<-splitAt n(splitOn "."s)=intercalate "."(x++[show$read z+1]++map(\_->"0")y)
```
[Try it online!](https://tio.run/##XYuxCsIwFAB3v@IROiTEBludxAqCo@DgqCIPTWkwTUPywLb479E6uh3HXYPxqa1NybS@CwR7JFQHE0mdvDU0@9ezGiK4N@/n43oQmzxO1Y7A8R8dHTDFoqiMIx3uaJH0ZHgv5Tk23SsLGh8wyuIqZYueX275li2YGERq0TioAHz4zpBBDaxQpVqqFYMyfQA "Haskell – Try It Online")
---
[Original](https://tio.run/##XY09C8IwGAb3/oqH0CElGqw6CRUER8HBUUVeNKXBNA1JoB9/PlpHt@OGu4bCWxmTkm5d5yOOFEmedIjy4oyO2b/OagTYStuo/JMMRQUmGR@EuIam63Ov6IVJlHchWnL89lju2YoVY5EBfaO8Ah8W024sqjD3DxGW/@hs51AoUkvaogKc/06QowYr5Vpu5JahTB8 "Haskell – Try It Online")
[Answer]
# Pyth - 21 bytes
```
j\.++<Kcz\.Qhs@KQmZ>K
```
[Test Suite](http://pyth.herokuapp.com/?code=j%5C.%2B%2B%3CKcz%5C.Qhs%40KQmZ%3EK&test_suite=1&test_suite_input=2%0A1.2.3.4.5%0A0%0A10.0&debug=0&input_size=2)
]