DEV Community

Cover image for Road to Genius: smart #21
Ilya Nevolin
Ilya Nevolin

Posted on

Road to Genius: smart #21

Each day I solve several coding challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.

coding challenge

Here's an interesting challenge, this time it's related to geometry, but don't be scared. We only need to fix two bugs 💎 and 💰. The code starts off with a function calculateCentroid that takes four parameters. Both bugs appear on the same line:
nc[i] = (s1 * c1[💰] + 💎 * c2[i]) / ns;
As you may know, symmetry is a very important characteristic in mathematics, a lot of formulas, especially in geometry have symmetric properties. If you analyze this buggy line of code, you start noticing a pattern (or symmetry), and the variable names are a good hint. The buggy line is most likely going to be:
nc[i] = (s1 * c1[i] + s2 * c2[i]) / ns;

coding challenge answer


Join me on the Road to Genius and upgrade your programming skills, at https://nevolin.be/codr/

Top comments (0)