RE (tilly) 3: The Big Test
by tilly (Archbishop) on Oct 17, 2000 at 19:10 UTC
|
Well if Perl were to do it like this human does, the test would be:
if ($number =~ /\D/) {
print "$number is not an integer\n";
}
elsif ($number =~ /[02468]$/) {
print "$number is even\n";
else {
print "$number is odd\n";
}
Honestly, that is *exactly* how I do it! :-) | [reply] [d/l] |
|
|
Actually, I prefer to test a number for even-ness using the same concept: Check the last digit, er... bit:
print "Odd" if $_ & 1;
print "Even" if not $_ & 1;
| [reply] [d/l] |
|
|
Yes, I use that too (it's been benchmarked as the fastest).
$_="goto+F.print+chop;\n=yhpaj";F1:eval
| [reply] |
|
|
Yes, a human tells if a number is even by checking the last
digit. But why does that work? Because we all (I think)
learned some really nifty tricks when we were little:
- A number is divisible by 2 if it ends in an even digit
(0, 2, 4, 6, or 8)
- A number is divisible by 3 if the sum of its digits is
3, 6, or 9 (and you keep summing the digits until you get
to a one-digit number)
- A number is divisible by 4 if its last two digits are
divisible by 4 (recursive, yes, but it takes a little extra
brain power to determine if a two-digit number is divisible
by 4)
- A number is divisible by 5 if its last digit is a 0 or
a 5
- A number is divisible by 6 if it's divisible by 2 and 3
- and so on...
So there's a connection between the last digit of a number
and its remainder modulo 2. That doesn't discount the fact
that even-ness is determined via the remainder of the number
modulo 2, it's just that the last digit modulo 2 is a shortcut.
$_="goto+F.print+chop;\n=yhpaj";F1:eval
| [reply] |
|
|
Um, japhy, I think I know the math quite well.
My point is that people don't think in terms of the logic behind it all. They don't. They really, really don't. People learn rather chaotically and only later (if ever) do they organize their world into something coherent that they can explain.
The problem is that programmers have to do that. And if you have been programming for a while, it becomes natural to start to think and understand in very different terms from the general public. It would be a serious mistake to confuse this difference for stupidity on the part of the general public. There are a lot of smart people who don't care to develop that skill. And when people first have to, it takes quite a bit of work.
Let me offer a few examples to drive this home.
The first is simple. Can you give a written description of how to tie your shoes? You (hopefully) have no problem doing it. Can you describe it?
The second involves your example. You throw around the word "modulo". Does your concept of modulo naturally include such concepts as taking polynomials over the integers and mapping them onto fields of algebraic numbers? Mine does! Are we talking about the same concept when we each say "modulo"?
The third will let you start some really good fights. It is part of a pair of questions I ran across once - and the fights will come from the knowledge that there is a verbal question that women find as easy as men find the question that I (a man of course) can remember. Here goes. Take a piece of paper and draw a cup. Draw a second cup tipped by 30 degrees. (Precision is not necessary.) Hand the picture to another person, and ask them to draw the water line if the cup is half-full of water (precision is not necessary).
Most adult men get this question right. Find it trivial. Find it unbelievable that anyone would have problems with it. The probability of success does not depend on education level.
Most adult women get this wrong. Will understand what the right answer is when they see it, but literally cannot see it. Again the probability of success does not depend on education level.
Until puberty there is no significant difference between the genders. Your ability to solve the problem (you are a mature male so I assume you will get it right) seems to be genetically determined. If you can do it it is simply astonishing that another would find it hard.
I ran across this nearly a dozen years ago now, and as I say it was one of a pair of questions. The other (which I got wrong) is a verbal question that women find easy and men fail to get, again the ability to solve it comes with puberty.
Before you make any more assertions about how people learn and think, please ask this question of several people of both genders. Ask, and think very hard about what you see.
Request:
Other than the fact it was a magazine I have no idea where this problem comes from or what the pair is. I have looked for it off and on for about a decade and have drawn blanks. If anybody knows of a reference or the paired problem, please tell me.
As I recall I read the magazine in some office, couldn't get the female problem, thought it was BS, found the male problem trivial. It was only a month or so later that I asked my gf of the time the problem as a joke and was astonished that she got it wrong. My mother did likewise. It has bugged me ever since.
| [reply] |
|
|
|
|
|
|
So there's a connection between the last digit of a number and its remainder modulo 2. That doesn't discount the fact that even-ness is determined via
the remainder of the number modulo 2, it's just that the last digit modulo 2 is a shortcut.
I think your mistaking a programming trick that resembles the human method for humans using the same method. 2 year olds can pick out even numbers, but can't do modulo. Just because you've learned how the computer "thinks", doesn't mean that people naturally think that way.
| [reply] |
|
|
One I used to see regularly when in my second Basic
class (*sigh*) was (in perl idiom)
if ($num/2 == int($num/2)) {print "$num even!\n":}
That still gives me the willies, though it is techically
correct(ish) and is more generally applicable than terminal
digit inspection =) Most people these days never got
taught what the mod function really does. Basic math
logic skills are passed off till college.
One thing I remember from Basic was that true was -1
and false was 0, and that all logical ops returned one
of those two values. We used to do this (sorta) in graphics programs
to get smoothly, randomly, changing colors and positions:
my @color= (127,127,127); #256x256x256 color palette
my @location= (50,50); #200x200 screen
for(;;) {
$color[0] += (int(rand*3)==1) - (int(rand*3)==1);
$color[1] += (int(rand*2)==1) - (int(rand*4)==1);
$color[2] += (int(rand*4)==1) - (int(rand*2)==1);
$location[0] += (int(rand*5)) - 2;
$location[1] += (int(rand*5)) - 2;
@color = map {$_ % 256} @color;
@location = map {$_ % 200} @location;
DrawPixel(@location,@color);
}
We did megacomplex things with math logic because
it was blazingly fast vs. if (){}; =) Seems like a
forgotten era now that I do web stuff.
--
$you = new YOU;
honk() if $you->love(perl) | [reply] [d/l] [select] |
|
|
| [reply] |
|
|
|
|
RE: RE: RE: The Big Test
by merlyn (Sage) on Oct 17, 2000 at 19:11 UTC
|
It's something a human should know how to do! How do you figure out of a number is even? It can be divided by two evenly!
japhy, you highly overestimate the knowledge of the populus. As a counter
example, notice the popularity of WWF,
including the number of people that swear it's real.
-- Randal L. Schwartz, Perl hacker
| [reply] |
|
|
Right. There are people who do not know how to find patterns,
and they should not be programming.
$_="goto+F.print+chop;\n=yhpaj";F1:eval
| [reply] |