Perl Quiz-of-the-Week #12
Mark Jason Dominus <[email protected]> Wed, 12 Feb 2003 19:53:08 -0500
| Newsgroups | gmane.comp.lang.perl.qotw.quiz-of-the-week |
|---|---|
| Organization | Plover Systems |
| Message-ID | <[email protected]> |
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message.
Thanks.
IMPORTANTE: Por favor, no enviéis soluciones, pistas, o cualquier otra
cosa que pueda echar a perder la resolución del problema hasta
que hayan pasado por lo menos 60 horas desde el envío de este
mensaje. Gracias.
IMPORTANT: S'il vous plaît, attendez au minimum 60 heures après la
date de ce message avant de poster solutions, indices ou autres
révélations. Merci.
WICHTIG: Bitte schicken Sie keine Lösungen, Tipps oder Hinweise für
diese Aufgabe vor Ablauf von 60 Stunden nach dem Datum dieser
Mail. Danke.
BELANGRIJK: Stuur aub geen oplossingen, hints of andere tips in de
eerste 60 uur na het verzendingstijdstip van dit
bericht. Waarvoor dank.
VNIMANIE: Pozhalujsta ne shlite reshenija, nameki na reshenija, i
voobshe lyubye podskazki v techenie po krajnej mere 60 chasov
ot daty etogo soobshenija. Spasibo.
Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60
Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4
Xie4Lou4 Da2An4 De5 Jian4Yi4. Xie4Xie4.
----------------------------------------------------------------
You'll write functions for displaying histograms (bar charts).
We'll use these to display the output from next week's quiz.
You're build one function, 'histogram()', whose arguments will be a
list of numbers. The function should construct a bar chart and then
return a list of strings which, if printed, would display the numbers
suitably.
For example,
histogram(1, 4, 2, 8, 5, 7)
might return the following list of strings:
" *\n",
" * *\n",
" * *\n",
" ***\n",
" * ***\n",
" * ***\n",
" *****\n",
"******\n"
when printed, these strings look like this:
*
* *
* *
***
* ***
* ***
*****
******
The behavior of 'histogram' will be controlled by several global
variables. $HISTOGRAM_WIDTH and $HISTOGRAM_HEIGHT will specify the
width and height of the result. The output should be scaled to fit in
a rectangle with $HISTOGRAM_HEIGHT rows and $HISTOGRAM_WIDTH rows.
The bars themselves will be made up of the character $HISTOGRAM_CHAR,
which must be a string of length 1.
If any of the $HISTOGRAM_ variables are undefined, the function should
use reasonable defaults.