DEV Community

Cover image for Road to Genius: beginner #11
Ilya Nevolin
Ilya Nevolin

Posted on

Road to Genius: beginner #11

Each day I solve several 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, but you will learn a ton of new and interesting things as you go.

programming challenge

This challenge is an easy one, but will make you think twice.

It starts with a function nonzero that takes two parameters weights and i. Then it declares a variable j = i+1, followed by a while-loop with a buggy line of code as body: 🍎++;. The bug 🍎 can be several things, it can be j, i or weights. But since the parameter weights is used as an array, it's unlikely the correct answer. Now we have to choose between j and i, to figure this one out let's start analyzing the least occurring parameter i, it's used only once during the initialization of j, it has no further use apparently. So 🍎 is likely going to be j because it's also used explicitly in the while-condition.

programming challenge answer


If you feel inspired and motivated to upgrade your coding + debugging skills, join me on the Road to Genius at https://nevolin.be/codr/

Top comments (0)