Skip to main content
added 2 characters in body
Source Link
nwellnhof
  • 10.6k
  • 1
  • 19
  • 38

Perl 6 -p-p, 57 41 bytes

$!=m/\./.to;.=substr(0,$!+$/)while m:c/./

Try it online!

Explanation

$!=m/\./.to;       # Store position of decimal point in $!
.=substr(0,$!+$/)  # Truncate string to length $!+$/
while m:c/./       # while there's a match for the next digit

Perl 6 -p, 57 41 bytes

$!=m/\./.to;.=substr(0,$!+$/)while m:c/./

Try it online!

Explanation

$!=m/\./.to;       # Store position of decimal point in $!
.=substr(0,$!+$/)  # Truncate string to length $!+$/
while m:c/./       # while there's a match for the next digit

Perl 6 -p, 57 41 bytes

$!=m/\./.to;.=substr(0,$!+$/)while m:c/./

Try it online!

Explanation

$!=m/\./.to;       # Store position of decimal point in $!
.=substr(0,$!+$/)  # Truncate string to length $!+$/
while m:c/./       # while there's a match for the next digit
deleted 5 characters in body
Source Link
nwellnhof
  • 10.6k
  • 1
  • 19
  • 38

Perl 6 -p, 57 4441 bytes

{$!=m/\./.to;.=substr(0,$!+$/)while m:c/\d./}

Try it online!

Modifies a string in-place.Try it online!

Explanation

{
 $!=m/\./.to;       # Store position of decimal point in $!
 .=substr(0,$!+$/)  # Truncate string to length $!+$/
 while m:c/\d./       # while there's a match for the next digit
}

Perl 6, 57 44 bytes

{$!=m/\./.to;.=substr(0,$!+$/)while m:c/\d/}

Try it online!

Modifies a string in-place.

Explanation

{
 $!=m/\./.to;       # Store position of decimal point in $!
 .=substr(0,$!+$/)  # Truncate string to length $!+$/
 while m:c/\d/      # while there's a match for the next digit
}

Perl 6 -p, 57 41 bytes

$!=m/\./.to;.=substr(0,$!+$/)while m:c/./

Try it online!

Explanation

$!=m/\./.to;       # Store position of decimal point in $!
.=substr(0,$!+$/)  # Truncate string to length $!+$/
while m:c/./       # while there's a match for the next digit
deleted 247 characters in body
Source Link
nwellnhof
  • 10.6k
  • 1
  • 19
  • 38

Perl 6, 5757 44 bytes

{S[\$!=m/\.<(/.to;.=substr(\d0,$!+$/)*]=[~] $0[^reducewhile {$^a>($^b&++$)??$b!!$a},$0]m:c/\d/}

Try it online!Try it online!

Modifies a string in-place.

Explanation

{
 S[          # replace regex match
   $!=m/\.        #   literal dot
   <(        #   start match
 /.to;  (\d)*     #  Store sequenceposition of digits,decimal storedpoint in $0
 ]=          # with
 [~]         #   concatenation of
 $0[^        #   digits up to
   reduce {          # reduce digits$!
     $^a>.=substr($^b&++$0,$!+$/)   # if digit andTruncate indexstring lessto thanlength acc$!+$/
     ??$b     while m:c/\d/      # then digit
     !!$a           while #there's elsea accumulator
match for the },$0
next ]digit
}

Perl 6, 57 bytes

{S[\.<((\d)*]=[~] $0[^reduce {$^a>($^b&++$)??$b!!$a},$0]}

Try it online!

Explanation

{
 S[          # replace regex match
   \.        #   literal dot
   <(        #   start match
   (\d)*     #   sequence of digits, stored in $0
 ]=          # with
 [~]         #   concatenation of
 $0[^        #   digits up to
   reduce {          # reduce digits
     $^a>($^b&++$)   # if digit and index less than acc
     ??$b            # then digit
     !!$a            # else accumulator
   },$0
 ]
}

Perl 6, 57 44 bytes

{$!=m/\./.to;.=substr(0,$!+$/)while m:c/\d/}

Try it online!

Modifies a string in-place.

Explanation

{
 $!=m/\./.to;       # Store position of decimal point in $!
 .=substr(0,$!+$/)  # Truncate string to length $!+$/
 while m:c/\d/      # while there's a match for the next digit
}
Source Link
nwellnhof
  • 10.6k
  • 1
  • 19
  • 38
Loading