This commit is contained in:
Miloslav Ciz 2024-06-18 16:48:37 +02:00
parent 20a4dd08ff
commit cb4007d9d6
20 changed files with 1842 additions and 1803 deletions

View file

@ -207,7 +207,9 @@ Bear in mind the main purpose of this quiz is for you to test your understanding
102. In C this `float x = 16777216; printf("%d\n",x == (x + 1));` outputs `1` (or at least it is possible) -- what the fuck. How can a number equal itself plus one? Explain what's going on here.
103. Can you be both pro-privacy and anti-censorship at the same time?
104. What's the error with the following reasoning? *-1 = (-1)^(2/2) = ((-1)^2)^(1/2) = 1^1/2 = 1*.
105. Did you enjoy this quiz?
105. Let's have a [spiral](spiral.md) that's drawn like this: we start with a drawing hand (like e.g. that of clock) that points horizontally to the right and has length *r1*; then the hand turns around a full circle (doesn't matter in which direction), linearly increasing its length to *r2* as it goes. Find the formula for the length of this spiral (this length will be something between the circumference of a circle with radius *r1* and circumference of a circle with radius *r2*).
106. Rounded to whole percents, what is the probability that you'll correctly answer this question?
107. Did you enjoy this quiz?
### Answers
@ -311,12 +313,14 @@ sin(x) / cos(x) - log2(2) = tg(x) - 1*, so we get *tg(x) >= 1*. So that will hol
97. For example: `int c1(unsigned int x) { int r = x % 2; while (x) r += (x >>= 1) % 2; return r; }`.
98. Firstly realize we don't need player's facing vector *PD* at all (if an enemy is showing us his back for example, no matter how we rotate ourselves we'll only ever be able to see his back). Instead we'll need a vector pointing from the player's position to the enemy position, let's say *V = normalize(EP - PP)*. Now let's observe our result will depend on the relatinship between *V* and *ED* -- for example if the vectors are the same (enemy is facing in the direction aligned with the direction from player to enemy), the player will see the enemy back. If the vectors are opposing, we'll see the enemy front. If the vectors are 90 degrees, we'll see either left or right side. So we just need to figure out what angle the vectors *V* and *ED* have between then, which we can easily do with [dot product](dot_product.md) that tells us the cosine of the angle -- so if we get dot product greater than *cos(45 degrees)*, we see the back, if we get value smaller than *cos(135 degrees)*, we see the front, otherwise we see the side. To distinguish between left and right side we may use for example [cross product](cross_product.md) to determine if one vector goes "left or right" from another vector.
99. Cache is a small memory placed between the CPU and main memory (RAM), it is a very fast type of memory, faster than the main memory, but it's also much smaller than main memory. The idea is that programs typically do a lot of work in some small region of main memory, they keep reading and writing the same (or nearby) memory cell(s) over and over and only after a while move somewhere else. So once the program starts a work in some memory area, the cache can load that area, let the program do its work very quickly in the cache, and then (when the program moves elsewhere) copy the results back from the cache to the memory. It's similar to downloading a file from the Internet to the disk, then editing the file locally and later on uploading it back. However the cache will be effective only if the assumption we made hold, i.e. if the program really mostly works in small areas of memory and makes minimum of long jumps, so if a program wants to fully utilize the cache, it should try to minimize these long jumps (for example by putting related data close to each other).
100. There is no correct answering with either "yes" or "no" (this is therefore the correct answer). The question can be reworded as: *Is "yes" the wrong answer to this question?*, which can be reworded as: *Is "no" the correct answer to this question?* If we try both possible answers -- "yes" and "no" -- we find neither works.
100. There is no correct answering with either "yes" or "no" (this is therefore the correct answer). The question can be reworded as: *Is "yes" the wrong answer to this question?*, neither yes or no (or both at once) work as an answer: answering "yes" leads to a contradiction (by giving "yes" as a correct answer we'll imply it's actually the wrong answer) and answering "no" would imply "yes" is the correct answer (which we've proven to not work).
101. BENIS
102. [Floating point](float.md) had decreasing precision towards higher values, this one if already beyond the resolution of 1, so the float type cannot represent this number plus one, adding one rounds the result down to the same number.
103. no
104. We can't replace *a^(b/c)* with *(a^b)^(1/c)* if *a* is negative, that equation doesn't generally hold.
105. yes
105. { I hope this is right :D ~drummyfish } First imagine the graph of a polar coordinate function that says the radius of a plain circle with radius *r* depending on angle: the graph is just constant function (horizontal line) with value *r* going from 0 to *2 * pi*. Integrating this function (from 0 to 2 * pi, here we simply multiply *r* by *2 * pi* as the graph is a rectangle) will give us the formula for the circumference of circle: *2 * pi * r* -- we'll take this largely on intuition but it can be seen that this holds because we're adding constant tiny increments of length from 0 to what we know is the circle circumference (2 * pi * r). Now imagine similar function, just starting at *r1* and linearly increasing to *r2*, i.e. we just have a linear function saying the spiral radius for current angle. Again, we'll integrate this, this time getting (bottom rectangle plus upper right triangle): *2 * pi * r1 + 2 * pi * (r2 - r1) / 2*. Simplifying this we get *pi * (r1 + r2)*, which is hopefully the solution (we see this will be between the circumferences of the smaller and larger circles, also for *r1 = r2* we again get the circumference of plain circle etc.).
106. Lol what, TBH I don't know :D The answer is probably that the question is shit because it's not even clear what it's asking, the definition of probability here is not clear (is it probability of a random "intelligent" man from the street answering it, or giving a completely randomly generated answer to it or what?). 100% might in some cases make sense (firstly we conclude that chance of guessing a number from 0 to 100 is 1/101, but then knowing this will be the answer we conclude we know it for sure, so we switch to 100% and then making further reasonings it stays stable at this value, but this probability assumes we make the reasoning we did, someone else could make a different reasoning maybe leading to other consistent answers). Haven't thought about it deeper yet though. If you know the answer let me know.
107. yes
## Other