Skip to main content
2 of 3
added 293 characters in body
xnor
  • 146.6k
  • 26
  • 279
  • 652

##Python 2, 45 bytes

f=lambda l:l==[]or l[len(l)/2-1]/l.pop()*f(l)

Outputs 0 for Falsy, nonzero for Truthy.

Checks that the last element is less than or equal to its parent at index len(l)/2-1. Then, recurses to check that the same is True with the last element of the list removed, and so on until the list is empty.


48 bytes:

f=lambda l,i=1:l==l[:i]or l[~-i/2]/l[i]*f(l,i+1)

Checks that at each index i, the element is at most its parent at index (i-1)/2. The floor-division produces 0 if this is not the case.

Doing the base case as i/len(l)or gives the same length. I had tried zipping at first, but got longer code (57 bytes).

lambda l:all(map(lambda a,b,c:b<=a>=c,l,l[1::2],l[2::2]))
xnor
  • 146.6k
  • 26
  • 279
  • 652