This commit is contained in:
Miloslav Ciz 2024-06-02 12:40:38 +02:00
parent cbedf57724
commit 1ff8f3a311
11 changed files with 1824 additions and 1804 deletions

View file

@ -198,7 +198,11 @@ Bear in mind the main purpose of this quiz is for you to test your understanding
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. Did you enjoy this quiz?
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. Did you enjoy this quiz?
### Answers
@ -233,7 +237,7 @@ Bear in mind the main purpose of this quiz is for you to test your understanding
29. *[recursion](recursion.md)*, *[compression](compression.md)*, *[nigger](nigger.md)*, *[censorship](censorship.md)*, *[faggot](faggot.md)*, *[network](network.md)*.
30. 1:5:27, 2:10:54, 3:16:21, 4:21:49, 5:27:16, 6:32:43, 7:38:10, 8:43:38, 9:49:05, 10:54:32, 12:00:00, you can compute it by making equations for position of the hour and minute hand depending on time, setting them equal and solving, i.e. you get something like *tm / (60 * 12) = (tm / 60) - (tm // 60)* (where *//* is integer division and *tm* is time in minutes); you will find the times are those when minute hand is at multiples of 60 / 11 minues (5:27), i.e. there are 11 such times around the circle and they are evenly spaced.
31. Shading is the process of computing surface color of 3D objects, typically depending on the object's material and done by GPU programs called [shaders](shader.md); shading involves for example applying textures, normal mapping and mainly lighting -- though it can make pixels lighter and darker, e.g. depending on surface normal, it only applies local models of light, i.e. doesn't compute true shadows cast by other objects. On the other hand computing shadows uses some method that works with the scene as a whole to compute true shadowing of objects by other objects.
32. We can't really talk about Turing completeness of plain neural networks, they cannot be Turing complete because they just transform fixed length input into fixed length output -- a Turing complete model of computation must be able to operate with arbitrarily large input and output. In theory we can replace any neural network with logic circuit or even just plain lookup table. Significance of neural networks doesn't lie in their computational power but rather in their efficiency, i.e. a relatively small and simple neural network may replace what would otherwise be an enormously large and complicated circuit.
32. Basic answer is that we can't really talk about Turing completeness of plain neural networks of this type, they cannot be Turing complete because they just transform fixed length input into fixed length output in a fixed number of steps -- a Turing complete model of computation must be able to operate with arbitrarily large input and output, it must be able to get stuck in an infinite loop etc. In theory we can replace any neural network with logic circuit or even just plain lookup table. Significance of neural networks doesn't lie in their computational power but rather in their efficiency, i.e. a relatively small and simple neural network may replace what would otherwise be an enormously large and complicated circuit.
33. two (or txq); The cipher offsets each letter by its position.
34. The number will be negative because the highest (leftmost) bit is 1; to convert a negative number to positive (and vice versa) in two's complement we flip all bits and add 1, i.e. 10000101 -> 01111010 + 1 -> 01111011 which is 123; the original value therefore represents -123.
35. *log2(n)*; Binary search works by splitting the data in half, then moving inside the half which contains the searched item, recursively splitting that one in half again and so on -- for this the algorithm will perform at worst as many steps as how many times we can divide the data in halves which is what base 2 logarithm tells us.
@ -299,7 +303,11 @@ sin(x) / cos(x) - log2(2) = tg(x) - 1*, so we get *tg(x) >= 1*. So that will hol
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. yes
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. yes
## Other