Given two inputs, a string \$s\$ and a decimal number \$n\$, output the string multiplied by that number.
The catch is that the number can be a float or an integer.
You should output the string \$\lfloor n \rfloor\$ times and then the first \$\lfloor (n - \lfloor n \rfloor) \cdot |\,s\,|)\rfloor\$ characters again.
Other notes:
- The input will not always be a float, it may be an integer.
So
1.5
,1
, and1.0
are all possible. It will always be in base 10 though, and if you wish an exception please comment. - The string input may contain white space except newlines, quotes and other characters. Control characters are excluded, too, if this helps.
- No built-ins for direct string repetition are allowed.
That means for instance Python’s
'a'*5
is forbidden. Nevertheless string concatenation (frequently denoted by the+
sign) is allowed.
Test cases
\$s\$ | \$n\$ | result |
---|---|---|
test case |
1 |
test case |
case |
2.5 |
casecaseca |
(will add more later) |
0.3333 |
(will |
cats >= dogs |
0.5 |
cats > |
Final Note
I am seeing a lot of answers that use builtin string multiplication or repetition functions. This is not allowed. The rule is: If it directly multiplies the string, you cannot do it.
direct
string repeating (what does this mean?). But all in all you're right \$\endgroup\$join "", ("case") x 2
vs"case" x 2
, in Perl 6[~] "case" xx 2
vs the same"case" x 2
\$\endgroup\$