pyth
pyth copied to clipboard
Implicitly round/floor float when multiplying with an array/string/etc.
An answer to a recent challenge had to floor a float in order to multiply by a string. If a floor is not explicitly provided, Pyth simply errors out.
There are two directions that this can go:
-
round/floor before multiplying:
*c5 2"ab"->abab -
append that fraction (rounded/floored) of the string/list:
*c5 2"ab"->ababa
I don't know which way would be better, but either way shouldn't cause any regressions.
I wouldn't quite call my answer recent, but this could be a nice change.
However, I'd recommend keeping the old behavior on one of the two permutations (preferably * <num> <seq>, so that we can hack a check for floats with .x*TG (where we're checking T for floatiness, and G is the current global value of "abc...yz".)
I'm not a Pyth expert, but wouldn't is just be better to have a float check builtin? IIRC there are some open commands.
I think we shouldn't go with rounding, because it can be rather confusing. Honestly, I think it should floor the argument. Regarding float check, it's not too hard to do it without a dedicated command (!sI). I think this functionality can be extended to:
- Indexing (
@). - Get first N (
<) - Remove first N (
>) - Cyclic rotations (
.<and.>)
And perhaps even more. Another version for @ would be to return the elements at indices floor(argument) and ceil(argument), similar to how Jelly does it. What do you think?