less_retarded_wiki/exercises.md

154 lines
42 KiB
Markdown
Raw Normal View History

# Exercises
2024-04-02 22:47:48 +02:00
**THIS IS CURRENTLY HIGHLY WORK IN PROGRESS**
2023-10-28 22:31:43 +02:00
Here there should be a set of exercise problems for those wishing to pursue [LRS](lrs.md) in any way.
2023-10-28 22:31:43 +02:00
{ Hmmm, it's hard to figure out exactly what to put here. ~drummyfish }
2023-03-18 16:53:50 +01:00
2024-04-07 20:25:34 +02:00
## Programming Challenges
2023-03-18 16:53:50 +01:00
2024-04-02 22:47:48 +02:00
See also [needed projects](needed.md).
Here you will find suggestions for programming projects, roughly sorted by their difficulty (in each level projects will be sorted roughly by difficulty too). You can use this to practice what you've learned in [c tutorial](c_tutorial.md), try to follow the [LRS](lrs.md) principles. We are kind of assuming you'll be programming these projects in [C](c.md) -- that's how we judge the difficulty etc. -- but of course no one is stopping you to make the project in another language if you so desire :)
2024-04-03 17:16:51 +02:00
**LRS programming challenge!** If you want you can treat this as a [game](game.md), kind of achievements you can collect. You can even make a git repo for your solutions so others can see and admire them { I'll be glad if you send me a link. ~drummyfish } Here are the rules:
2024-04-02 22:47:48 +02:00
- Award yourself points like this:
- 1 point for a completed project in level 0.
- 4 points for a completed project in level 1.
- 16 points for a completed project in level 2.
- 64 points for a completed project in level 3.
2024-04-07 20:25:34 +02:00
- 256 points for a completed project in level 4.
- If you complete all projects in level *N*, you can automatically consider all projects of all lower levels completed as well, i.e. if you complete whole level 2, count yourself whole level 1 and 0 as well. (Once achieved you'll keep it forever, i.e. if more projects later appear in given level that you won't have solved, it won't take away your lower level points.)
2024-04-04 21:32:43 +02:00
- A project is considered completed only if you really complete all the requirements! It is not enough to say "mmm, I could do this if I wanted" -- no, you have to REALLY DO IT to count. If the requirement is to make a complete game, a buggy demo doesn't count. Also if you just use some cheat, use 100 libraries to do everything for you, you know you didn't really complete it :) If it's obvious implementing something is part of the challenge (for example collision detection in physics engine), you cannot use a library for it, you have to do it yourself. Just be honest with yourself.
- You CANNOT award yourself partial points, i.e. if you meet 90% of requirements for some project, you CANNOT give yourself 90% points for it, not even one point. Complete it 100%, then get 100% points. Again, it doesn't count to say "mmm, I could finish this if I wanted" -- no, until you finish it it's not finished. This is part of the challenge and insisting on it also makes you potentially make a nice, tidy program that will increase good in the world ;)
2024-04-02 22:47:48 +02:00
- You may reuse your own code without it counting as third party library, i.e. if you write 3D renderer in one project, you can use it in writing 3D game as another project, with it counting as if you wrote everything from scratch just for that project.
- Don't [cheat](cheating.md), you're only cheating yourself :)
### Level 0: Trivial, *Piece Of Cake*
2024-04-03 17:16:51 +02:00
1. **hello**: Make a program that outputs `hello`.
2024-04-02 22:47:48 +02:00
2. **counting**: Make a program that outputs numbers from 1 up to 100.
3. **guess a number**: Make a game in which the computer secretly thinks a number from 0 to 9 and the player guesses the number. The computer then says if the player won and what the secret number what.
4. **password generator**: Make a program which when run outputs randomly generated password (the password must be different each time you run the program of course). The password must be at least 10 characters long, contain at least one decimal digit and one special character.
2024-04-07 20:25:34 +02:00
5. **rock, paper scissors**: Make a game of rock paper scissors, the player plays against the computer.
6. **average**: Make a program that reads two numbers (you can assume only non-negative integers will be input) and writes out their average (it can be rounded, even to just integer, e.g. 3 and 8 can give 5).
7. **[Nim](nim.md)**: Implement the simple variant of the game Nim for two human players -- At the beginning there will be 15 matches, players take turn, in each turn a player can take 1, 2 or 3 matches. That who takes the last one loses. The game has to show the number of matches as a numeral and also as some kind of symbols, for example: `|||||||||||||||`. Players have to input `1`, `2` or `3` to play their turn, on wrong input the game has to report error and ask again. At the end winner must be shown. Thumbs up for randomly setting the initial number of matches between 10 and 15.
2024-04-02 22:47:48 +02:00
### Level 1: Easy, *I'm Too Young To Die*
1. **[fizzbuzz](fizzbuzz.md)**: Write the classic fizzbuzz program.
2024-04-03 17:16:51 +02:00
2. **[anagram](anagram.md) checker**: Make a program that reads one line of text from the user and checks if it's an anagram (i.e. if it's spelled the same forward and backwards) or not -- you can just output *yes* or *no*.
2024-04-04 21:32:43 +02:00
3. **number [encyclopedia](encyclopedia.md)**: Make a program that writes numbers from 0 to 1000 (including both) and about each of which it writes some facts. These facts have to include at least the number's square, square root, sum of its decimal digits, its [binary](binary.md) representation, prime factorization and whether the number itself is [prime](prime.md), perfect number and [Fibonacci](fibonnaci.md) number.
2024-04-06 22:21:54 +02:00
4. **[game of life](game_of_life.md)**: Make a program that simulates game of life on a finite *N * N* grid, with wrapping space (i.e. a cell on the very left of the grid is considered a neighbor of the cell on the very right in the same row, same thing with top and bottom). Make *N* configurable at least as a compile time option, draw the world as [ASCII art](ascii_art.md) to terminal, make the user step forward by pressing some key. You can initialize the grid values randomly, but thumbs up for allowing setting the initial world state (e.g. reading it from a file or something).
5. **text adventure**: Make an interactive [CLI](cli.md) text adventure that will take an average player at least 10 minutes to finish. Part of game mechanics must involve inventory, i.e. picking up items, carrying them around and using them.
6. **calculator**: Make an interactive calculator -- it can be a purely [command line](cli.md) program into which user types expressions and your program evaluates them. The functionality must be at least on the level of the most plain physical calculators, i.e. it doesn't have to parse whole complex expressions, but it should be able to add, subtract, multiply, divide and find square roots. Results can be approximate, showing just 3 fractional decimal digits. Thumbs up for more features like handling expressions with brackets, having a variable storing last result, converting between bases and so on.
7. **[bytebeat](bytebeat.md)**: Make at least three cool sounding bytebeat songs.
2024-04-07 20:25:34 +02:00
8. **Lorem ipsum [markdown](md.md) generator**: Create a program that generates gibberish text in markdown format that looks like normal human text. Each time it is run, it will generate generally a different text that consists of 3 to 5 sections, each section starts with a heading which starts with `# ` after which 3 to 5 words follow, then there are two newlines and then 3 to 5 paragraphs follow; each paragraph ends with two newlines, except for the last one in the document which only ends with one newline. Paragraph consists of 5 to 10 sentences; each sentence consists of 3 to 10 words, starts with capital letter (other letters are lowercase) and ends with period. About 1 in 20 words in paragraphs are highlighted -- highlight is either italic (the word is between `*`s) or bold (the word is between `**`s). After period there is space except when it's the last period in a paragraph (then there is no space). Words are selected randomly from some set of words that you define (have at least 10 different words). Thumbs up for also generating lists etc.
2024-04-06 22:21:54 +02:00
9. **Caesar cipher**: Make a program that encrypts/decrypts text with the simple cipher known as Caesar cipher, i.e. by offsetting each letter by certain fixed number *N* (e.g. with *N = 2* the letter *A* will become *C*, *B* will become *D* etc.). Assume just ASCII characters on input (encrypted output can be non-ASCII). You can just choose and hardcode some specific *N* but thumbs up for allowing to set any *N*. You can input/output text from/to standard input/output or files -- it's up to you -- also you can either make one program that does both encoding and decoding (e.g. depending on CLI flag) or make two programs, one for each task.
2024-04-07 20:25:34 +02:00
10. **filetype guesser**: Create a program that reads a file and guesses its file type. You can NOT use the file name, only the file content. First look at the [magic number](magic_number.md) (file signature) -- check at least PDF, JPEG, PNG, MP3, GIF and TAR. If this doesn't succeed, then see if 90% of bytes are printable ASCII characters: if so, then guess the file to be TXT, otherwise you may report unknown type (or optionally you can try some extra checks if you want).
11. **[brainfuck](brainfuck.md) interpreter**: Make a program that interprets brainfuck. You may choose to read the input program either from standard input or from a file (the file may have some hardcoded name, e.g. your program will just look for a file named `program.bf` in the same directory). If the brainfuck program is invalid or runtime error occurs in it, you may just write out `error` and halt your interpreter. Thumbs up for making the interpreter nicer, e.g. allowing to pass input file name as a CLI argument, reporting more details about errors (e.g. its position in source code) and so on.
2024-04-02 22:47:48 +02:00
### Level 2: Mid, *Hurt Me Plenty*
2024-04-04 21:32:43 +02:00
1. **[chess](chess.md) without AI**: Make a program that allows two human players to play chess, AI is not required. It can be just a CLI program that draws the chessboard to terminal and reads moves by having players type the squares. Of course the program mustn't allow illegal moves, it must know if the game ended, who won (or if it's a draw) and so on. Implement all rules correctly, i.e. don't forget en passant, castling rights, stalemates and so on. Time controls are not required at all. Thumbs up for some basic recording of games, undos, showing playable squares or even having some kind of stupid AI (can just make random moves).
2. **2D game**: Make a complete 2D game in which you control a character, with at least 5 levels. Genre is up to you, recommended is e.g. platformer or top-down shooter. The game must have "real" graphics, i.e. not just terminal ASCII art -- using a library like [SAF](saf.md), Allegro or [SDL](sdl.md) may be a good choice. Sounds are not required but thumbs up if you have them.
2024-04-02 22:47:48 +02:00
3. **[gopher](gopher.md) browser**: Write interactive gopher browser -- it can be a purely [command line](cli.md) browser. It has to be able to follow links and go back at least one page. The program must include some basic help and ability to save files to disk.
2024-04-04 21:32:43 +02:00
4. **simple text [compression](compression.md)**: Write a program that can compress and decompress plain [ASCII](ascii.md) text files using some very simple technique like [run length encoding](rle.md) (RLE) or dictionary methods (you can even use a fixed dictionary, e.g. have a list of common English words that you will represent by some shorter symbols). You can assume input characters will only have 7bit ASCII codes, so you can compress the text also by dropping the 8th unused bit. You don't have to achieve great compression ratio (you can even enlarge some files), but you must pass the following test: take the program's source code, this article's plain text and Wikipedia main page plain text, your program must compress at least two of these to a smaller size (and of course successfully decompress them into identical files). The program must work as a [filter](filter.md), i.e. it mustn't load the whole file into memory or perform multiple passes, it has to use approximately same amount of RAM for input of any size.
2024-04-07 20:25:34 +02:00
5. **stupid chatbot**: Make an entertaining chatbot that can react to basic sentences like "how are you?", "are you a robot?", "tell me a joke" and so on. It must give a human-like answer to at least 50 different sentences. It has to deal with typos and text variability a little bit (for example multiple spaces in a row or all caps text mustn't confuse it). It must have a mood meter which changes depending on what the partner says -- for example if the bot gets insulted, it gets more angry and starts inserting profanity to responses; on the other hand if it's happy it will insert nice smiley faces etc. The bot also has to remember and use the name of its chat partner if that is brought up. Test the bot by having it chat with itself.
2024-04-04 21:32:43 +02:00
6. **arbitrary size [rational numbers](rational_number.md)**: Make a library that allows working with arbitrary size rational numbers, i.e. represent each number as a pair of numerator and denominator, the number will be automatically allocating itself as much memory as it needs for storing the two numbers. It mustn't waste too much memory, i.e. whenever it changes, it will try to reallocate its memory and decrease its size if possible. Size of the number will only be limited by amount of RAM your program can use. Furthermore implement these operations with the numbers: converting to/from the language's native numbers (with rounding if necessary), comparisons (equal, greater, greater or equal, smaller, smaller or equal), addition, subtraction, multiplication, division and printing and/or converting the number to string (at least decimal -- if the number has infinitely many fractional digits, just cut the output somewhere).
7. **image to [ASCII art](ascii_art.md)**: Make a program that takes an RGB bitmap image and renders it with ASCII characters (i.e. prints it out to console). You can support loading the image from just one file format of your choice, possibly something simple like PPM, BMP or Farbfeld. The program must support resizing the image and it must allow to just set one dimension with keeping the aspect ratio. Thumbs up for extra features like setting brightness/contrast and so on.
2024-04-03 17:16:51 +02:00
8. **educational [sorting](sorting.md) visualization**: Make a program for visualizing sorting algorithms -- it may draw real graphics (either directly to the screen or by outputting animation file) or just render ASCII art graphics, but it has to clearly show what the sorting algorithm is doing, i.e. which elements are being compared, which are swapped and if it makes good sense to highlight something else (like the pivot or already sorted part of the array), you should do it. Implement at least bubble sort, insertion sort, selection sort and quick sort. Also offer benchmark mode in which all algorithms race in sorting the same array (this can be without advanced visualization, just show e.g. number of steps for each).
2024-04-04 21:32:43 +02:00
9. **3D model of [fractal](fractal.md)**: Make a program that outputs 3D model of either Siepinski triangle or Koch snowflake fractal. The output shall be some simple 3D format like obj or Collada. The model can be primitive, i.e. it can be just flat shape made of triangles which don't have to really be connected, but the program must allow specifying the number of iterations of the fractal (during invocation, e.g. as a CLI flag). Check that the model is correct by opening it in some 3D editor such as Blender.
2024-04-03 22:57:42 +02:00
10. **[sudoku](sudoku.md) solver**: Create a program to which the user somehow passes a sudoku puzzle (in a file, through a CLI flag, interactively... the choice is yours, but passing a new puzzle mustn't require program recompilation) and the program attempts to solve it. It must first employ some basic reasoning, at very least it has to repeatedly try the elimination method, i.e. marking a set of possible values in each empty square and then reducing these sets by crossing out values that can't be in that square because the same value is in its column/row/minisquare -- wherever only one value remains in the set, it is filled in as final; this has to be repeated until no more progress is being made. If you want, you can employ other techniques as well. After this if the puzzle is still not solved, the program will resort to [brute force](brute_force.md) which has to eventually lead to solution (even if it would take too long). If the program finds that the puzzle is unsolvable, it has to report it.
2024-04-06 22:21:54 +02:00
11. **language recognizer**: Make a program that will be able to learn and then recognize language of text it is given (in theory it should work for any kind of language, be it human or computer language). Specifically the program will first get *N* files, each one representing a different language (e.g. 5 books in different human languages), then it will take some other text and say to which of the initial *N* files it is linguistically most similar. For simplicity assume only plain ASCII files on input (you can just use some Unicode to ASCII utility on all input files). Use some simple [machine learning](machine_learning.md) technique such as some variant of k-NN. It will suffice if for each training example you construct a vector of some nice features, for example {average word length, vowel/consonant ratio, relative frequency of letter A, relative frequency of letter E, ...}, give each component some weight and then just find the nearest neighbour to the tested sample in this feature space (if you want to be more fancy, split the input files into parts so you get more training samples, then try k-NN with some convenient k). You shouldn't and CANNOT use neural networks, and of course you CANNOT use any machine learning library ;) You don't have to achieve great accuracy but your program should likely be able to quite reliably tell e.g. German from C++.
2024-04-02 22:47:48 +02:00
### Level 3: Hard, *Ultra Violence*
2024-04-07 20:25:34 +02:00
1. **[quine](quine.md) master**: Without looking it up, write a quine in one language and radiation hardened quine in another language. Quine is a program that outputs its own source code (don't cheat, you can't read it from the source file), radiation hardened quine is a quine that remains a quine if you remove any single character from the program.
2. **non-trivial [programming language](programming_language.md)**: Design language *L*, write its specification and make a self hosted interpreter and/or compiler for it, i.e. write *L* in *L* (for this you may first have to write it in another language). *L* must be [Turing complete](turing_complete.md) and you have to provide mathematical proof of it. *L* must allow [recursive](recursion.md) function calls. It must not support native [OOP](oop.md). *L* must be usable for programming very basic things -- show it is so by writing [bubble sort](bubble_sort.md) in it. Write [quine](quine.md) in it. Thumbs up for also making a compiler.
2024-04-04 21:32:43 +02:00
3. **3D game**: Make a complete game with 3D graphics from 1st or 3rd man perspective that will have at least half an hour worth of gameplay time -- the gameplay can really be 2D (e.g. like [wolf3D](wolf3d.md)) but the graphics must be judged as 3D by average guy who sees the game. If your platform allows it at all, it must have basic sounds (no need for music, but e.g. shooting should at least make beeps and so on). The genre is up to you, it can be a shooter, platformer, RPG or anything where you control a character. For the 3D graphics you can either use a 3D library, in which case you HAVE TO implement textured graphics (the textures may be [procedural](procgen.md) if you want), or you can write your own renderer. If you write custom renderer, then if it's a "true 3D", it can have just flat, untextured graphics; if it's a "[pseudo 3D](pseudo3d.md)" (like raycasting or BSP, ...), it must have at least some texturing (e.g. walls).
4. **textured 3D [software renderer](sw_rendering.md)**: Make 3D software renderer that rasterizes triangles (just like for example [OpenGL](ogl.md)), with texturing. Affine texture mapping (i.e. the easier, incorrect texturing by linear interpolation of texturing coordinates in screen space) will pass, but thumbs up for perspective correct texture mapping. Implement some basic [shading](shading.md) like, e.g. Goraud with ambient and diffuse light. You have to handle visibility even of non-convex shapes, e.g. with z-buffer or at least approximately by sorting triangles. It's enough if you can display some textured model with setting camera position and rotation somehow. You don't have to handle any 3D formats, 3D models can just be passed as arrays of numbers (same with textures). It is enough if you output static images e.g. to a file, but thumbs up for being able to handle real-time rendering, animation and having extra features like transparency, scene graph and so on. Extra thumbs up for not using [float](float.md).
2024-04-02 22:47:48 +02:00
5. **[regular expression](regex.md) library**: Make a library for working with regular expressions. Implement at least the following operations: search of regular expression, substitution of regular expressions WITH capture groups and generating random strings by regular expression.
2024-04-04 21:32:43 +02:00
6. **[chess](chess.md) [AI](ai.md)**: Use any sane approach to write a chess engine of reasonable strength. No, you can't just fork stockfish, write it from scratch. It has to support xboard or UCI interface, the strength must be such that in usually wins at least once in a 10 game match against [smolchess](smallchesslib.md), Maia 1500, GNU chess, Dreamer, ChessMaster, Stockfish or similar engine with equivalent settings (search depth, time for move etc.); alternatively it can pass by getting stable rating over 1600 on lichess or by beating someone with FIDE rating over 1500 in a 10 game match. You get the idea.
7. **bitmap image editor**: [GIMP](gimp.md) is bloated! You have to save us by writing a GUI image editor that's at least a bit more advanced than the original MS paint. It has to be able to save and load images (supporting just one format is enough), draw basic shapes (at least a line, rectangle and circle), copy/paste parts of the image (with rectangle select), resize the image as a whole (with scaling it), have fill bucket and adjust brightness and contrast of the whole image. It should be reasonably user friendly, i.e. upon quitting it should ask if you want to save the work, it must have some basic help etc. Thumbs up for extra features like filters (blur, invert, edge detect, ...), layers and so on.
8. **64K intro**: Make an impressive [demoscene](demoscene.md)-style 3D intro with music. It must have duration of at least 1 minute and fit into a 64 KB executable. It has to be good enough so that an average demoscener would approve it as not completely laughable.
2024-04-03 17:16:51 +02:00
9. **3D [path tracer](path_tracing.md) without [floating point](float.md)**: Write a path tracer (NOT a mere [ray tracer](ray_tracing.md)) without using floating point. It can only produce static images that may just be saved to a file in some simple format (no need to draw real time animation to the screen). It must be possible to position and rotate the camera arbitrarily and to set its field of view. It has to support several shapes of objects in the scene: at least a sphere, plane and cylinder, and it must support transparent objects. Thumbs up for supporting polygonal models, depth of field and loading scene description from a file.
2024-04-04 21:32:43 +02:00
10. **[gopher](gopher.md) fulltext search engine**: Create a whole search engine (with crawler, index creator, user frontend, ...) for the gopher network. It can store its database just to flat files (no need to use SQL or something like that). It has to allow at least very basic fulltext search, i.e. about each gopher site you'll have to remember which words it contains (and possibly their count), so that if the user searched e.g. for `cats dogs`, you'll give him sites that contain both of these words somewhere in their text -- offer options to search either for sites containing all searched words or just some of them. Besides this you can make simplifications (ignore case, don't support Unicode, special characters etc.). Thumbs up for additional features like creating a graphical map of the crawled gopherspace along the way.
2024-04-06 22:21:54 +02:00
11. **[Jpeg](jpg.md) clone**: Create a usable format for photo images with lossy [compression](compression.md), similar to [Jpeg](jpg.md), that achieves good compression ratio and allows setting compression level, including setting compression level 0 (when it will only apply lossless compression). The format doesn't have to store any metadata, it's enough if it holds a 24 bit RGB bitmap of arbitrary resolution. For compression it must do at least following: separating the color and intensity channel and subsampling the color channel (see e.g. [YCbCr](ycbcr.md)), then converting the image to frequency domain (probably with [discrete cosine transformation](dct.md)) and quantizing the high frequencies, and then applying at least some lossless compression (RLE or Huffman coding or something). You can't use any libraries to do the described things (e.g. DCT, color conversion etc.), do it all yourself. The program, with medium compression level set, has to beat lz4 at compressing photos at least 90% times (in theory it should win always but we'll give you some margin if you fuck something up).
2024-04-07 20:25:34 +02:00
12. **console [emulator](emulation.md)**: Make an emulator of either [PlayStation 1](ps1.md), Nintendo64, GameGear or any version of [GameBoy](gameboy.md) (GB, GBC or GBA). You can use a library for 3D rendering if you need it. You don't have to implement networking or weird/non-standard features (like light sensor etc.). You don't have to achieve high accuracy but at least a few games should be playable. You have to allow saving/loading game states. Sound support can be basic.
13. **[genetic programming](genetic_programming.md)**: Create a [KISS](kiss.md) genetic programming framework. Make some kind of simple, low level model of computation, its language (something like Turing machine, brainfuck, Forth etc.) and its interpreter, then implement firstly generating random programs, secondly randomizing (mutating) existing programs and thirdly combining existing programs (creating offspring). Now create a system that will spawn a population of random programs and will then direct its evolution by generations toward optimizing performance at some given task -- this performance will be measured by fitness function (which will somehow score any given program depending on how well it's working) that will be customizable in your framework, i.e. anyone must be easily able to rewrite the fitness function to whatever he desires (it's okay if changing fitness function requires recompilation of your program). In each generation your framework will remove badly performing programs, breed new programs by combining well performing ones, randomly mutate some programs and add in a few new completely random programs -- specific parameters of this must also be curstomizable (again, recompilation here is okay). Test this by evolving some simple program (solving a maze, quadratic equation, blurring an image or something similar).
2023-03-18 16:53:50 +01:00
2024-04-02 22:47:48 +02:00
### Level 4: God Tier, *!Nightmare!*
2023-03-18 16:53:50 +01:00
2024-04-02 22:47:48 +02:00
1. **3D [physics engine](physics_engine.md) without [floating point](float.md)**: Warm up for the god tier by making a 3D physics engine without using floating point, usable in real time. It must support complex shapes, i.e. not just plain spheres ;) The engine can use rigid body or soft body physics, or both. It doesn't have to be physically accurate but should produce results that an average observer will judge realistic enough for a game.
2. **[operating system](operating_system.md)**: Make a whole [self hosted](self_hosting.md) operating system with your own custom kernel, with basic [GUI](gui.md) and tools such as a text editor, file browser and programming language compiler. Throw in some games because without them your OS will be boring. Run the OS on real hardware. It doesn't have to support networking, sound, USB and similar bloat, but thumbs up if you manage even that.
3. **[MMORPG](mmorpg.md)**: Make both client and server for an MMORPG game. The game has to support 3D graphics (but can also have 2D frontends) and have some basic lore that makes sense. Remember, it is MASSIVELY multiplayer game, so you have to be able to handle at least 1000 players connected at the same time on some kind of affordable computer. There must be chat, PvP and PvE combat. Thumbs up for releasing it all under [CC0](cc0.md).
4. **[Python](python.md)**: Implement the Python programming language, INCLUDING its whole standard library. Bonus points for finishing before the version you are implementing stops being supported.
2024-04-07 20:25:34 +02:00
5. **the grandest program of all time**: Make a program that (in a simplified way but still) simulates the whole [Universe](universe.md) and allows its user to explore and zoom in on anything not just in vast space but mainly on Earth, in big and small scales AND in all times in past and future, while the simulation approximately matches our available data (i.e. recorded historical events, famous people, geography, known bodies in the Universe etc.) and procedurally generates/interpolates/extrapolates unknown data (i.e. for example if we don't know what Napoleon did on a certain day, the program will make some guess and show him doing something). This will be the great visual encyclopedia in which one can observe the big bang, [Jesus](jesus.md), dinosaurs, black holes, the future destruction of Earth and so on.
6. **ruin [bitcoin](bitcoin.md)**: Make a program that can mine one bitcoin by running for at most one minute on some consumer laptop released before year 2010. Warning: this is probably unsolvable, but if you solve it you may help save the planet :P
2024-04-03 17:16:51 +02:00
2024-04-07 20:25:34 +02:00
TODO: text editor, tetris, voice synth?, snake, quadratic equation, fractals, 2D raycasting, fourier transform, primes, image library, web browser, diff, HTML parser/visualizer?, markov chain, syntax beautifier, grep, some kinda server, function plotter, pi digits, 2D physics engine, encryption?, custom markup lang, procedural MIDI, machine translation?, maze gen., genetic prog., language recognizer, AI?, photogrammetry, solar system simulator, emulator, chat (P2P?), auto integrator, steganography, driver? ...
2024-04-03 17:16:51 +02:00
2024-04-07 20:25:34 +02:00
## Quiz/Questions/Problems/Test
2024-04-03 17:16:51 +02:00
Here are some questions to test your LRS related knowledge :D
1. What's the difference between *[free software](free_software.md)* and *[open source](open_source.md)*?
2. Name at least 10 different [programming languages](programming_language.md).
3. Why is text written on a piece of paper flipped horizontally when viewed in a mirror -- why is it not flipped vertically?
4. Say we want to generate a random number from 0 to 999 (including both) with uniform probability distribution (i.e. every number is equally likely). In C we often do it using the modulo operator like this: `int num = rand() % 1000`. However there is a problem with this -- describe what the problem is and how its negative effect can be reduced. Hint: it's called *modulo bias*.
5. What's the difference between [data](data.md) and [information](information.md)?
6. Bob has written a program and died. The program is now [unmaintained](maintenance.md). Bob's program uses 10 libraries. The probability that the API of one such library will be [updated](update_culture.md) and changed in any given year is 5%. If this happens, Bob's program will stop working. During the next 5 years what is the probability of his program breaking?
7. What will the following C (C99) snippet print out? `int x = 2; putchar('a' + ((1 == 3 > 2) + ++x));`
8. Order the following software by the date of the release of their 1.0 version from oldest to newest: [TempleOS](temple_os.md), [MS DOS](dos.md), original [Unix](unix.md), [Linux](linux.md), [Windows](windows.md). Also point out which one stands out from others and why.
9. If you're running in a race and overtake the guy who's currently in third place, what place will you be in?
10. We have two gears, each of same size and same number of teeth. Gear A is fixed in place, it can't move or rotate, gear B runs around gear A so that it keeps touching it (and therefore rotates along the way) until it gets to the place where it started. How many revolutions around its own axis (from your stationary point of view) has gear B made?
11. What's the worst socioeconomic system in the world? You don't even have to say why because that would take too long.
12. Manually convert the [binary](binary.md) numeral 10110000000010110101 to hexadecimal.
2024-04-04 21:32:43 +02:00
13. How would you compute the circumference of a circle with radius *r* without using floating point? Consider just the approximate value of pi ~= 3.14, i.e. write the formula multiplying *2 * r* by 3.14 only using whole numbers (of course the result will be rounded to whole number too).
2024-04-06 22:21:54 +02:00
14. Name at least five licenses commonly used for [FOSS](foss.md) programs, five text editors/IDEs commonly used for programming and five operating systems whose source code is mostly free-licensed (none of these is allowed to be using the same or forked kernel of any other).
2024-04-07 20:25:34 +02:00
15. What is the minimum number of [bits](bit.md) that will allow us to represent 12345678910111213 distinct values?
2024-04-06 22:21:54 +02:00
16. Give at least one example of [analog](analog.md) electronic device and one of [digital](digital.md) mechanical device.
17. Answer yes/no to following: Is base-three number 2101 greater than base-seven number 206? Is [gemini](gemini.md) better than [gopher](gopher.md)? Is there any [triangle](triangle.md) (in Euclidean geometry) whose one side is longer than the sum of lengths of its other two sides?
18. 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.)
19. Solve these [anagrams](anagram.md): *no cure sir*, *come piss ron*, *ginger*, *nicer shops*, *fog tag*, *trek now*.
20. In 3D computer [graphics](graphics.md) what's the difference between [shading](shading.md) and drawing [shadows](shadow.md)?
2024-04-07 20:25:34 +02:00
21. Can we say [neural networks](neural_network.md) are [Turing complete](turing_complete.md)? Explain why or why not.
22. 22. Wicw mx uum yvfe bbt uhmtf ok?
23. What is the principle of [asymmetric cryptography](asymmetric_cryptography.md) and why is it called *asymmetric*?
24. 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 }
25. Did you enjoy this quiz?
2024-04-03 17:16:51 +02:00
### Answers
1. Though legally similar (but not identical), free software is a movement based on ethics and pursuing freedom for the software user, open source is evil business movement that avoids talking about ethics, it was forked from free software and is solely focused on exploiting free software licenses for making profit.
2. [C](c.md), [C++](cpp.md), [Java](java.md), [JavaScrip](javascript.md), [Python](python.md), [Lisp](lisp.md), [Forth](forth.md), [Brainfuck](brainfuck.md), [Fortran](fortran.md), [Pascal](pascal.md), [Haskell](haskell.md), [Prolog](prolog.md), [Smalltalk](smalltalk.md), [comun](comun.md), ...
2024-04-06 22:21:54 +02:00
3. The mirror doesn't really flip the text -- what's left/right in front of it is also left/right in it. It is you who flipped the text when you pointed it at the mirror -- you most likely flipped it horizontally so that's how you see it in the mirror, but you could as well have flipped it vertically; then the text would be flipped vertically in the mirror.
2024-04-03 17:16:51 +02:00
4. Modulo bias happens when the random number generator's range is non-divisible by our desired range that we enforce with modulo operator -- with shown approach some numbers then have higher probability of being generated than others. For example if rand() here return numbers from 0 to 1023, there is only one way to get 999 (999 % 1000) but two ways to get 0 (0 % 1000 and 1000 % 1000), i.e. 0 is more likely to be generated. Common approach to reducing this effect is to repeatedly generate numbers until we get one falling into the "fair" range (this is not guaranteed to end so we should limit the maximum number of attempts).
5. The relationship is commonly described like this: information is interpreted data. I.e. data is just a sequence of symbols, information is the knowledge we extract from it.
6. The probability of program breaking is 1 minus probability of it not breaking. For a program to NOT break during one year, all libraries have to stay unchanged (probability 0.95 for each one): that's 0.95 * 0.95 * 0.95 * ... = 0.95^10. Similarly the probability of it not breaking during 5 years is (0.95^10)^5, so the probability of the program breaking in 5 years is around 92%.
7. `e`
8. Original Unix (around 1970), MS DOS (1981), Windows (1985), Linux (1998), TempleOS (2007). Linux stands out because it's not an operating system, it's a kernel.
9. third
10. two (try it, see coin rotation paradox)
11. [capitalism](capitalism.md)
2024-04-04 21:32:43 +02:00
12. B00B5
2024-04-06 22:21:54 +02:00
13. *(2 * r * 314) / 100*
14. [GPL](gpl.md), LGPL, AGPL, [MIT](mit.md), BSD, Apache, [CC0](cc0.md), unlicense, zlib, WTFPL, ...; [vim](vim.md), [emacs](emacs.md), [Acme](acme.md), Geany, vi, Notepad++, Neovim, Kate, nano, gedit, ...; [Debian](debian.md), 9front, [OpenBSD](openbsd.md), [FreeDOS](freedos.md), [Haiku](haiku.md), [Minix](minix.md), ReactOS, [GNU](gnu.md)/[Hurd](hurd.md), V6 [Unix](unix.md), FreeRTOS, ...
15. The number is *N* such that 2^N = 12345678910111213, rounded up, that is ceil(log2(12345678910111213)) = 54.
16. amplifier, voltmeter, analog hardware for [neural networks](neural_net.md), ...; abacus, mechanical calculators such as Curta, Turing machine made of wood, ...
17. no, no, no
18. The walls will collide in 10 seconds during which the fly has been constantly flying with the speed 1 m/s, so it traveled 10 meters.
19. *[recursion](recursion.md)*, *[compression](compression.md)*, *[nigger](nigger.md)*, *[censorship](censorship.md)*, *[faggot](faggot.md)*, *[network](network.md)*.
20. 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.
2024-04-07 20:25:34 +02:00
21. 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.
22. two (or txq); The cipher offsets each letter by its position.
23. 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*.
24. 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.
25. yes
2024-04-06 22:21:54 +02:00
## Other
Make your own exercises in daily life, adopt a mindset of taking small intellectual (or even non-intellectual) challenges. Don't slip into conformist consumerist life of comfort and ignorance that will make your brain rot. Learn new things just for the same of it -- make a game, learn a new language, learn to play music, learn chemistry, paint a picture, learn [chess](chess.md), read a whole [encyclopedia](encyclopedia.md), read Quran, solve puzzles in magazines, construct a machine out of wood, collect rocks, write a book, compose a song, ... you get the idea. Even if you just play vidya games, at least play some puzzle game or a strategy game, or a creative sandbox game, or invent some self-imposed challenge and make it into a puzzle game if it's not, or write a bot that plays the game for you, don't be just a zombie staring into screen. It's good to make it a habit to do some small exercise every day, such as play one game of chess with your computer every single day, or watch one video about math etc. -- in a year or two you'll become pretty good at a new skill just by this. WARNING: do not confuse this with the so called "[self improvement](productivity_cult.md)" cult, you'd be retarded to join that.