Cellophane is a thin, transparent sheet made of regenerated cellulose. Cellulose fiber from wood, cotton or hemp is dissolved in alkali and treated with carbon disulfide to make a solution called viscose. This solution is then extruded through a slit into a bath of dilute sulfuric acid and sodium sulfate to reconvert the viscose into cellulose. The film is then passed through several more baths, one to remove sulfur, one to bleach the film, and one to add glycerin to prevent the film from becoming brittle.

cellofaan
Cellulose fiber from wood, cotton or hemp is dissolved in alkali and treated with carbon disulfide to make a solution called viscose.

Cellophane was invented by Swiss chemist Jacques E. Brandenberger. It took ten years for Brandenberger to perfect his transparent film, before cellophane was patented in 1912. Cellulose film has been manufactured continuously since the mid-1930s and is still used today. As well as packaging a variety of food items, there are also industrial applications, such as as a base for such self-adhesive tapes (including Sellotape and Scotch Tape) and as a semi-permeable membrane in a certain type of battery. Cellophane sales have dwindled since the 1960s, due to alternative packaging options and due to the polluting effects of carbon disulfide and other by-products of the process used to make viscose.

Assignment

A rectangular grid is drawn on a flat surface — for example a window or a lighted plate used by doctors to view x-ray images. The rows of the grid have been numbered left to right starting from zero, as do the columns from top to bottom. Some rectangular cellophane sheets are attached to the surface, with each sheet exactly covering some of the squares in the grid. These transparent sheets are either colored red or blue. If a square is covered by one or more red sheets it is colored red. If a square is covered by one ore more blue sheets it is colored blue. If a square is covered by at least one read and at least one blue sheet, it is colored purple.

cellofaan

Determine how many purple squares you get if the grid on a surface is covered by a given series of red and blue sheets. This is done in the following way.

Example

In the following interactive session, we assume that the file cellophane.txt1 is located in the current directory. The arrangement of the cellophane sheets on the grid corresponds in both cases to the arrangement in the above figure.

>>> purple([(0, 0, 5, 5, 'R'), (10, 0, 5, 5, 'R'), (3, 2, 9, 2, 'B')])
8

>>> cellophane('cellophane.txt')
8