MATLAB Community

MATLAB, community & more

Prettier Cody Code!

We did some web updates last night, and Cody emerged with a fresh coat of paint. As a result it’s more mobile-friendly. The tags for each problem are a little more prominent on the right side. But I especially want to call your attention to the fact that code regions now feature proper MATLAB syntax highlighting.

I want to show you what it looks like with a problem that John D’Errico created a few weeks ago. The problem, Counting the Grand Primes, asks you to look for prime pairs that differ by exactly 1000. The leading answer is by Peng Liu.

Spoiler Alert! If you haven’t solved this problem yet, you wouldn’t ordinarily be allowed to look at this solution. But I’m going to show you anyway, because it’s a nice solution and a good illustration of the new feature.

peng2

Ooh! Line numbers! Notice that the keywords “function” and “end” are blue and the comments are green. Thoughtfully, Peng has provided not just one, but three solutions. Two of them excel in the Cody sense: they don’t use a lot of code. But we all know there’s more to life than being short. The first one runs faster because you compute the prime numbers once rather than twice. Since two of the solutions are commented out, they appear in green.

If you do a lot of MATLAB programming, you’ll appreciate how important syntax highlighting is to your coding practice. It should make it easier to create and interpret solutions.

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.