14
Given 2 inputs, a string and a decimal number, 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 floor(n) time and then the first floor((n-floor(n))*len(string)) letters again.
Other notes:
- The input will not always be a float, it may be an int. So 1.5, 1, and 1.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 whitespace, quotes and other characters. No newlines or control chars though.
- No built-ins for direct string repeating, even string multiplication like the python
'a'*5are allowed. However string addition is allowed.
Test cases:
The comma & space separate the inputs.
test case, 1 -> test case
case, 2.5 -> casecaseca
(will add more later), 0.3333 -> (will(space)
cats >= dogs, 0.5 -> cats >
Final Note:
I am seeing a lot of answers that use builtin string multiplication or repeation functions. This is not allowed. @VTC's answer is valid though, because it does not multiply the string, only the float input. So the definitive rule is: If it directly multiplies the string, you can't do it.
The wording was modified repeatedly (I did not see the first revision). I suggest to remove
directstring repeating (what does this mean?). But all in all you're right – edc65 – 2016-02-08T16:10:16.9531Related quine version – Sp3000 – 2016-02-08T16:47:40.860
@Sp3000 yeah, I know. I think the difference is significant enough. – Rɪᴋᴇʀ – 2016-02-08T17:18:10.167
"No built-ins for direct string repeating, even string multiplication like the python 'a'*5 are allowed." You don't explain the difference between these. They sound the same to me. – msh210 – 2016-02-08T20:50:22.913
@edc65 In Perl you can do list repetition then concatenate the elements of that list, which isn't direct string repetition. In Perl 5:
join "", ("case") x 2vs"case" x 2, in Perl 6[~] "case" xx 2vs the same"case" x 2– Brad Gilbert b2gills – 2016-02-08T20:59:23.607@BradGilbertb2gills yes, that is allowed. So are stack duplication operators and number*number multiplication. – Rɪᴋᴇʀ – 2016-02-08T21:31:28.550