heatdeath
heatdeath is a perl script that will model entropy in a closed system over a certain amount of iterations (or until entropy is at maximum).
It works by creating a matrix (of the dimensions you specify) of numbers, with all theodds on the top and all the evens on the bottom, and swaps two numbers at random until maximum entropy is reached or the maximum number of tries is hit.
The numbers to swap are chosen randomly by Crypt::Random, and only adjacent numbers are swapped.
heatdeath indexes how much entropy there is in the system after each swap, on a scale from 0 (complete order, all the evens on one side and all the odds on another) to 1 (complete disorder). It prints out a graph using GD::Graph showing the entropy in the system over time. An example can be seen here.
It is also possible to print out the matrix at any given time by calling 'display' in the code, feel free to modify it yourself or suggest features (such as other data to track, or optimisations).
Releases
- heatdeath-1.0 - 2009-10-07
Usage
You have to at minimum pass the length of one side of the grid (2 for 2x2, 4 for 4x4, 6 for 6x6), which has to be an even number. You also should pass the maximum number of swaps that should be made before the program exits (so as to prevent the program from running forever if maximum entropy is never reached, which is a small possibility). Additionally you can also pass the imagename that will be used as a third argument.
This will run heatdeath for a maximum of 100 swaps over a 4x4 grid. The image will be printed to the current working directory as a .png file:
heatdeath 4 100
This will run heatdeath as before, but print the graph to heatdeath-4-100.png:
heatdeath 4 100 heatdeath-4-100.png
License
heatdeath is released under the MIT/X Consortium License. A copy of the license can be found in the release tarballs.