How Many Hanukkah Candles?

The Festival of 1 + n + f(n-1) Lights

As Hanukkah approached and I gathered my holiday supplies, I ran through my list to make sure I had everything I needed. Latkes? Check. Chcoclate Gelt? Double check. Menorah? Check. Candles? Check.... I think? How many am i going to need? I phoned a friend, they weren't sure. Now, I could have just googled like any sane person, but at this point the question meant more than the answer. 

To me their was only one way I was going to answer this question: algorithmically.

#include <stdio.h>
#include <stdlib.h>

int candles(int n) {
	if (n < 1) {
        return 0;
    }
	return 1 + n + candles(n-1);
}

int main(int argc, char* argv[]) {
	printf("%d\n", candles(atoi(argv[1])));
}

The answer is 44. Happy Hanukkah!


Leave A Comment