Cody is an online MATLAB programming competition platform created by MathWorks. Thousands of programmers around the world participate in this platform. More than 5000 programming challenges are available here and it's a good place to hone your programming skill.
My journey in Cody is a transformative one. I developed a kind of fear of programming in my 1st year while taking the C programming course. I was deeply frustrated and had almost lost any interest in coding. Things started to change when I started practicing programming in Cody. At first, I found it very difficult. “I can do this all day” - the words of Captain America were my motto at that time to keep on going without giving up. Gradually, I began to improve and the fear I had inside me was long gone. I am very much thankful to Math Works for creating such a wonderful platform where people can test their programming skills as well as learn to code efficiently.
So far, I have solved around 3000 problems in Cody. I also created around 200 new problems there as well as 5 problem groups.
My highest ranking in Cody was 4th with 60 badges.
My profile link - https://www.mathworks.com/matlabcentral/cody/players/16549154
I have listed below some of the interesting problems that I created -
The Tortoise and the Hare
Suppose in an infinitely long line, the hare is standing in position 0. From that place, it can move in both +ve and -ve direction. The condition is that, in i-th jump, it can move i step forward or backward. So one possible scenario can be -
0 [i=1] --- 1 step forward
1 [i=2] --- 2 step forward
3 [i=3] --- 3 step forward
6 [i=4] --- 4 step backward
2 [i=5] --- 5 step forward
7 [i=6] --- 6 step backward
1 [i=7] --- 7 step forward
8
If you look carefully, you'll find that -- If the tortoise moves this way, it'll always be able to reach any destination (x). The question is what is the minimum number of moves it'll take to reach destination x? For example -- if x=8,
in the above example, it takes 7 steps
but if it moves this way -- [0,-1,1,4,8] -- steps required = 4 (So 4 is the optimum way)
Word Ladder
Given a set of words, and two other words - start and destination, find the smallest chain from start to the destination such that adjacent words in the chain only differ by one character and each word in the chain exists in the set. All the words are of the same length. The starting word is not in the set but the destination word would be.
For example,
Start = 'COLD'
Destination = 'WARM'
set ={ CORD CARD DART FORT WARM FARM WARD}
COLD → CORD → CARD → WARD → WARM
Problem link - https://www.mathworks.com/matlabcentral/cody/problems/45463-word-ladder
Checkmate
The positions of different chess pieces are given in a cell p. The position of the king is given as x. Determine if the opponent king is in check for individual scenarios. Any invalid position should produce 0. For instance,
x='Kg7'
p={'Qe5','Qg5','Qb5','Qa7'}
output= [1,1,0,1]
If the king is in check, examine the next move of the king. List all those possible moves by which the king can avoid the check by the next move. Otherwise 'checkmate'. If the king is currently not in check, then he doesn't need to move. so return empty.
Vampire and Pseudo-Vampire Numbers
A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:
At most one of x and y are divisible by 10;
x and y have the same number of digits; and
The digits in v consist of the digits of x and y (including any repetitions).
If these conditions are met, x and y are known as the "fangs" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.
Write a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.
A pseudo-vampire number is similar to vampire numbers except -
It can be of any length, unlike the vampire numbers which have even no digits.
It can have n number of fangs which need not be of the same length, unlike the vampire numbers which can have only two fangs.
But the fangs must contain precisely all the digits of the original number.
Given a number x, determine whether it is a pseudo-vampire number. Find all the fangs of that number as well.
Problem Groups
A list of the problem groups I created is provided below -
Introduction to Cody
You can check out the following video on how to solve problems in Cody.