Here’s the challenge we issued on May 3.
Many tried, but few succeeded in solving this puzzle. In fact, fewer than half (39 percent) of those who submitted answers were able to get the correct answer. Others found their way to the front of the line by sharing the coding challenge with friends.
Today we’re releasing the emails of those who solved the challenge and are sitting on their royal thrones right at the front of our waitlist.
See all the winners here.
— — — — — — — — — — — — — — — — — — — —
If you gave it a shot, but didn’t quite get the answer right, here’s the way the puzzle was solved:
Overall it looks like a python code snippet but also includes some pseudo-math type of expressions. Let’s start by taking apart this puzzle line by line.
Line 1
This line talks about a URL to the JSON file. If you open this URL with your browser, it should start like this.
{“date”: [“2015–07–10”, “2015–07–11”, “2015–07–12”, “2015–07–13”, “2015–07–14”, “2015–07–15”, “2015–07–16”, “2015–07–17”, “2015–07–18”, “2015–07–19”, “2015–07–21”, “2015–07–21”, “2015–07–22”, “2015–07–23”, “2015–07–24”, “2015–07–25”, “2015–07–26”, “2015–07–27”, “2015–07–28”, “2015–07–29”, “2015–07–31”, “2015–07–31”, “2015–08–01”, “2015–08–02”, “2015–08–03”, “2015–08–04”, “2015–08–05”, “2015–08–06”, “2015–08–07”, “2015–08–08”, “2015–08–09”, “2015–08–11”, “2015–08–11”, “2015–08–12”, “2015–08…
Yes, it is a JSON with keys of “date”, “open”, “high”, “low”, “close” and “volume”. Looks like some kind of historical price data. Makes sense. Alpaca is about algo trading.
Line 2
This line was apparently a bit tricky. The quiz meant to be as simple as literal python code to slice the string variable “file” and get “-100” as an integer but some people thought it was meant to slice the content of JSON file.
Line 3
MA here is the Moving Average function, which is a basic indicator derived from some historical price data, and typically it takes the input data and the time period of average as the parameters.
Line 4
Calculates MA but with unknown X, and X is the set of number that satisfies this condition.
Line 5
What is the minimum value in X?
In short, the puzzle is asking:
Using this historical price data (line 1), let m be the 5-day moving average of open prices on 100 days (line 2) before 04/01/2018 (line 3). Find the minimal (line 5) day moving average of close prices on the same day whose absolute difference from m is bigger than the fraction of square root 2 (line 4)?
If you use python and pandas, you can find the answer in a few tens of line of code with brute-force loop and get the answer of 61. This is the correct answer.