Skip to main content
added 910 characters in body
Source Link
Jordan
  • 11.9k
  • 1
  • 36
  • 56

Ruby, 139 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),*$'[0]&&$'.ljust(4b,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!Attempt This Online!

Explanation

f = ->n,b,i=1{ # Recursive lambda definition; n is the number, b is the target length, i is the number of iterations c = [ # Make an array of... *n.scan(/.{#{b=b.to_i}}/), # the whole sections of length b *$'[0] && $'.ljust(b, ?1) # plus, if there’s stray letters, the final section padded to length b ].map{ _1.chars.map(&:to_i).reduce :* # Multiply each section’s digits } * "" # Join back together c.size < b ? # If we’re under the target length... [c, i] : # return the remaining string and iteration count f[c, b, i+1] # otherwise call itself recursively, incrementing the iteration count } p f[*$*] # $* is ARGV; splat it into f's arguments 

Ruby, 139 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),*$'[0]&&$'.ljust(4,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

Ruby, 139 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),*$'[0]&&$'.ljust(b,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

Explanation

f = ->n,b,i=1{ # Recursive lambda definition; n is the number, b is the target length, i is the number of iterations c = [ # Make an array of... *n.scan(/.{#{b=b.to_i}}/), # the whole sections of length b *$'[0] && $'.ljust(b, ?1) # plus, if there’s stray letters, the final section padded to length b ].map{ _1.chars.map(&:to_i).reduce :* # Multiply each section’s digits } * "" # Join back together c.size < b ? # If we’re under the target length... [c, i] : # return the remaining string and iteration count f[c, b, i+1] # otherwise call itself recursively, incrementing the iteration count } p f[*$*] # $* is ARGV; splat it into f's arguments 
Fix bug
Source Link
Jordan
  • 11.9k
  • 1
  • 36
  • 56

Ruby, 131139 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),$'*$'[0]&&$'.ljust(4,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!Attempt This Online!

Ruby, 131 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),$'.ljust(4,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

Ruby, 139 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),*$'[0]&&$'.ljust(4,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

deleted 3 characters in body
Source Link
Jordan
  • 11.9k
  • 1
  • 36
  • 56

Ruby, 144131 bytes

f=->n,b,i=1{c=nc=[*n.scan (/.{1,#{b=b.to_i}}/ c[-1]=c[-1]),$'.ljust (4,?1 c=c)].map{|e|e_1.chars.reducemap(1&:to_i){_1*_2.to_i}reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!Attempt This Online!

Ruby, 144 bytes

f=->n,b,i=1{c=n.scan /.{1,#{b=b.to_i}}/ c[-1]=c[-1].ljust 4,?1 c=c.map{|e|e.chars.reduce(1){_1*_2.to_i}}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

Ruby, 131 bytes

f=->n,b,i=1{c=[*n.scan(/.{#{b=b.to_i}}/),$'.ljust(4,?1)].map{_1.chars.map(&:to_i).reduce:*}*"" c.size<b ?[c,i]:f[c,b,i+1]} p f[*$*] 

Attempt This Online!

Source Link
Jordan
  • 11.9k
  • 1
  • 36
  • 56
Loading