DEV Community

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

Posted on

Road to Genius: beginner #1

This is the first post of my "Road to Genius" series. 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 challenges intro

I've created a brand new account with username "IlyaDEVto", now let's click play and get started.

programming challenge

The first challenge is pretty simple, the number of answers we can choose from is limited, making our life easy. Now let's have a look at the code, the first line creates an array with name arr with certain values (5,0,4,9,0), then we have a variable R which is zero. Then we have a while loop whose condition is based on the array's length. This loop executes the next line of code as long as arr is not empty. The challenge is to fix two bugs (indicated by πŸš€ and β˜ƒοΈ).

To find πŸš€, we must look at the question (which is the comment on the very last line), it says such that R=18 (number). We know that initially the R value is zero, so the code must be changing R such that it eventually becomes 18. If you take the sum of all the values in arr you will notice they sum up to 18. And if you already know a little bit of coding you can see that πŸš€ should be R, because that line of code under the while-loop does exactly that.

To find β˜ƒοΈ you can take a peek at the answers these are (R, arr and pop). R and arr are both variables, and it does not make sense to use these because for instance the code πŸš€ += arr.arr(); is incorrect and will throw an error, the () parentheses indicate a function call, so the only function we have is pop. This removes the last item from arr and returns its value. That value is added to πŸš€, which we already know to be R.

So that buggy line becomes: R += arr.pop(); And just like that we have solved our first challenge.

programming challenge answer

If you already know a little bit of programming, solving this should take you no more than 10 seconds, writing this whole description is just for the purpose of having a detailed explanation to non-programmers.


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)