Post Reply 
Bug or Not? Taking STRING of a string whilst making leading zeros
01-30-2018, 08:48 PM
Post: #11
RE: Bug or Not? Taking STRING of a string whilst making leading zeros
(01-30-2018 08:16 PM)Didier Lachieze Wrote:  Here is a version without the limitation of NZ<12:
Code:
EXPORT NZEROS(NZ)
BEGIN
 RETURN CAS("tail(string(10^NZ))");
END;

(01-30-2018 02:28 PM)Joe Horn Wrote:  Warning #2: In CAS programs, be sure to use the newer, smarter function STRING(), not its older, dumber sibling string(). Thankfully, Home always uses STRING().
What's the difference between the two functions?

Neat solution.
I am surprised that the obvious recursive solution is faster (and can recurse up to at least 1000 digits):
Code:

EXPORT ZEROS(NN)
 BEGIN
  IF NN>0 THEN
   RETURN "0"+ZEROS(NN-1);
  END;
  RETURN ""; 
 END;
I had expected that the recursive solution would be worse.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Bug or Not? Taking STRING of a string whilst making leading zeros - StephenG1CMZ - 01-30-2018 08:48 PM



User(s) browsing this thread: 1 Guest(s)