Tolong lepaskan saya!

34

Sebagai pegolf kode, kami tidak terbiasa melepaskan ( pasti ). Kami akan membutuhkan beberapa alat untuk membantu kami melakukan itu.

Tentu saja, untuk membantu memasarkan rilis baru, kami membutuhkan Versi Rilis yang bagus dan berkilau. Siapa yang tidak senang ketika mereka mendengar tentang versi 3.0.0?

Tugas

Tugas Anda adalah menulis program / rutin / ... untuk menambah nomor versi.

Anda perlu menambah nomor versi dan mengatur ulang yang "kurang penting" (yaitu versi tambalan).

Anda mendapatkan dua argumen: versi saat ini (ex "1.0.3") sebagai string, dan indeks untuk mengetahui mana yang akan diperbarui (0 atau 1-diindeks).

Contoh, diindeks 0:

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

Versi ini adalah string, setiap bagian adalah angka, dipisahkan dengan titik. Tidak ada titik awal, tidak ada jejak atau tidak ada titik berurutan (dan tidak ada di luar angka / titik). Tidak ada batasan ukuran string versi.

^[1-9]\d*(\.[1-9]\d*)*$

Kasus kesalahan (dua contoh terakhir) adalah perilaku yang tidak terdefinisi. Apa yang terjadi jika input yang salah tidak ada hubungannya dengan tantangan ini.

Seperti biasa, lubang standar dilarang. Anda diizinkan mencetak atau mengembalikan string.

Yang Mulia
sumber
1
Bisakah kita meminta untuk menerima sebagai input pertama indeks dan kemudian nomor versi?
Leo
@ Leo ya, pesanan tidak menjadi masalah.
Ven
Saya mungkin menambahkan test case untuk menambah angka akhir dalam string, atau contoh atau sesuatu untuk diuji.
nmjcman101
@ nmjcman101 bagaimana ini kasus khusus?
Ven
3
Saya berharap saya bisa membuat tantangan yang sama dengan kondisi menang sebagai "paling mudah dibaca" sehingga seseorang akan menulis ini untuk saya gunakan dalam pekerjaan nyata. =)
jpmc26

Jawaban:

12

Japt, 16 11 byte

¡V«´V+ÂX}'.

Uji secara online! Nomor input diindeks 1.

Berdasarkan jawaban JavaScript saya. Ini mengambil keuntungan dari salah satu fitur Japt yang paling membantu: memisahkan satu string pada yang lain sebelum memetakan setiap item, kemudian bergabung pada string itu lagi setelah memetakan.

Tanpa penjelasan dan penjelasan

¡  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
Produksi ETH
sumber
2
Sungguh fitur yang manis!
Jonathan Allan
1
Ya ampun, saya pikir saya sudah di tas. Maaf, saya akan terobsesi dengan jawaban V saya dan memeras setiap byte terakhir dari itu. : P
DJMcMayhem
11

Vim 20 25 byte

Sayangnya saya menyadari bahwa itu tidak menangani kasus memperbarui nomor terakhir, jadi saya harus menambahkan byte. Ini 1-diindeks.

DJA.0@"t.qq2wcw0@qq@qx

TryItOnline

Tidak dapat dicetak:

DJA.^[0@"t.^Aqq2wcw0^[@qq@qx

Ini mengambil argumen dalam urutan terbalik, sebagai baris terpisah:

3
1.2.3.4.5

Penjelasan:

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 '.'
nmjcman101
sumber
1
Bagus! Penjelasan akan sangat membantu
Kritixi Lithos
@KritixiLithos Ditambahkan. Sayangnya saya harus menambahkan beberapa byte juga untuk menangani penambahan nomor versi final, tetapi itu terjadi.
nmjcman101
Saya pikir jika Anda pergi 0-diindeks, Anda hanya bisa melakukan DJ@"t.<C-a>qq2wcw0<esc>@qq@qyang kembali ke dua puluh
DJMcMayhem
@DJMcMayhem Saya tidak berpikir saya bisa melakukan itu karena saya tidak akan bisa membedakan 0 dan 1.
nmjcman101
1
Oh ya, poin bagus. Bagaimana dengan DJ@"f.@"<esc><C-a>qq2wcw0<esc>@qq@q?
DJMcMayhem
11

JavaScript (ES6), 44 42 40 37 byte

Disimpan 3 byte berkat @Neil

x=>i=>x.replace(/\d+/g,n=>i&&+n+!--i)

Nomor input diindeks 1.

Cuplikan tes

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))

