Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
24
10-02.md
24
10-02.md
|
|
@ -2,14 +2,14 @@
|
|||
[Previous](10-01.html) [Table of Contents](index.html) [Next](10-03.html)
|
||||
------------------------ --------------------------------- --------------------
|
||||
|
||||
Not so nowadays, though. Computers love boring work; they’re very
|
||||
Not so nowadays, though. Computers love boring work; they're very
|
||||
patient and disciplined, and, besides, one human year = seven dog years
|
||||
= two zillion computer years. So when we’re faced with a problem that
|
||||
has an obvious but exceedingly lengthy solution, we’re apt to say, “Ah,
|
||||
let the computer do that, it’s fast,” and go back to making paper
|
||||
= two zillion computer years. So when we're faced with a problem that
|
||||
has an obvious but exceedingly lengthy solution, we're apt to say, "Ah,
|
||||
let the computer do that, it's fast," and go back to making paper
|
||||
airplanes. Unfortunately, brute-force solutions tend to be slow even
|
||||
when performed by modern-day microcomputers, which are capable of
|
||||
several MIPS except when I’m late for an appointment and want to finish
|
||||
several MIPS except when I'm late for an appointment and want to finish
|
||||
a compile and run just one more test before I leave, in which case the
|
||||
crystal in my computer is apparently designed to automatically revert to
|
||||
1 Hz.)
|
||||
|
|
@ -18,7 +18,7 @@ The solution that I instantly came up with to finding the GCD is about
|
|||
as brute- force as you can get: Divide both the larger integer (iL) and
|
||||
the smaller integer (iS) by every integer equal to or less than the
|
||||
smaller integer, until a number is found that divides both evenly, as
|
||||
shown in Figure 10.1. This works, but it’s a lousy solution, requiring
|
||||
shown in Figure 10.1. This works, but it's a lousy solution, requiring
|
||||
as many as iS\*2 divisions; *very* expensive, especially for large
|
||||
values of iS. For example, finding the GCD of 30,001 and 30,002 would
|
||||
require 60,002 divisions, which alone, disregarding tests and branches,
|
||||
|
|
@ -88,7 +88,7 @@ Integer pairs for which to find GCD
|
|||
|
||||
**Listing 10.3**\
|
||||
(Division: code recursive\
|
||||
Euclid’s algorithm)
|
||||
Euclid's algorithm)
|
||||
|
||||
20\
|
||||
(33%)
|
||||
|
|
@ -106,7 +106,7 @@ Integer pairs for which to find GCD
|
|||
(0.12%)
|
||||
|
||||
**Listing 10.4**\
|
||||
(C version of data recursive Euclid’s algorithm; normal optimization)
|
||||
(C version of data recursive Euclid's algorithm; normal optimization)
|
||||
|
||||
12\
|
||||
(20%)
|
||||
|
|
@ -142,7 +142,7 @@ Integer pairs for which to find GCD
|
|||
(0.05%)
|
||||
|
||||
**Listing 10.5**\
|
||||
(Assembly version of data recursive Euclid’s algorithm)
|
||||
(Assembly version of data recursive Euclid's algorithm)
|
||||
|
||||
10\
|
||||
(17%)
|
||||
|
|
@ -200,7 +200,7 @@ Table 10.1 Performance of GCD algorithm implementations.
|
|||
|
||||
#### Wasted Breakthroughs {#Heading5}
|
||||
|
||||
Sedgewick’s first solution to the GCD problem was pretty much the one I
|
||||
Sedgewick's first solution to the GCD problem was pretty much the one I
|
||||
came up with. He then pointed out that the GCD of iL and iS is the same
|
||||
as the GCD of iL-iS and iS. This was obvious (once Sedgewick pointed it
|
||||
out); by the very nature of division, any number that divides iL evenly
|
||||
|
|
@ -213,13 +213,13 @@ in Listing 10.2.
|
|||
/* Finds and returns the greatest common divisor of two positive
|
||||
integers. Works by subtracting the smaller integer from the
|
||||
larger integer until either the values match (in which case
|
||||
that’s the gcd), or the larger integer becomes the smaller of
|
||||
that's the gcd), or the larger integer becomes the smaller of
|
||||
the two, in which case the two integers swap roles and the
|
||||
subtraction process continues. */
|
||||
|
||||
unsigned int gcd(unsigned int int1, unsigned int int2) {
|
||||
unsigned int temp;
|
||||
/* If the two integers are the same, that’s the gcd and we’re
|
||||
/* If the two integers are the same, that's the gcd and we're
|
||||
done */
|
||||
if (int1 == int2) {
|
||||
return(int1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue