12
1
Inspired by this conversation in chat.
Your goal in this challenge is to emulate a ninja and count how many deaths he has left.
Specs
You ninja starts out with 9 deaths left. He also gets an integral starting health as an input.
Then, he takes as input a list of events in his life that alter his health. These can be negative, positive, or zero integers.
At any point, if his health reaches at or below zero, he loses a life and his health goes back to the starting health.
Your program should report the number of deaths he has left. If he has zero or less left, you should output dead
instead.
This is code-golf, so shortest code in bytes wins!
Test Cases
3, [] -> 9
100, [-20, 5, -50, 15, -30, -30, 10] -> 8
10, [-10, -10, -10, -10] -> 5
10, [-10, -10, -10, -10, -10, -10, -10, -10, -10] -> dead
0, [] -> dead
0, [1] -> dead
100, [10, -100] -> 9
1YAY!!! My chat post is linked!!! :P – Rɪᴋᴇʀ – 2016-01-09T02:35:53.777
8Looks like I'm in trouble... – NinjaBearMonkey – 2016-01-09T02:48:49.937
So the order of events is "die if <=0, read a number, add to total, repeat"? – lirtosiast – 2016-01-09T02:56:20.703
@ThomasKwa yeah, but the dying can happen multiple times – Maltysen – 2016-01-09T02:57:12.077
1Can ninjas regenerate like time lords? Please? – Ashwin Gupta – 2016-01-09T07:20:16.333
Can the starting health be negative? – ETHproductions – 2016-01-09T14:08:41.123