Produksi ETH
sumber
2
Dicoret
1
@KritixiLithos Apa yang salah dengan browser saya? cubeupload.com/im/ofJySU.png
Gustavo Rodrigues
n=>i&&+n+!--i
Neil
@Neil Terima kasih! Saya hanya tidak tahu bagaimana cara membuat ekspresi itu lebih jauh ...
ETHproduksi
10

V , 13 , 12 byte

Àñf.ñò2wcw0

Cobalah online!

Ini diindeks 0.

Ada ctrl-a(ASCII 0x01) di sana, jadi di sini adalah versi yang dapat dibaca:

Àñf.ñ<C-a>ò2wcw0

Penjelasan:

À                   " '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'
DJMcMayhem
sumber
7

Perl, 40 37 34 + 1 = 35 byte

-2 byte terima kasih kepada @Dada. -3 byte berkat ide yang saya dapatkan dari membaca kode Japt @ ETHproductions.

Jalankan dengan -pbendera.

$a=<>;s/\d+/$a--<0?0:$&+!($a+1)/ge

Cobalah online!

Rincian kode

-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
Gabriel Benamy
sumber
Hapus semua tanda kurung di kedua sisi! (dan $&bukannya $1itu)
Dada
Saya tahu saya kehilangan sesuatu! Terima kasih!
Gabriel Benamy
Menggunakan angka 1-diindeks dapat menghemat 4 byte: Cobalah secara online!
Xcali
5

Jelly , 19 17 byte

ṣ”.V€‘⁹¦µJ’<⁹×j”.

1-diindeks.

TryItOnline!

Bagaimana?

ṣ”.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 '.'
Jonathan Allan
sumber
3
Selamat atas 10k !!
Luis Mendo
Tidak bisa menunggu Jelly 2.0 sehingga Anda dapat menyingkirkannya V€:).
Ven
@LuisMendo - terima kasih! Saya sangat tidak patuh (Dennis memperhatikan tonggak 1K saya sebelum saya juga).
Jonathan Allan
5

MATLAB, 85 byte

function f(s,j);a=split(s,'.');a(j)=string(double(a(j))+1);a(j+1:end)='0';join(a,'.')

Satu upaya berbasis golf pertama!

MattWH
sumber
Well done! First time I see the new string type in action :-)
Luis Mendo
5

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

JustinM - Reinstate Monica
sumber
You don't need the string and int in the anonymous function signature
TheLethalCoder
@TheLethalCoder ahh yes of course, thanks.
JustinM - Reinstate Monica
4

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)
Kade
sumber
4

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

Unprintables:

DJA.^[0@"t.^Aò2wcw0^[òx

This takes the arguments in reverse order, as separate lines:

3
1.2.3.4.5
nmjcman101
sumber
1
Nice answer! I'm always happy to see someone else use V! Just so you know, if you put the first input in 'args', it will predefine register 'a' to that number, so you could do @a (or even shorter, À) which should save you a bunch of bytes.
DJMcMayhem
4

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.

Neil
sumber
4

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
Ven
sumber
3
Just fyi, self answers are totally eligible. In fact, they're even encouraged
DJMcMayhem
@DJMcMayhem I knew about this, but I thought they were not eligible
Ven
3

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.

briantist
sumber
2

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=".")
rturnbull
sumber
2

05AB1E, 22 bytes

'.¡vy²N‹i0*}²NQi>})'.ý

Try it online!

I don't know how to do if-else in 05AB1E, so this is longer than it should be.

Magic Octopus Urn
sumber
1
If I'm not misunderstanding, I don't think this works. The question says you have to 0-out the minor versions, so 1.0.0.0.3, 3 should produce 1.0.0.1.0 not 1.0.0.1.3.
LambdaBeta
@LambdaBeta misread, fixed.
Magic Octopus Urn
2

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!

