·······@pegasus.cc.ucf.edu (Jason Soukeras) wrote:
..
>If I figure out what 1000! is
>and divide it by a number that is 3 digits shorter... and then do the
>same thing w/ another number that is 3 digits shorter but one more than
>the first...will the portion of the answer to the left of the decimal
>place be the same?
..
Well, ok. I took the bait and ran your test [code and results at
end]; however, then I noticed that it's trivial to calculate the
result as long as I take your example as the definitive specification.
That is, as long as the denominator should be 1000! minus the 3 least
significant digits the answers are 1000.0 and 999.nnnn where n <> 0.
The 3 least significant digits must all be 0 because
1000 * 999! = 999! followed by 3 zeros. Thus,
(truncate 1000! 1000) is 1000.0 and has nothing to the
right of the decimal (i.e., no remainder.)
Given this, you know that (truncate 1000!/((1000!/1000) - 1)) =
the other answer minus 1 to the left of the decimal and a non-zero
remainder.
Thus, both the left and right differ from the other answer.
(defun factorial (n)
(if (zerop n)
1
(* n (factorial (1- n)))))
(defun test (n)
(setf n (factorial n))
;;get rid of the least 3 significant digits
(let ((denominator (truncate n 1000)))
(multiple-value-bind (left1 right1)
(truncate n denominator)
(multiple-value-bind (left2 right2)
(truncate n (1+ denominator))
(format t "The values to the left are ~:[not ~]equal~%~
...to the right are ~:[not ~]equal"
(= left1 left2)
(= right1 right2))))))
;;;; output from test
? (test 1000)
The values to the left are not equal
..to the right are not equal