This commit is contained in:
Miloslav Ciz 2024-06-10 10:07:07 +02:00
parent aadf27a49f
commit 65fdd3799d
31 changed files with 1913 additions and 1808 deletions

View file

@ -197,14 +197,16 @@ Bear in mind the main purpose of this quiz is for you to test your understanding
92. =fgtnmtg qlcowj jakju lm vglcnr gjv dm gocl gjv qk vcjU
93. Please solve the following inequality: *sin(2 * x) / (2 - 2 * sin^2(x)) - log2(1 / 8^(-1/3)) >= 0*, mathematically write exactly which values of *x* will satisfy it. Don't use calculator, ok? But you can look up goniometric formulas etc.
94. Given continuous differentiable function *f(x)*, derive the formula for computing the length of the curve of the function graph on interval *[x1,x2]*. No need to provide 100% formal proofs, you can use intuition as long as you get the correct formula and show it works on a few examples. For example the length of the graph of function *f(x) = x* on interval *[0,1]* will be *sqrt(2)* (holds from Pythagorean theorem). Compute the length of curve of the graph of *f(x) = sin(x)* on interval *[0,2 * pi]*.
95. Give correct answers to at least three of the following. Full name of an influential software engineering essay that's shortened as *catb*. Name of the creator and BDFL of the Perl language. First name (by which he was known) of a famous suckless and cat-v member who commited suicide in 2012. Name of [esolang](esolang.md) made in 1972 that's considered to be the first esolang ever. First name that was shared by the two most famous members of the [Doom](doom.md) development team, the engine programmer and level designer.
96. Write a function in C, in 100 characters or fewer, that counts the number of 1 bits in a number of `unsigned int` type.
97. You're programming a "pseudo 3D" game that shows a 3D view from the player's perspective but really the player only has a position and facing direction in two dimensions, the level exists just in a 2D plane. Enemies also have a 2D position and facing direction, and they are rendered with 2D sprites, just like in [Doom](doom.md) or Wolfenstein 3D. Each enemy sprite has 4 versions, each for one of the four major viewing directions: front, back and two side views (left and right). Given player's position *PP*, normalized facing direction vector *PD*, enemy position *EP* and normalized enemy facing vector *ED*, how do you compute which of the four sprite versions to chose for the rendering? I.e. from the relative positions and rotations figure out which side of the enemy we're seeing.
98. What's the principle of [CPU](cpu.md) [cache](cache.md)? How exactly does it speed up programs? Under what conditions will the cache work well? I.e. how should a program ideally behave to make maximum use of the cache?
99. If you answer "yes" to this question, will you have lied?
100. Form a word by answering each following sentences with one letter. Binary number 1011 in hexadecimal. Base of natural logarithm. *x = min(max(0,t - 1),1)*, *y = 2 - t for 1 <= t <= 2 otherwise t mod 1*, *t* goes from 0 to 3. Number whose square is -1. `'U' - 'T' + 'R'`.
101. 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.
102. Did you enjoy this quiz?
95. If someone murders your whole family, does he deserve death?
96. Give correct answers to at least three of the following. Full name of an influential software engineering essay that's shortened as *catb*. Name of the creator and BDFL of the Perl language. First name (by which he was known) of a famous suckless and cat-v member who commited suicide in 2012. Name of [esolang](esolang.md) made in 1972 that's considered to be the first esolang ever. First name that was shared by the two most famous members of the [Doom](doom.md) development team, the engine programmer and level designer.
97. Write a function in C, in 100 characters or fewer, that counts the number of 1 bits in a number of `unsigned int` type.
98. You're programming a "pseudo 3D" game that shows a 3D view from the player's perspective but really the player only has a position and facing direction in two dimensions, the level exists just in a 2D plane. Enemies also have a 2D position and facing direction, and they are rendered with 2D sprites, just like in [Doom](doom.md) or Wolfenstein 3D. Each enemy sprite has 4 versions, each for one of the four major viewing directions: front, back and two side views (left and right). Given player's position *PP*, normalized facing direction vector *PD*, enemy position *EP* and normalized enemy facing vector *ED*, how do you compute which of the four sprite versions to chose for the rendering? I.e. from the relative positions and rotations figure out which side of the enemy we're seeing.
99. What's the principle of [CPU](cpu.md) [cache](cache.md)? How exactly does it speed up programs? Under what conditions will the cache work well? I.e. how should a program ideally behave to make maximum use of the cache?
100. If you answer "yes" to this question, will you have lied?
101. Form a word by answering each following sentences with one letter. Binary number 1011 in hexadecimal. Base of natural logarithm. *x = min(max(0,t - 1),1)*, *y = 2 - t for 1 <= t <= 2 otherwise t mod 1*, *t* goes from 0 to 3. Number whose square is -1. `'U' - 'T' + 'R'`.
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. Did you enjoy this quiz?
### Answers
@ -303,14 +305,16 @@ Bear in mind the main purpose of this quiz is for you to test your understanding
93. Let's simplify the left-hand side: *sin(2 * x) / (2 - 2 * sin^2(x)) - log2(1 / 8^(-1/3)) = 2 * sin(x) * cos(x) / (2 * (1 - sin^2(x))) - log2(8^1/3) = 2 * sin(x) * cos(x) / (2 * cos^2(x)) - log2(2) =
sin(x) / cos(x) - log2(2) = tg(x) - 1*, so we get *tg(x) >= 1*. So that will hold when *pi/4 + pi * n <= x < pi/2 + pi * n*, *n* is an integer.
94. Considering an infinitely small non-zero interval *dx*, and the graph height increase over this interval *dy*, the distance increase (from Pythagorean theorem) on this interval will be *sqrt(dx^2 + dy^2)*. We can replace *dy* by *tan(alpha) * dx*. By definition tangent of the function's angle at a certain point is its derivative, so we can also replace *tan(alpha)* by derivative of the function, *f'(x)*. So we get length increase *sqrt(dx^2 + f'(x)^2 * dx^2) = sqrt(dx^2 * (1 + f'(x)^2)) = dx * sqrt(1 + f'(x)^2)*. Now to add infinitely many values over infinitely small intervals we use integrals, so to add all these small length increases we can write the final formula: *length(x1,x2) = Integral(x1,x2) sqrt(1 + f'(x)^2) dx*. Testing this on *f(x) = x* from 0 to 1 we get the expected *length(0,1) = Integral(0,1) sqrt(1 + 1^2) dx = sqrt(2)*. For *f(x) = sin(x)* from 0 to *2 * pi* we get *length(0,2 * pi) = Integral(0,2 * pi) sqrt(1 + cos^2(x)) dx ~= 7.64*, which seems about right (it's a bit more than 2 * pi).
95. [The Cathedral And The Bazaar](bazaar.md), Larry Wall, Uriel, INTERCAL, John (Carmack and Romero).
96. For example: `int c1(unsigned int x) { int r = x % 2; while (x) r += (x >>= 1) % 2; return r; }`.
97. 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.
98. 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).
99. 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. BENIS
101. [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.
102. yes
95. no
96. [The Cathedral And The Bazaar](bazaar.md), Larry Wall, Uriel, INTERCAL, John (Carmack and Romero).
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.
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. yes
## Other