Our team participated in a remote trivia event this week, of course using Coda docs to collaborate on answers.
One of the questions referred to the song “The Twelve Days of Christmas”. If you haven’t heard it, the lyrics run through a list of gifts each day. (Full lyrics here.) The question asked: How many gifts were given in this song?
The general idea is that on the first day, you receive 1 gift of x. On the second day, you receive 2 gifts of y and 1 gift of x. On the third, you receive 3 gifts of z, 2 gifts of y, and 1 gift of x.
Hint: Gauss figured this out in elementary school (sort of)
Other hint: It’s also related to the number of edges in a fully connected graph
Edit: I was wrong. It’s the triangular numbers, not the number of edges in a fully connected graph
As Paul said before deleting their post (not sure why?), there is also a way to do it without FormulaMap
Also, @Breno_Nunes, it might be nice to blur your answers to save people from the spoilers in case they want to take a shot. You can do that like this:
I got confused at first. To simply calculate the sum of 1 + 2 + … + N, there’s an arithmetic progression sum formula (1 + N) * (N / 2) (because 1+13 + 2+11 + 3+10… i.e. 13 x half the numbers.
But then I saw that I had to sum the progressions themselves as well. So this formula isn’t really relevant here.
I still have a feeling that it can be simplified to a polynomial that doesn’t have to use loops
I guess this is similar to @Breno_Nunes’ first solution, except WithName allows us to reuse the initial array and take slices of it, instead of making a new one.
One of the nice things about WithName is it helps to make formulas a bit more self-documenting