Some bits I wrote in C. They are all very small programs in one C file.
Programs here are in public domain.
Some of them can be compiled using Tom Duff's com program.
romint.c | romint deals with roman numerals. To convert an arabic number into a roman one, use '-r', to do the converse use '-a'. |
calc.c | calc is a tiny C99 integer desktop calculator. It computes the result of simple arithmetic expressions. I wrote it to use the Shunting-yard algorithm of E. Dijkstra to parse mathematical expressions. Very few operations are supported (+ - * %), but it is quite small. See also eexp.c. |
hanoi.c | hanoi will solve the classical problem of the towers of Hanoi with N disks. |
pi.c | pi will compute many digits of pi using a spigot algorithm by Rabinowitz and Wagon. Use the -n option to specify the number of digits needed. It will work at a very decent speed for the first hundreds of digits. The output of the program for '-n 100000' can be seen here. |
permut.c | permut will display the list of all permutations of N objects, where N is a parameter specified at run time as the only option of the permut program. |
avl.c | This C file is a simple recursive (for most functions) implementation of balanced trees by G. M. Adelson-Velskii and E. M. Landis. I rewrote it from scratch to enjoy a copyright free, public domain implementation of this useful data structure. One basic test program is also available: avltest.c. This is still work in progress. BUG: On 01/22/2016 I fixed a problem in the ins function! |
spline.c | This short C file is a trivial implementation of cubic Hermite splines in dimension D. This is typically used to find a smooth curve interpolating a given set of points. An example X11 program using it is available here: xspline.c. See also the screenshot. |
serve.c | This program is a simple one time use HTTP server convenient to move a file between computers in a user friendly way. It takes a parameter -n to indicate the maximum number of times the file can be downloaded, a negative value means no limit. From the downloader's point of view, a 'Save as' dialog box is displayed with a hint for the file name. |
q.c | This program when compiled will simply print its source code. It is not exactly portable C since it relies on ASCII as the character encoding used. There are C one-liners that use printf, this one does not use it. I guess we could make it shorter, though. This kind of program is commonly called Quine. |
earth.c | earth is an animated wallpaper for X11. It will display our planet with proper lighting depending on the current time. In its default mode it will open a new window to render, use -r to render in the root window instead. In window mode, you can spin the earth using left and right arrows, more details are provided on top of the C file. |
hilbert.c | This will create a PostScript file displaying one iteration of Hilbert's curve construction. I did this starting from the visual pattern of Hilbert's curve and reverse engineering the algorithm. For example, the output of the program for the seventh curve yields the following rendering (converted to PDF via ps2pdf). |
algsum.c | algsum computes one polynomial zeroing the sum of two algebraic integers. The two input algebraic integers are given as monic polynomials which zeroes them; for instance "i" is given as "x² + 1". The algorithm used is directly based on the proof that algebraic integers form a ring. To get a short description of the input format, see the C file's header. |
subs.c | subs extracts all substrings of a given length in a text. I use it combined with sort and uniq to find repetitive patterns in some code I would like to submit to the IOCCC. |
eexp.c | eexp was a way for me to experiment with LR parsing table generation. I defined a small SLR(1) grammar for arithmetic expressions and built the parsing tables by hand. They are packaged in this program that implements a minimal infix notation desk calculator. |
cube.c | A fun program that displays a spinning cube with ascii art in your terminal. You can customize to rotation speed with three command line parameters, it is also possible to change the "color" of each face in the source code. The technique used is simple raycasting. |
mprobe.c | This is an xbiff program for the command line, it is best used in a dedicated terminal or in a tmux window. The ASCII art for the mailbox is really miserable so feel free to submit me improvements... Just list all the mbox files you want to monitor as arguments. |
markov.c | Generates gibberish using Markov chains learned from an input text. Many typographical conventions are not handled properly and I am not sure how correct this program is... If you want to have some fun, use books from the Gutenberg project as learning sources. The compilation requires avl.c. |
epig.c | Prints one epigram from Alan Perlis' Epigrams on Programming. Alan Perlis was the first Turing award recipient. |