This nifty assignment was developed by Steve Wolfman, Pratt 1997, ECE/CS Dual Major. We've made a few minor edits to give it a bit of a local flavor.
Please read this assignment and the associated How-To before you start programming.
The natural world is full of hidden and beautiful mathematics. The whorls of a conch shell hide the Fibonacci sequence and its Golden Ratio, plants grow in fractal patterns, and comets trace hyperbolic patterns through the solar system. All those beautiful patterns hide in the grungy data of human observation.
So, what are the populations of every town in North Carolina and the number of posts by various authors to a Duke sports bulletin board hiding from you?
n
and a list of numbers
from a file and outputs a list of 10 values: the frequency with
which each digit 0–9 appears as the n
th
digit of one of the input numbers.
To be human-readable, the data files should also allow labels for the data. We'll accomplish this by allowing commenting in the input file. Your program should ignore anything between (* and *). You may assume that the (* and *) symbols will be surround by whitespace and that nested comments — comments inside other comments — are not allowed. Below are enrollments in Research Triangle Park colleges and universities in Fall 2000 (thanks to the "Research Triangle Regional Partnership" website: http://www.researchtriangle.org/data/enrollment.html).
(* Duke University *) 12176 (* North Carolina Central University *) 5476 (* Louisburg College (Junior College) *) 543 (* Campbell University *) 3490 (* University of North Carolina at Chapel Hill *) 24892 (* North Carolina State University *) 28619 (* Meredith College *) 2595 (* Peace College *) 603 (* Shaw University *) 2527 (* St. Augustine's College *) 1465 (* Southeastern Baptist Theological Seminary *) 1858
If the user enters 0 as the value for n
, and thus chooses the
first digit, then your program should print:
In your README
, you should describe the distribution of
digits for each of the data files and how they conform or differ
from what you would expect from a random list of numbers.
Note: throughout this problem, you may
assume that the numbers processed are non-negative or you can use the
absolute value function Math.abs
to help you handle
negative numbers in a reasonable way.
(* *)
style above).