pyth icon indicating copy to clipboard operation
pyth copied to clipboard

Implicitly round/floor float when multiplying with an array/string/etc.

Open xPMo opened this issue 7 years ago • 3 comments

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:

  1. round/floor before multiplying: *c5 2"ab" -> abab

  2. 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.

xPMo avatar Feb 10 '18 01:02 xPMo

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".)

Steven-Hewitt avatar Feb 10 '18 06:02 Steven-Hewitt

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.

ConorOBrien-Foxx avatar Feb 10 '18 17:02 ConorOBrien-Foxx

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?

Mr-Xcoder avatar Feb 10 '18 17:02 Mr-Xcoder