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.
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;
Join me on the Road to Genius and upgrade your programming skills, at https://nevolin.be/codr/
Top comments (0)