Post History
Python 3.8, 117 bytes def f(l): r,s,t=0,0,0 while s<len(l):_,s,t,r=[t:=max(t,(s+i+h)*(h>i))for i,h in enumerate(l[s:])],t,0,r+1 return r Try it online! The idea is to find the le...
Answer
#2: Post edited
# [Python 3.8 (pre-release)], 117 bytes- <!-- language-all: lang-python -->
- def f(l):
- r,s,t=0,0,0
- while s<len(l):_,s,t,r=[t:=max(t,(s+i+h)*(h>i))for i,h in enumerate(l[s:])],t,0,r+1
- return r
- [Try it online!][TIO-lp9oxfzp]
- The idea is to find the left-most uncovered spot, find the umbrella that cover as many spots to the right as possible. Repeat until no more uncovered spot.
- I'm sure this can be golfed further.
[Python 3.8 (pre-release)]: https://docs.python.org/3.8/- [TIO-lp9oxfzp]: https://tio.run/##bY3NCsIwEITvfYocE7uH/lm0WF@kFCmYkECblk2K@vQxqVWoyrDLMh@zMz2sHHV@mNC5KxdE0J5VEUEwYOsEvCJyk6rnxJx6rgO9BAZYN7aqh@5OLVATq1iyHZVnxZgYkSiQRGnC9Txw7CynfWOqlrU@mADGqW/gdkZN0E2otKWCNkfIIIXc7yJcLWPRh6Ww0YaFVLFOyG/p/uUtE1R@/c2Wxt@2f375dldlnron "Python 3.8 (pre-release) – Try It Online"
- # [Python 3.8], 117 bytes
- <!-- language-all: lang-python -->
- def f(l):
- r,s,t=0,0,0
- while s<len(l):_,s,t,r=[t:=max(t,(s+i+h)*(h>i))for i,h in enumerate(l[s:])],t,0,r+1
- return r
- [Try it online!][TIO-lp9oxfzp]
- The idea is to find the left-most uncovered spot, find the umbrella that cover as many spots to the right as possible. Repeat until no more uncovered spot.
- I'm sure this can be golfed further.
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-lp9oxfzp]: https://tio.run/##bY3NCsIwEITvfYocE7uH/lm0WF@kFCmYkECblk2K@vQxqVWoyrDLMh@zMz2sHHV@mNC5KxdE0J5VEUEwYOsEvCJyk6rnxJx6rgO9BAZYN7aqh@5OLVATq1iyHZVnxZgYkSiQRGnC9Txw7CynfWOqlrU@mADGqW/gdkZN0E2otKWCNkfIIIXc7yJcLWPRh6Ww0YaFVLFOyG/p/uUtE1R@/c2Wxt@2f375dldlnron "Python 3.8 (pre-release) – Try It Online"
#1: Initial revision
# [Python 3.8 (pre-release)], 117 bytes <!-- language-all: lang-python --> def f(l): r,s,t=0,0,0 while s<len(l):_,s,t,r=[t:=max(t,(s+i+h)*(h>i))for i,h in enumerate(l[s:])],t,0,r+1 return r [Try it online!][TIO-lp9oxfzp] The idea is to find the left-most uncovered spot, find the umbrella that cover as many spots to the right as possible. Repeat until no more uncovered spot. I'm sure this can be golfed further. [Python 3.8 (pre-release)]: https://docs.python.org/3.8/ [TIO-lp9oxfzp]: https://tio.run/##bY3NCsIwEITvfYocE7uH/lm0WF@kFCmYkECblk2K@vQxqVWoyrDLMh@zMz2sHHV@mNC5KxdE0J5VEUEwYOsEvCJyk6rnxJx6rgO9BAZYN7aqh@5OLVATq1iyHZVnxZgYkSiQRGnC9Txw7CynfWOqlrU@mADGqW/gdkZN0E2otKWCNkfIIIXc7yJcLWPRh6Ww0YaFVLFOyG/p/uUtE1R@/c2Wxt@2f375dldlnron "Python 3.8 (pre-release) – Try It Online"