We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def workbook(_, k, arr):
p = s = 0
for i in arr:
for j in range(0, i, k):
p, s = ((p + 1, s + 1)
if j < p + 1 <= min(i, j + k)
else (p + 1, s))
return s
Here's a semi-short, non-looping functional solution…
It could be shorter, but I've seen people complain about the readability of functional code. So, I tried to make this descriptive. I used verbose names for lambda arguments. I also added lambdas for accessing the members of tuples returned from the inner map levels.
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →
Python: Semi-short looping solution…
Here's a semi-short, non-looping functional solution…
It could be shorter, but I've seen people complain about the readability of functional code. So, I tried to make this descriptive. I used verbose names for lambda arguments. I also added lambdas for accessing the members of tuples returned from the inner map levels.
Here's a terse version of the same code…