Cody™ is a MATLAB game that challenges and expands your knowledge of MATLAB. It is a web service provided to the community in which you sharpen your programming skills by solving problems and interacting with the community. You can comment on any problem or solution and learn from solutions provided by others. Or you can challenge the community by contributing problems that you devise. To play, you need a Community Profile.
On the Problems page there are two problem groups: Community and Cody Challenge. The Community group contains all problems contributed by Cody players. The Cody Challenge group starts with three problems added by the Cody administrator and unlocks more problems as you solve them. You can browse or solve problems in either group.
When you see an interesting problem, click the Solve This Now! button. Don't worry about hurting your score or your pride by submitting an incorrect answer. Other players do not see your name with an incorrect solution, nor does it affect your score.
Let's say you choose to solve this problem in the Community Challenge group:
Given an input number x, return the output value x+1.
Cody always gives you a starting point, or function template. In this case, the function template is
function y = plus_one(x)
y = x;
end
The function template does not return the correct answer; in this example, you need to add +1 to make it work, as shown below.
function y = plus_one(x) y = x+1; end
When you submit this code, you will get the correct answer. Now try your hand at another problem.
Initially, you see only three Cody Challenge problems. Each time you solve one, Cody unlocks three more. The more you solve, the more you reveal.
Cody calculates a size for each solution. When you submit a correct answer to a problem, you can see other solutions of the same size (that is, the same length or longer), but not shorter solutions.
Each time you solve a new problem, you unlock all solutions to your previously solved problems in the same group.
Cody uses a node-count calculation to determine the solution size based on the number of nodes in the parse tree. Think of size as code length. Writing succinct code earns you a better result. Comments do not contribute to code size.
To illustrate how Cody determines size, here are two solutions to the plus-one problem. Solution 1 has a size of 12. Solution 2 has a size of 16. Both functions return the correct answer, but the first solution provides the better score due to its smaller size.
function y = plus_one(x) y = x+1; end
function y = plus_one(x) z = x; y = z+1; end
You can find the official scoring code on File Exchange.
Any Cody player can Challenge others by adding problems to the Community group. If you have a problem without a solution in mind or are looking for a better idea how to solve it, post it in the Community group and see what other players come up with.
Note: Cody does not handle graphical problems yet.
Provide a function template to help players get started. You also need to write tests to validate players' solutions. You can also provide your own solution to validate your tests. Give it a try!
Cody checks each solution against a number of tests. Cody determines whether your solution passes these tests and measures the size of your code, which is the number of nodes in the parse tree.
The leading solution is the first solution of the smallest size.
To improve your score, solve problems correctly and contribute problems. You earn:
Search directives help you find Cody solutions. From the Solutions page, specify search directives in the search box.
| Solution Result | Directive | Examples |
|---|---|---|
Player with this name |
player: |
|
| Player with this ID number | player_id: | player_id:140947 |
| Problem with this ID number | problem_id: | problem_id:1 |
| Solution with this size | size: | size:20 |
| Solution size with this range | size_range: | size_range:10-20 |
player:"Ned Gulley".player:"Ned"
size_range:10-20 finds all solutions by players with the name "Ned" and a solution size between 10 and 20. -player:"Ned" finds solutions from all players except those with the name "Ned".