Post History
Python 3, 35 bytes f=lambda x,i=1:x>0and-~f(x-1/i,i+1) Try it online! Subtracts each 1/i in turn from the initial value until the result is no longer positive.
Answer
#2: Post edited
- # [Python 3], 35 bytes
- <!-- language-all: lang-python -->
- f=lambda x,i=1:x>0and-~f(x-1/i,i+1)
- [Try it online!][TIO-khopivsg]
- [Python 3]: https://docs.python.org/3/
[TIO-khopivsg]: https://tio.run/##K6gsycjPM/7/P802JzE3KSVRoUIn09bQqsLOIDEvRbcuTaNC11A/UydT21Dzf1p@kUKFQmaeQrShjpGOsY5JrBUXZ0FRZl6JggZQoabmfwA "Python 3 – Try It Online"
- # [Python 3], 35 bytes
- <!-- language-all: lang-python -->
- f=lambda x,i=1:x>0and-~f(x-1/i,i+1)
- [Try it online!][TIO-khopivsg]
- [Python 3]: https://docs.python.org/3/
- [TIO-khopivsg]: https://tio.run/##K6gsycjPM/7/P802JzE3KSVRoUIn09bQqsLOIDEvRbcuTaNC11A/UydT21Dzf1p@kUKFQmaeQrShjpGOsY5JrBUXZ0FRZl6JggZQoabmfwA "Python 3 – Try It Online"
- Subtracts each `1/i` in turn from the initial value until the result is no longer positive.
#1: Initial revision
# [Python 3], 35 bytes <!-- language-all: lang-python --> f=lambda x,i=1:x>0and-~f(x-1/i,i+1) [Try it online!][TIO-khopivsg] [Python 3]: https://docs.python.org/3/ [TIO-khopivsg]: https://tio.run/##K6gsycjPM/7/P802JzE3KSVRoUIn09bQqsLOIDEvRbcuTaNC11A/UydT21Dzf1p@kUKFQmaeQrShjpGOsY5JrBUXZ0FRZl6JggZQoabmfwA "Python 3 – Try It Online"