This commit is contained in:
Miloslav Ciz 2024-04-25 20:58:19 +02:00
parent 4493396d0f
commit 484f66449a
7 changed files with 1741 additions and 1736 deletions

View file

@ -1,6 +1,6 @@
# Exercises
Here there should be some exercises for those wishing to pursue [LRS](lrs.md) in any way.
Here there should be some exercises such as programming projects, math problems or quizes for those wishing to pursue [LRS](lrs.md) in any way.
## Programming Challenges
@ -97,7 +97,7 @@ TODO: tetris, voice synth?, snake, quadratic equation, fractals, 2D raycasting,
## Quiz/Questions/Problems/Test
Here are some questions to test your LRS related knowledge :D
Here are some questions to test your LRS related knowledge :D Questions here are of varying difficulty, areas and may potentially have even multiple solutions, just like in [real life](irl.md).
1. What's the difference between *[free software](free_software.md)* and *[open source](open_source.md)*?
2. Use numbers 1, 3, 4 and 6, each exactly once, with any of the basic arithmetic operations (addition, subtraction, multiplication, division) and brackets to get the result 24.
@ -121,7 +121,7 @@ Here are some questions to test your LRS related knowledge :D
20. Give at least one example of [analog](analog.md) electronic device and one of [digital](digital.md) mechanical device.
21. Transitive [relation](relation.md) is such that if element *A* is in relation with *B* and *B* is in relation with *C*, then also *A* is in relation with *C*. Give one real life example of transitive relation and one real life example of relation that is NOT transitive.
22. Is physical violence ever justified?
23. Find a normalized (having length 1) [normal](normal.md) ([vector](vector.md) that's perpendicular to surface) of the [triangle](triangle.md) defined by vertices *A = {1,2,3}*, *B = {5,5,1}* and *C = {1,5,2}*. (Orientation doesn't matter.)
23. Find a normalized (having length 1) [normal](normal.md) ([vector](vector.md) that's perpendicular to surface) of the [triangle](triangle.md) defined by vertices *A = {1,2,3}*, *B = {5,5,1}* and *C = {1,5,2}*. (Orientation doesn't matter. Geometric, not [sexual](gay.md).)
24. Why will (in a typical programming language such as C) an infinite [recursion](recursion.md) crash the program but infinite loop generally won't?
25. Answer yes/no to following: Is base-three number 2101 greater than base-seven number 206? Is using [gemini](gemini.md) a good idea when [gopher](gopher.md) exists? Is there any [triangle](triangle.md) (in Euclidean geometry) whose one side is longer than the sum of lengths of its other two sides?
26. There are two walls 2 meters apart, the right wall is moving left by the speed 0.1 m/s, the left wall is moving right by the same speed 0.1 m/s. There is a fly in the middle between the walls, flying by speed 1 m/s. It is flying towards one wall, then when it reaches it it turns around and flies towards the other wall etc. When the walls completely close in, what distance would the fly have traveled? (There is a simple solution.)
@ -130,18 +130,20 @@ Here are some questions to test your LRS related knowledge :D
29. In 3D computer [graphics](graphics.md) what's the difference between [shading](shading.md) and drawing [shadows](shadow.md)?
30. Can we say that the traditional feed forward [neural networks](neural_network.md) are [Turing complete](turing_complete.md)? Explain why or why not.
31. Wicw mx uum yvfe bbt uhmtf ok?
32. What is the *Big O* time [complexity](complexity.md) of worst case scenario for [binary search](binary_search.md)?
33. Does the statement "10 does not equal 10" logically [imply](implication.md) that intelligent alien life exists?
34. Consider a function *f(x) = sqrt(1 - x^2)* with *x* belonging to <-1,1>. Convert it to [polar coordinates](polar_coordinates.md), i.e. write function *g(angle)* that for given *angle* (in [radians](radian.md)) returns distance from origin and specify for which values of *angle* the function is defined.
35. What is the principle of [asymmetric cryptography](asymmetric_cryptography.md) and why is it called *asymmetric*?
36. What is the main reason for [Earth](earth.md) having seasons (summer, winter, ...)?
37. Name at least three [x86](x86.md) [assembly](assembly.md) instructions and shortly explain what they do.
38. Point out what's highly unusual or uncommon about this paragraph. That is find a quality of this paragraph that you wouldn't normally think to find if you took a random paragraph from, say, a random book in your library, or in similar work. It's not that difficult.
39. WARNING: VERY HARD. There are two integers, both greater than 1 and smaller than 100. *P* knows their product, *S* knows their sum. They have this conversation: *P* says: I don't know the numbers. *S* says: I know you don't, I don't know them either. *P* says: now I know them. *S* says: now I know them too. What are the numbers? To solve this you are allowed to use a programming language, pen and paper etc. { Holy shit this took me like a whole day. ~drummyfish }
40. Compare advantages and disadvantages of [hash](hash.md) tables vs binary [trees](tree.md) for storing text strings, especially in regards to searching the string database.
41. A woman gave birth to two sons in the span of a single hour, i.e. they are of the same age, but they aren't twins. Hows is this possible?
42. Name at least two TCP/IP or OSI [network](network.md) layers: about each shortly explain its purpose, addressing and at least one protocol of this layer.
43. Did you enjoy this quiz?
32. 8 bit binary value 10000101 will be interpreted as number 133 under unsigned, direct representation, but what number will it represent in [two's complement](twos_complement.md) representation?
33. What is the *Big O* time [complexity](complexity.md) of worst case scenario for [binary search](binary_search.md)?
34. Does the statement "10 does not equal 10" logically [imply](implication.md) that intelligent alien life exists?
35. Consider a function *f(x) = sqrt(1 - x^2)* with *x* belonging to <-1,1>. Convert it to [polar coordinates](polar_coordinates.md), i.e. write function *g(angle)* that for given *angle* (in [radians](radian.md)) returns distance from origin and specify for which values of *angle* the function is defined.
36. What is the principle of [asymmetric cryptography](asymmetric_cryptography.md) and why is it called *asymmetric*?
37. What is the main reason for [Earth](earth.md) having seasons (summer, winter, ...)?
38. Name at least three [x86](x86.md) [assembly](assembly.md) instructions and shortly explain what they do.
39. Point out what's highly unusual or uncommon about this paragraph. That is find a quality of this paragraph that you wouldn't normally think to find if you took a random paragraph from, say, a random book in your library, or in similar work. It's not that difficult.
40. WARNING: VERY HARD. There are two integers, both greater than 1 and smaller than 100. *P* knows their product, *S* knows their sum. They have this conversation: *P* says: I don't know the numbers. *S* says: I know you don't, I don't know them either. *P* says: now I know them. *S* says: now I know them too. What are the numbers? To solve this you are allowed to use a programming language, pen and paper etc. { Holy shit this took me like a whole day. ~drummyfish }
41. Compare advantages and disadvantages of [hash](hash.md) tables vs binary [trees](tree.md) for storing text strings, especially in regards to searching the string database.
42. A woman gave birth to two sons in the span of a single hour, i.e. they are of the same age, but they aren't twins. How is this possible?
43. Name at least two TCP/IP or OSI [network](network.md) layers: about each shortly explain its purpose, addressing and at least one protocol of this layer.
44. We know [HTTPS](https.md) is shit because it's [encrypted](encryption.md) and requires [certificates](certificate.md). Explain what these certificates are, why HTTPS needs them, how their absence could be "abused" and who issues them.
45. Did you enjoy this quiz?
### Answers
@ -176,18 +178,20 @@ Here are some questions to test your LRS related knowledge :D
29. 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.
30. 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.
31. two (or txq); The cipher offsets each letter by its position.
32. *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.
33. Yes, a false statement implies anything.
34. The function plot is a half circle, so expression in polar coordinates is quite simple: *g(alpha) = 1*, *alpha* belongs to interval <0, pi>.
35. The main difference against symmetric cryptography is we have two keys instead of one, one (private) for encrypting and one (public) for decrypting -- neither key can be used for the other task. Therefore encryption and decryption processes differ greatly (while in symmetric cryptography it's essentially the same, using the same key, just in reversed way), the problem looks different in one direction that the other, hence it is called *asymmetric*.
36. It's not the distance from the Sun (the distance doesn't change that much and it also wouldn't explain why opposite hemispheres have opposite seasons) but the tilted Earth axis -- the tilt changes the maximum height to which the Sun rises above any specific spot and so the angle under which it shines on the that spot; the [cosine](cos.md) of this angle says how much energy the place gets from the Sun (similarly to how we use cosine to determine how much light is reflected off of a surface in [shaders](shader.md)).
37. For example: MOV (moves values between memory locations or registers), JNE (jump if not equal, jumps to another instruction if comparison resulted in non-equality), ADD (adds values in memory or registers), CMP (compares two values and sets the flags register), RET (returns from procedure, pops return address and jumps there) etc.
38. There is no letter "e", one of the most common letters in English and other languages -- this is very unlikely to happen by chance.
39. 4 and 13, solution: make a table, columns are first integer, rows are second (remember, both *P* and *S* can be making their own table like this too). Cross out whole bottom triangle (symmetric values). *P* doesn't know the numbers, so cross out all combinations of two primes (he would know such numbers as they have only a unique product). *S* knew *P* didn't know the numbers, so the sum also mustn't be a sum of two primes (if the sum could be written as a prime plus prime, *S* couldn't have known that *P* didn't know the numbers, the numbers may have been those two primes and *P* would have known them). This means you can cross out all such numbers -- these are all bottom-left-to-top-right diagonals that go through at least one already crossed out number (combination of primes), as these diagonal have constant sum. Now *P* has a table like this with relatively few numbers left -- if he now leaves in only the numbers that make the product he knows, he'll very likely be left with only one combination of numbers -- there are still many combinations like this, but only the situation when the numbers are set to be 4 and 13 allows *S* to also deduce the numbers after *P* declares he knows the numbers -- this is because *S* knows the combination lies on one specific constant-sum diagonal and 4-13 lie on the only diagonal that in this situation has a unique product within the reduced table. So with some other combinations *P* could deduce the numbers too, but only with 4-13 *S* can finally say he knows them too.
40. Hash table will only allow efficient searching of exact matches while binary tree will also allow efficient searching e.g. for all strings starting with some prefix. On the other hand hash table may be faster, in ideal case searching for the match in constant time, but this will depend on the quality of implementation (hash function, number of hash bits, ...), in worst case hash table can degenerate to a mere list. Binary trees will generally be a bit slower, with logarithmic time, but here we'll also have to ensure good implementation, especially balancing the tree -- badly implemented tree may also degenerate to a list.
41. They are two of triplets (or quadruplets, ...).
42. For example: application layer (highest level layer, concerned with applications communicating with each other, addressing by ports, protocols: HTTP, Gopher, FTP, DNS, SSH, ...), transport layer (middle level layer, concerned with delivering data over a potentially unreliable channel, implements establishment of connection, handshakes, reliable delivery, delivering in correct order etc., protocols: TCP, UDP, ...), network layer (below transport layer, concerned with delivering packets over a network, implements routing, forwarding etc., addressing by IP addresses, i.e. numerical machine addresses, protocols: IPv4, IPv6, ...), OSI physical layer (lowest level layer, concerned with sending bits between two directly connected devices, works with frequencies, electronic circuits etc., no addressing, protocols: ethernet, USB, Bluetooth, ...), ...
43. yes
32. 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.
33. *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.
34. Yes, a false statement implies anything.
35. The function plot is a half circle, so expression in polar coordinates is quite simple: *g(alpha) = 1*, *alpha* belongs to interval <0, pi>.
36. The main difference against symmetric cryptography is we have two keys instead of one, one (private) for encrypting and one (public) for decrypting -- neither key can be used for the other task. Therefore encryption and decryption processes differ greatly (while in symmetric cryptography it's essentially the same, using the same key, just in reversed way), the problem looks different in one direction that the other, hence it is called *asymmetric*.
37. It's not the distance from the Sun (the distance doesn't change that much and it also wouldn't explain why opposite hemispheres have opposite seasons) but the tilted Earth axis -- the tilt changes the maximum height to which the Sun rises above any specific spot and so the angle under which it shines on the that spot; the [cosine](cos.md) of this angle says how much energy the place gets from the Sun (similarly to how we use cosine to determine how much light is reflected off of a surface in [shaders](shader.md)).
38. For example: MOV (moves values between memory locations or registers), JNE (jump if not equal, jumps to another instruction if comparison resulted in non-equality), ADD (adds values in memory or registers), CMP (compares two values and sets the flags register), RET (returns from procedure, pops return address and jumps there) etc.
39. There is no letter "e", one of the most common letters in English and other languages -- this is very unlikely to happen by chance.
40. 4 and 13, solution: make a table, columns are first integer, rows are second (remember, both *P* and *S* can be making their own table like this too). Cross out whole bottom triangle (symmetric values). *P* doesn't know the numbers, so cross out all combinations of two primes (he would know such numbers as they have only a unique product). *S* knew *P* didn't know the numbers, so the sum also mustn't be a sum of two primes (if the sum could be written as a prime plus prime, *S* couldn't have known that *P* didn't know the numbers, the numbers may have been those two primes and *P* would have known them). This means you can cross out all such numbers -- these are all bottom-left-to-top-right diagonals that go through at least one already crossed out number (combination of primes), as these diagonal have constant sum. Now *P* has a table like this with relatively few numbers left -- if he now leaves in only the numbers that make the product he knows, he'll very likely be left with only one combination of numbers -- there are still many combinations like this, but only the situation when the numbers are set to be 4 and 13 allows *S* to also deduce the numbers after *P* declares he knows the numbers -- this is because *S* knows the combination lies on one specific constant-sum diagonal and 4-13 lie on the only diagonal that in this situation has a unique product within the reduced table. So with some other combinations *P* could deduce the numbers too, but only with 4-13 *S* can finally say he knows them too.
41. Hash table will only allow efficient searching of exact matches while binary tree will also allow efficient searching e.g. for all strings starting with some prefix. On the other hand hash table may be faster, in ideal case searching for the match in constant time, but this will depend on the quality of implementation (hash function, number of hash bits, ...), in worst case hash table can degenerate to a mere list. Binary trees will generally be a bit slower, with logarithmic time, but here we'll also have to ensure good implementation, especially balancing the tree -- badly implemented tree may also degenerate to a list.
42. They are two of triplets (or quadruplets, ...).
43. For example: application layer (highest level layer, concerned with applications communicating with each other, addressing by ports, protocols: HTTP, Gopher, FTP, DNS, SSH, ...), transport layer (middle level layer, concerned with delivering data over a potentially unreliable channel, implements establishment of connection, handshakes, reliable delivery, delivering in correct order etc., protocols: TCP, UDP, ...), network layer (below transport layer, concerned with delivering packets over a network, implements routing, forwarding etc., addressing by IP addresses, i.e. numerical machine addresses, protocols: IPv4, IPv6, ...), OSI physical layer (lowest level layer, concerned with sending bits between two directly connected devices, works with frequencies, electronic circuits etc., no addressing, protocols: ethernet, USB, Bluetooth, ...), ...
44. Certificate is a file that contains the domain's public key (needed to communicate using asymmetric cryptography) that is [digitally signed](digital_signature.md) by some "trusted authority", a business that declares itself to be trusted and lets itself be paid for cryptographically confirming that public keys belong to specific servers. Without certificates a [man in the middle](man_in_the_middle.md) "attack" could be performed in which a middle man could sneakily swap a public key that's being transmitted for his own public key which would then allow him to listen to the unencrypted communication.
45. yes
## Other