Why Take Time to Do An Hour of Code
Some of the mathematics that is most relevant to programming is known as “discrete mathematics”. This is the mathematics of discrete elements, such as symbols, character strings, truth values, and “objects” (to use a programming term) that are collections of properties. Discrete mathematics is concerned with such elements; collections of them, such as sets and sequences; and connections among elements, in structures such as mappings and relations. In many ways discrete mathematics is more relevant to programming than numerical mathematics is: not just to particular kinds of programming, but to all programming. Many experienced programmers approach the design of a program by describing its input, output, and internal data objects in the vocabulary of discrete mathematics: sets, sequences, mappings, relations, and so on. This is a useful habit for us, as programmers, to cultivate. It can help to clarify our thinking about design problems; in fact, solutions often become obvious. And we inherit a well-understood vocabulary for specifying and documenting our programs and for discussing them with other programmers.
First I'll read the first web page and store all the URLs I find in a list. Then I'll read the second web page and, every time I find a URL, search the list for it. But wait: I don't want to include the same URL in my result more than once. I'll keep a second list of the URLs that I've already found in both web pages, and search that before I search the list of URLs from the first web page.
But a programmer who is accustomed to thinking in terms of discrete mathematical structures might immediately think of a different approach: The URLs in a web page are a set. I'll read each web page and build up the set of URLs in each using set insertion. Then I can get the URLs common to both web pages by using set intersection. Either approach will work, but the second is conceptually simpler, and it will probably be more straightforward to implement. In fact, once the problem is described in mathematical terms, most of the design work is already done.
Let's Code and Earn Credits
Period 1 -khanacademy.org/coaches
Class Code: N4E8N4EZ
Period 2 - Hour of Code 7N7ZQ778
Period 3 - Hour of Code UN4YBFX2
PERIOD 4 -Hour of Code M6G75VS6