less_retarded_wiki/exercises.md
2024-04-02 22:47:48 +02:00

16 KiB

Exercises

THIS IS CURRENTLY HIGHLY WORK IN PROGRESS

Here there should be a set of exercise problems for those wishing to pursue LRS in any way.

{ Hmmm, it's hard to figure out exactly what to put here. ~drummyfish }

Programming Projects

See also needed projects.

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, try to follow the LRS principles. We are kind of assuming you'll be programming these projects in C -- 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 :)

LRS programming challenge! If you want you can treat this as a game, kind of achievements you can collect. You can even make a git repo for your solutions so others can see and admire them { Pls send me the repo if you make it. ~drummyfish } Here are the rules:

  • 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.
  • 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 level 2, count yourself whole level 1 and 0 as well.
  • 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 :) 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 ;)
  • 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, you're only cheating yourself :)

Level 0: Trivial, Piece Of Cake

  1. hello world: Make a program that outputs hello world.
  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.

Level 1: Easy, I'm Too Young To Die

  1. fizzbuzz: Write the classic fizzbuzz program.
  2. number encyclopedia: Make a program that writes number 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 representation, prime factorization and whether the number is prime, perfect number and Fibonacci number.
  3. brainfuck 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 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.
  4. game of life: Make a program that simulates game of life on a finite N * N grid, with wrapping (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 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 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 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, converting between bases and so on.

Level 2: Mid, Hurt Me Plenty

  1. chess 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 draw 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 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. Sounds are not required but thumbs up if you have them.
  3. gopher browser: Write interactive gopher browser -- it can be a purely command line 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.
  4. simple text compression: Write a program that can compress and decompress plain ASCII text files using some very simple technique like run length encoding (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, i.e. it mustn't load the whole file into memory, it has to use approximately same amount of RAM for input of any size.
  5. stupid chatbot: Make an entertaining chatbot that can react to basic sentences like "how are you?", "are you a robot?" and so on. It must give a human-like answer to at least 20 different sentences. It has to deal with typos and text variability a little bit and has to have some kind of memory (for example it can remember the name of its chatting partner). Test the bot by having it chat with itself.
  6. arbitrary size numbers: Make a library that allows working with arbitrary size fixed point numbers, i.e. you will provide a data type in which it is possible to store a binary number with any number of bits before and after the radix point -- size of the number will only be limited by amount of RAM your program can use. Each number will dynamically allocate as much memory as it needs. Additionally implement these operations with the numbers: converting to/from the language's native numbers (with rounding), printing and/or converting the number to string, addition, subtraction, multiplication and dividing.
  7. image to ASCII art: 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.

Level 3: Hard, Ultra Violence

  1. non-trivial programming language: Design language L and make an interpreter for it. L must be Turing complete and you have to provide mathematical proof of it. L must allow recursive function calls. It must not support native OOP. L must be usable for programming very basic things -- show it is so by writing bubble sort in it. Write quine in it.
  2. radiation hardened quine: Without looking it up, write radiation hardened quine in some 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.
  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) 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 moving through 3D world. 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 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" (like raycasting or BSP, ...), it must have at least some texturing (e.g. walls).
  4. textured 3D software renderer: Make 3D software renderer that rasterizes triangles (just like for example OpenGL), 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 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. 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.
  5. regular expression 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.
  6. chess AI: 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 it beats smolchess, Maia 1500, GNU chess, Dreamer, Stockfish or similar engine in a 10 game match with both engines having 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 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 etc. Thumbs up for extra features like filters (blur, invert, edge detect, ...), layers and so on.
  8. 64K intro: Make an impressive demoscene-style 3D intro with music that's at least 1 minute long and fits into 64 KB. It has to be good enough so that an average demoscener would approve it as not completely laughable.

Level 4: God Tier, !Nightmare!

  1. 3D physics engine without floating point: 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: Make a whole self hosted operating system with your own custom kernel, with basic GUI 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: 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.
  4. Python: Implement the Python programming language, INCLUDING its whole standard library. Bonus points for finishing before the version you are implementing stops being supported.
  5. ruin bitcoin: Make a program that can mine one bitcoin by running for at most one minute on any consumer laptop released before year 2010. Warning: this is probably unsolvable, but if you solve it you may help save the planet :P

TODO: text editor, demo, tetris, voice synth?, snake, JPG like compression, quadratic equation, compression, 2D raycasting, fourier transform, primes, image library, web browser, arbitrary size int, diff, MD parser, sudoku solver/generator, bytebeat, markov chain, grep, some kinda server, chatbot, function plotter, raytracer, pi digits, 2D physics engine, encryption?, procedural MIDI, machine translation?, language recognizer, search engine, AI?, ...

Quiz

TODO: some questions + answers here