Archive for the ‘Algorithms’ Category

How to convert from pixels to millimeters

Wednesday, July 2nd, 2008

I am working with PHP and FPDF to generate a PDF invoice. The designers have created a couple of very helpful documents, there are three total. The first is a mockup of the invoice. The second shows fonts, font sizes, and font colors. The last document show the positioning of all elements on the invoice. My only problem, is that the document was made with pixels at a resolution of 300 DPI rather than in millimeters. Anyone that is familiar with FPDF will know that PDF’s created with FPDF can not be generated with pixels in mind. PDF documents in FPDF can only use point (pt), millimeteres (mm), centimeters (cm), or inches (in). (more…)

Rounding to the nearest half dollor (or quarter dollar)

Wednesday, June 18th, 2008

One of my recent projects required that I round the price I was calculating to the nearest half dollar. This started out at a pain. Rounding to the floor, or to the ceiling, or normal rounding is quite easy. But I have never had to round to the nearest half dollar. (or quarter dollar) After a little bit of time thinking about it, I came up with a solution. (more…)

EVEN-EVEN Simulation

Tuesday, January 22nd, 2008

Simulate the EVEN-EVEN automaton found in the book in code. Don’t just “solve the problem”—implement the machine (i.e., there should be evidence of the states and transitions in your code). Input at least the strings below. The output should echo the string in quotes and indicate whether it is in the language EVEN-EVEN or not.

a, abab, aabbab, baab, <the empty string>
(more…)


Switch to our mobile site