Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

##Ruby, (削除) 88 (削除ここまで) 87 bytes

Ruby, (削除) 88 (削除ここまで) 87 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map! &:to_i)while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map! &:to_i # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

##Ruby, (削除) 88 (削除ここまで) 87 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map! &:to_i)while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map! &:to_i # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

Ruby, (削除) 88 (削除ここまで) 87 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map! &:to_i)while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map! &:to_i # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}
added 11 characters in body
Source Link

##Ruby, 88(削除) 88 (削除ここまで) 87 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!(&:to_i))while i[0]
o}

Try it online. Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!(&:to_i) # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

##Ruby, 88 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!(&:to_i))while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!(&:to_i) # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

##Ruby, (削除) 88 (削除ここまで) 87 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!&:to_i)while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!&:to_i # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}
added 56 characters in body
Source Link

##Ruby, 88 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!(&:to_i))while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!(&:to_i) # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

##Ruby, 88 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!(&:to_i))while i[0]
o}

Try it online.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!(&:to_i) # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}

##Ruby, 88 bytes

f=->i{o=[]
(s,l,*i=i
r=s...s+l
o[r]=[([*o[r]]+[0]).max+1]*l
o.map!(&:to_i))while i[0]
o}

Try it online.

Inspired by grc's answer, but in a different language and just slightly shorter.

Explanation:

f=->i # lambda with parameter i, expects array of ints
{
 o=[] # output
 (
 s,l,*i=i # pop start and length
 r = s...s+l # range is used twice, so shorten it to 1 char
 o[r] =
 [(
 [*o[r]] # o[r] returns nil if out of bounds, so splat it into another array
 +[0] # max doesn't like an empty array, so give it at least a 0
 ).max+1]*l # repeat max+1 to fill length
 o.map!(&:to_i) # replace nil values with 0
 ) while i[0] # i[0] returns nil when i is empty, which is falsy
 o # return o
}
Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /