Skip to main content
added 94 characters in body
Source Link
Asone Tuhid
  • 2.4k
  • 8
  • 22

Ruby, 240 237 233 bytes

#Ruby 240 237 bytes ThisThis is incredibly inefficient

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

  
->i{f=->n{n>0?n*f[n-1]:1}
s=->a{eval a.map{|i|f[i]}.inject:*?*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{while j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u]size<j[u].size&&break;u=g}size;u=g;end
j[u]}

Try it online!Try it online!

#Ruby 240 237 bytes This is incredibly inefficient

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

 
->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject:*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

Ruby, 240 237 233 bytes

This is incredibly inefficient

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

 
->i{f=->n{n>0?n*f[n-1]:1}
s=->a{eval a.map{|i|f[i]}*?*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
while j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size<j[u].size;u=g;end
j[u]}

Try it online!

deleted 81 characters in body
Source Link
Asone Tuhid
  • 2.4k
  • 8
  • 22

#Ruby 240 237 bytes This is incredibly inefficient and (on my computer at least) stalls when trying to calculate the last test case

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject:*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

#Ruby 240 237 bytes This is incredibly inefficient and (on my computer at least) stalls when trying to calculate the last test case

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject:*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

#Ruby 240 237 bytes This is incredibly inefficient

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject:*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

added 17 characters in body
Source Link
Asone Tuhid
  • 2.4k
  • 8
  • 22

#Ruby 240240 237 bytes This is incredibly inefficient and (on my computer at least) stalls when trying to calculate the last test case

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject(:*)}
r=->e,a=[2]{s[a]==e e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!Try it online!

#Ruby 240 bytes This is incredibly inefficient and (on my computer at least) stalls when trying to calculate the last test case

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject(:*)}
r=->e,a=[2]{s[a]==e ?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

#Ruby 240 237 bytes This is incredibly inefficient and (on my computer at least) stalls when trying to calculate the last test case

Accepts an array of ints as input

Returns a string and chooses the shortest option between, say, '720!','6!!' and '3!!!'

->i{f=->n{n>0?n*f[n-1]:1}
s=->a{a.map{|i|f[i]}.inject:*}
r=->e,a=[2]{e==s[a]?a:s[a]<=e&&(r[e,a[0..-2]+[a[-1]+1]]||r[e,a+[2]])}
j=->v{v.join(?!)+?!}
u=r[s[i]]
loop{j[g=u.map{|i|i&&r[i]?[r[i],p]:i}.flatten].size>j[u].size&&break;u=g}
j[u]}

Try it online!

Source Link
Asone Tuhid
  • 2.4k
  • 8
  • 22
Loading