Road to Genius - Python Series level 3
Ilya Nevolin
Posted on January 20, 2021
Welcome to the third level where we solve Python Challenges from Codr's Ranked mode. The goal is to reach the Genius level, so join me at Codr!
The first challenge is a function trap
, we have to fix three bugs. The first two bugs sit next to each other, in what appears to be a for loop. So it should probably be: for i in range...
. The panda bug is a return value, we know that value A should be a number, so it makes most sense to return either variable maxi or V, because LM and RM are lists. You can either make a bet on either maxi or V, but from my analysis, the variable maxi seems to be used for tracking a maximum value, while variable V doesn't have any usage outside being the return value. To be very certain you can calculate V's and maxi's values to see which one results in A = 8
.
Here we have a recursive function backtrack
. Recursive functions are known for calling itself until some condition is met. The first diamond bug is the last function parameter, to figure it out we have to find a variable that is not declared inside the function: start
.
The second bug is an operator, which makes an empty list.
To solve this challenge we need to solve A's value. After a quick glimpse at the function, it's used for solving a quadratic function:
a = 2
b = 8
c = 1
quadratic:
d = b²-4ac
d = 64-8 = 56
d = sqrt(56) / 2a
d = 1.8708
return [-9.8708, 6.1292]
out = quadratic(a,b,c)
A = math.floor(out[0]*100)
A = math.floor(-987.08)
A = -988 --> floor rounds to a lower value!!!
A = abs(A)
A = 988
Here we need to fix three bugs which appear very close to each other. A quick look at the code, it appears to be some kind of calculator. The inner most if-else statements are its basic operations. The green heart and droplet are likely to be token == '-'
since minus is missing and a possible answer, consequently the diamond should be -
.
We are lucky here, this challenge is the same function as the previous one, you can take a peek above to solve it quickly ;)
Just like that we made it to the 4th level (Superior) stay tuned for that! If you enjoyed this post, make sure to join Codr, like and follow me on DEV <3!
Posted on January 20, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.