Enthusiastically Russianify a String
Perl 6, 21 bytes
{$^a~")"x$^b*$a.comb}
Jelly, 7 bytes
ȮL×Ċ”)x
Try it online!
Uses the decimal format.
How?
ȮL×Ċ”)x - Main link: string, decimal
Ȯ - print string
L - length(string)
× - multiply by the decimal
Ċ - ceiling (since rounding method is flexible)
”) - a ')' character
x - repeated that many times
- implicit print
Common Lisp, 59 52 50
Parentheses? I am in.
(lambda(s n)(format()"~a~v@{)~}"s(*(length s)n)0))
Details
(lambda(s n) ; two arguments (string and ratio)
(format () ; format as string
"~a~v@{)~}" ; control string (see below)
s ; first argument (string)
(* (length s) n) ; second argument (number of parens)
0)) ; one more element, the value does not matter
Format control string
~a
: pretty print argument (here the given string)~v@{...~}
: iteration block, limited to V iteration, where V is taken as an argument, namely the(* ...)
expression. The iteration is supposed to iterate over a list, but when you add the@
modifier, the list is the remaining list of arguments to the format function. There must be at least one element in the iterated list (otherwise we exit, disregarding V). That is why there is an additional argument to format (0).
Since no element in the list is consumed by the format, the loop is infinite but fortunately, it is also bounded by V, a.k.a. the number of parentheses to be printed.
Edit: thanks to Michael Vehrs for pointing out that there is no need to round the numerical argument (the question allows to truncate/round however we want, so the default behavior works here).