Wednesday, December 11, 2024

HTML table year calendar

I wrote a simple new program in Perl, yeartable.pl, another one like this other old calendar program, but now I try to visualize all the days of a given year in one page, suitable to be copied to your favourite word processor and then printed, to get a calendar like this:

Calendar table view in spanish

To run it you need to provide the year, the names of the months and the names of the week days, for example:

$ perl yeartable.pl
Use: perl yeartable.pl YEAR "Jan,Feb,..." "Sun,*Mon,..."
(put * in the week-day to be the first row in the table)
$ perl yeartable.pl 2025 "Jan,Feb,Mar,Apr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic" "S,*M,T,W,T,F,S" > 2025.html

And then you can open the generated file with an internet browser, copy the table directly to a word processor and adjust the format. Enjoy!

Using jugs of known capacities to get certain quantity

Suppose you only have a few containers of known capacities for measuring quantities, for example two jugs of 5 and 7 litres of capacity respectively, and you want to use them to obtain exactly 1 litre, for example. Can you do it?

jars 7 5 litres

To solve this kind of problems, I wrote a simple Perl program, jugs.pl, that explores the solutions using a brute-force backtracking algorithm limiting its recursivity level for finding the solutions with minimum steps.

There are two versions of these problems, one having a limited quantity of the substance to be moved from one jug to another, and other having an unlimited quantity available to fill any jug and discard it. My program only supports the first version, since the second one can be simulated by creating one jug filled with a large quantity that represents the source and sink of the substance, for example:

jars 20 7 5 litres

This way you can use the program to print a solution for the problem:

$ perl jugs.pl 20,7,5 20,0,0 1
(12) (7) (1)    1->3 3->2 1->3 3->2 2->1 3->2 1->3 3->2
$ perl jugs.pl
Use: perl jugs.pl M1,M2,...,MX I1,I2,...,IX N [NUMSTEPS]
Minimum steps to obtain N units in one of X jugs
given the Maximum and Initial quantity for each jug.

This way you can explore different configurations to learn more from the problem, even setting the number of steps of the solutions. Enjoy!