Lord Ratte
sumber
Nice! Not sure you need the parseInt here though?
Ven
Btw you can save two bytes by using parenless calls (i.e. .join '.' or .split '.')
Ven
Use + instead of parseInt (use ~~ if you need it to be cast to integer)
Cyoce
2

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

Jeffrey04
sumber
2

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.

Titus
sumber
2

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.

Florrie
sumber
Okay, that wasn't terribly clear, thanks.
Florrie
1

Pyth - 21 bytes

j\.++<Kcz\.Qhs@KQmZ>K

Test Suite

Maltysen
sumber
3
No, this isn't quite correct. Your 10.0 test case gives 11.0.0, that's one too many part!
Ven
1

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.
colsw
sumber
Nice! I love seeing more powershell here.
briantist
@briantist honestly a lightweight uncompiled version of C# which can interface with everything is a godsend, I deal with a lot of Microsoft stuff at work and absolutely love it.
colsw
Oh absolutely; PowerShell is my jam, but not a lot of people think to use it for golfing. It has some features that are great for golfing, and others that make it suck for golfing, but overall it's a solid choice! I'm toying with the idea of doing a presentation about golfing in PowerShell at my next PSUG.
briantist
@briantist the default aliases are beautiful, but I'd love to be able to use a pre-defined set of a few common commands as single char aliases f for golfing, if say it could compete with some actual golfing languages if we could use r instead of random
colsw
Funny thing about random, it's not an an alias! It's a result of PowerShell's command evaluation. As it looks to find a command in aliases, functions, cmdlets, native applications, etc., the very last thing it tries to do is prepend Get- to whatever it is. So you're actually calling Get-Random, but technically not as an alias. You can see this working by running service, or childitem, or for maximum irony, alias.
briantist
1

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
Zhigang An
sumber
Welcome to CodeGolf. In the title, You should tell the size of the source code, not the byte code. And the source should, of course, be as short as possible (no unnecessary whitespace, single character variable names etc.). Good Luck.
Titus
can probably use 0 instead of NULL and remove the return 0; at the end of the main. NSString *s can probably have the space removed. **argv is 1 byte shorter than *argv[]. @autoreleasepool{} is probably unnecessary.
Ven
1

Javascript ES6: 60 bytes

n.split(".").map((n,r)=>{return r>i?n=0:n}).join("."),n[i]++}
Jack
sumber
2
Welcome to PPCG! This doesn't seem to be valid, as it is does not take input in any way, and there is an extra } at the end. On golfing: one of the features of arrow functions is implicit return, so you can replace (n,r)=>{return r>i?n=0:n} with (n,r)=>r>i?n=0:n to save some bytes.
ETHproductions
1

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.

plannapus
sumber
1

APL (Dyalog), 31 bytes

Requires ⎕IO←0 (Index Origin 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!

 prompt for text input

'.'⎕VFIVerify and Fix Input 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 Replace spaces with periods

Adám
sumber
1

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.

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
Kevin Cruijssen
sumber
1

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.

Ven
sumber
1
sadly f=(a,b)->(for e,i in a/\.<newline> if i<b then e else if i>b then 0 else+e+1)*\. is way longer :(
ASCII-only
@ASCII-only I think it's possible to compress if i<b then e else if i>b then 0 else+e+1 in i.e. [+e+1;0;e;e][i>b+(2*i<b)] or something along those lines, maybe even ([+e;-1][i>b+(2*i<b)]||e-1)+1
Ven
(a,b)->(for e,i in a/\.<newline> [+e+1;0;e][(i>b)+2*(i<b)])*\., 54
ASCII-only
Then let's remove the signature: ->(for e,i in it/\.<newline> [+e+1;0;e][(i>&1)+2*(i<&1)])*\. for 52
Ven
btw you can replace ; with space. also... looks like that's basically as far down as it'll go with this approach
ASCII-only
1

Haskell, 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!


Original

bugs
sumber
128
ASCII-only