+ 6

How do you people calculate, complex math in your head while competing or answering quizzes?

Some complex or complex looking quizzes shown while answering quizzes. How do you come up with the answer of that loop? like: show last number / number or total numbers. for (i=1;i <=999;i=i+9){ echo / print (i); } What are some easy techniques to use for this sort of solution?

23rd Aug 2017, 2:44 AM
Rifat
Rifat - avatar
2 Antworten
+ 8
Hi @Rifat... For me, when seeing a new complex computing question for the first time, I scan the code for clues on what the author is looking for. Below is a breakdown of my thought process for this particular use case: - First, I take note that this loop will start at value 1 and increment by 9 until it reaches 999 or more. At this point, I shift my focus to what specifically the question is asking so I can use my remaining time to quickly answer based on what I know. The following are some examples of how I would approach answering different variations for this question: - Last value printed: (value of i in the last valid loop) - Answer: 991 - Based on the (max value possible) + (initial value) - (incremented value). - 999 + 1 -9 = (991) -> last valid value before loop condition fails - Value of i after loop is finished? - Answer: 1000 - Based on (value of i in the last valid loop) + (incremented value) - 991 + 9 = (1000) -> value of i that fails the looping condition - Number of times the loop will run: - Answer: 111 - Based on whole number quotient of (value of i after last valid loop) / (incremented value) - 1000 / 9 = (111) -> number of times the loop will run I honestly couldn't tell you how I came up with these formulas. I'm not even thinking about it when I review these questions. They just come to me very quickly. One thing I noticed is I get more questions like these wrong if I'm attempting to answer after 1am in the morning, prior to going to sleep. Also, it's much easier for me to run through the logic steps each time than it is for me to memorize the answer. It's much more difficult to memorize so many answers that may have a series of variations and recall them correctly when toggling between challenges across multiple languages.
27th Aug 2017, 5:57 AM
David Carroll
David Carroll - avatar
+ 9
You can use paper and a pen to take note. For this specific case, 9 * 111 = 999, plus 1 in the initial assignment, we'll have 1000, this is the value of i when the for loop ends, so the last i got printed is 1000 - 9 = 991.
23rd Aug 2017, 3:31 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar