Bookkeeping for the Sex Bob-ombs (check if a running sum ever gets too low)

Haskell, 22 bytes

f t=all(>=t).scanl(+)0

Usage: f (-5) [4,-3,-6] which outputs True.

Make a list of sub-totals and check if all elements are >= t.

Edit: Bugfix for empty list and positive ts


Python 2, 41

f=lambda a,t:t<=0<(a and f(a[1:],t-a[0]))

The first argument is the array; the second is the minimum running total.


J, 11 bytes

   */@:<:0,+/\

Tests

   _5 (*/@:<:0,+/\)  1 2 3 _20
0
   _5 (*/@:<:0,+/\)  >a: NB. empty list
1

1-byte improvement thanks to FUZxxl.

Explanation for the original version (*/@(<:0,+/\))

  • +/\ creates a running sum (sum +/ of prefixes \)
  • 0,+/\ appends a 0 to the running sum
  • (<:0,+/\) left side input smaller or equal <: than (elements of of the) result of 0,+/\ on the right side input
  • @ with the previous result
  • */ product of all elements (1 if all elements are 1, 0 if an element is 0)