This recent puzzler was very successful with entries from four different continents. I can understand the busy researchers of Antarctica not joining in, but I expected to hear from Australia and Africa. The t-shirt orders have been sent out and should arrive soon.
The movies were all interesting in different ways. I hope to have highlights on the usability aspects up soon. However, I can comment immediately on the coding style that we saw. It always amazes me how differently people approach the problem.
Here was the problem statement:
What is the sum of all the natural numbers up to and including 1,000 that are multiples of 3 or 5?
There were a few skills needed to solve this problem:
- Decide if a number met the criteria for being a multiple of 3 or 5.
- Make sure numbers like 15 were not counted twice
- Sum these numbers
The most common methods for deciding if a number is a multiple of 3 or 5 were the commands:
For REM and MOD, if there was a non-zero return from the function, then the number should NOT be added to the sum, so there was usually a logical flip-flop with the ~ operator.
The two vector constructions would simply generate the numbers to be added directly
Next, the code needed to determine if there was an overlap of the sets of numbers above. Some people were dealing with two binary vectors (1’s if divisible and 0’s if not). They could use the | operator to do an OR. If not using a vector, but going through a FOR loop, they would use the || operator.
Once this final binary vector was constructed, the indexing would be of the form:
>> a = [1 2 3 4 5];
>> b = logical([0 0 1 0 1]);
Some of the people were carrying around vectors like [3 6 9 12 15] and [5 10 15]. For them, they could use the UNIQUE function to pull out the unique values and avoiding the double count of 15 and 30 and such. UNION served a very similar purpose.
The final step, adding the numbers was always done with SUM, if people were carrying around the vectors of numbers. If people were using for loops, then it was a simple accumulator with the
X = X+i type of construction.
Everyone that sent in a video found the correct answer, and as hoped, we saw a range of skills. Some people marched through without making so much as a typo, some people missed some of the productivity accelerators like using F5 to save and run a file, while some people struggled with syntax.
The struggles that we saw are very useful at design time in an effort to make MATLAB easier to use. Tools like the new function hints, m-lint and the function browser are all grown from things we observe in usability studies done at The MathWorks.
Thank you all for participating, and if you are in the Boston area, let us know, we often are looking for people to do full studies with longer challenges.
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.