DEV Community

Cover image for Road to Genius: advanced #41
Ilya Nevolin
Ilya Nevolin

Posted on

3 1

Road to Genius: advanced #41

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.

let S = 0;
for (let i = 0; i < 150; i💧) {
  let h = Math.floor(i / 💎);
  if (h > 0)
    S += i % h;
}

// 💧 = ? (operator)
// 💎 = ? (number)
// such that S = 73 (number)
Enter fullscreen mode Exit fullscreen mode

Here's a pretty short code for an advanced challenge, let's have a look. The core of the code is a for-loop that runs from 0 to 150 (excluded), and then depending on the if-condition it increases S's value.

We won't have to fully analyze the code since fixing the two required bugs is pretty simple.

The first one 💧 has to be the ++ operator, to ensure the for-loop works correctly.

The second bug 💎 is quite tricky, you can't determine its value in an easy way, it could be any number. Either you reverse engineer the code to ensure that S = 73 at the end, or take a peek at the possible answers for 💎: 0, 2 and 150. Dividing i by 0 or 150 will never yield a value larger than 0, so the if-condition is never going to trigger. The only choice left is 2:

coding challenge answer

By solving these challenges you train yourself to be a better programmer. You'll learn newer and better ways of analyzing, debugging and improving code. As a result you'll be more productive and valuable in business. Get started and become a certified Codr today at https://nevolin.be/codr/

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay