[Talk] Question about scripts
Nick Simicich
talk@flux.org
Fri, 8 Sep 2006 10:37:45 -0400
On Thu, 7 Sep 2006 14:19, Kwan Lowe wrote:
> Not really Linux related so I'm posting it here...
>
> Say you get a request to print out the first 10 digits of Pi in the
> fewest possible
> number of lines (source). You turn in the following:
>
> #!/bin/sh
> echo "3.141592653"
Leave out the first line, /bin/sh is understood as a special case
default by exec(2).
> The instructor marks it wrong, and argues that it's contrary to the
> spirit of the
> assignment. What do you folks think?
You gave the assignment as "print out", not "calculate and print out".
If he gave the assignment that way, I'd take him to the dean.
I once had a friend who had an assignment in Fortran programming that
could not be done because when done in the most obvious way, it suffered
an overflow on their DEC machine. Before IEEE floating point, different
manufacturers built floating point unite to different standards, and IBM
had allowed more exponent bits.
He called me and I suggested two alternatives. One was using logarithms
and the other was to keep the intermediate results in an array - he used
the array method, and solved the problem. The instructor failed him
without looking at his program, he assumed that he had worked it out by
hand and written a program to print the result, while turning in some
fake program. He "knew", you see, that there was an intermediate resukt
that overflowed on their DEC.
In a subsequent meeting between him, the Dean, and the instructor which
was highlighted by him walking them through the program and showing how
he solved it, it came out that the instructor knew no Fortran and could
not actually read my friend's program. He was not invited back the
following term.
Many languages have a pi constant, would that have been acceptable?
In apl it could have been written as:
QQ<- 11 T QQ <- O 1
Where QQ is the quad quote
T is take
O is large circle
The numeric pi is converted to a string, and then the first 11 positions
of the string are extracted and output.
--Nick Simicich njs@scifi.squawk.com