+ 14
[NOT a Wrong answer... Solved.] Where is that "10099100" from??
There is a question in PHP challenges: function myfunc($i=1) { static $id = 58; $id-=$i; echo $id; } myfunc(); myfunc(1); myfunc(-1); (by @Martin Kalco) and the right answer according to author is "10099100"! But I get (even tested it in code playground): "575657"! You can check it here: https://code.sololearn.com/wwV0BXu1oRiP/?ref=app Why do you think the answer is "10099100"?
11 Respostas
+ 11
Buddies. My opinion is different.
I saw this quiz several hours ago and I've got right answer.
Here is my solution.(Sorry for my poor English)
$id is static variable. So it has been allocated statically.
$id is initialized only once across many calls of myfunc().
Although $id was 58 at first.
After some process it becomes another value.
So In here we dont know $id's current value.
and that's why creater of this quiz give us hint.
the answer was 100__100
We can get $id's current value from this.
myfunc(); // This made $id 100
So $id is 100 now.
and We should find myfunc(1);
and it will be 99($id - $i = 100 - 1)
So the answer for the blank is 99.
And check the rest part
myfunc(-1); // $id = 99 -(-1) = 100
--------
I think the creater want to ask "Do you know static variable's characteristic?".
And as the evidence, creater give us the context.
Although some process are omitted in the quiz.
It doesnt matter because we can find the context...
This was my process of solve the problem.
+ 9
you are right, I've reported that quizz and it cost me 32XP a couple of days ago...
+ 9
@Faith seems not đ as that is not the only case...
+ 9
@Andrew Kharchenko
Yes you're right. This is bad quiz.
Many questions are show just part of the quiz.
(no headers/libraries included, dont mention about the version, etc...)
It confuses us and make us lose xp.. đ„
+ 8
I saw the quiz without answer too and lost my 32xp.
At that time I thought "This is unfair!".(Though it is right that the quiz has no answer)
Although my goal isnt xp I was so sad.
+ 7
I don't know much PHP, but I can't wrap my head around how 10099100 would be the answer. Can we get a screen shot to make sure everything you wrote is exactly what the question asks?
+ 7
@eh...(Legacy) Hmm.. Right you are! âđ
But again: I see it as a bad practice not to show parts of code where some changes made. Some may think that the code written in the question is the only code meddling with variable asked in the question. (I myself thought so, and most people here I assume think so... but after I've suddenly encountered a question with radiobuttons where "no choosen radiobutton" was the right answer I am no more wondering those challenges tricks... they just dissapoint me... even if it's another one benefit for me and people playing a lot of challenges after memorizing those tricky answers)
+ 6
The only way I see this code producing 10099100 is when $id is 101 instead of 58.
+ 4
@Rrestoring faith Sure, here is the link to the screenshot:
https://ibb.co/hKWWoF
+ 4
Yep, already encountered question in java that had an version dependent answer and version was not mentioned (about interfaces containing not only abstract methods). Of course some simplifying is needed, when it's obvious that something hidden does not changes which answer is right (those left out headers, outer classes etc) I think another one option in question reporting is needed: Bad wording :) (I would not choose this option for subject question, so it's a little bit offtopic, sorry)
+ 3
How would these quizes even get accepted? Does Sololearn not check them if they receive lots of likes?