Post Reply 
(49g 50g) Number of Trailing Zeros in N!
06-04-2022, 06:53 PM (This post was last modified: 06-04-2022 06:54 PM by John Keith.)
Post: #6
RE: (49g 50g) Number of Trailing Zeros in N!
Just for laughs, a couple of programs to print large integers as triangles. They are most useful on a PC-based emulator where the resulting string can be pasted into a text file and printed.

The first program makes a triangle where row n has 2n-1 digits, similar to Thomas' Python program if not as elegant. Input is an integer, output is a string centered at the 40th column. Maximum integer size is 1521 digits (39 rows). If the number of digits is not a square, the last row will be incomplete.

Code:

\<< \->STR -1. 40. 13. CHR 10. CHR + \-> k sp crlf
  \<< ""
    WHILE OVER SIZE
    REPEAT 'k' 2. STO+ 'sp' 1. STO-
      SWAP k SPLIT UNROT
      crlf + " " sp RPTCHR SWAP + +
    END NIP
  \>>
\>>

The next version makes a triangle where row n has n digits (like Pascal's triangle). The string is left justified. There is no maximum size but very large integers will make rows longer than 80 characters. If the number of digits is not a triangular number, the last row will be incomplete.

Code:

\<< \->STR 0. 13. CHR 10. CHR + \-> k crlf
  \<< "" SWAP
    WHILE DUP SIZE
    REPEAT 'k' 1. STO+
      k SPLIT UNROT crlf + + SWAP
    END DROP
  \>>
\>>

As an example, this is 570!:


1
19
647
5758
26679
992521
3150971
60611198
503056621
9007683399
48400991237
661587270341
8103894782133
53453090699254
154454320719614
5487509118626349
08696686820305004
379306247797103488
6790434213832213245
94841498332690282044
085187027223617659230
9518428094945979214940
56709685270263887874435
753547709167084262926620
3332741387705148411462271
23095175757304448772093194
373279490301207089965787664
8575127566724513575715482702
70788565544870146828024429021
833502813292623326287501458026
9161119577367392188068125282549
20234801893594111768456673065490
279986528074506746792875128696146
7862034450599336508683729157632623
68712749711136718818742496831196746
909912133660990822097617434066349471
5222497263330885513955829086147220454
59821787316263806805289352977171927611
915931808505004008935038815697112288240
3089565859840019822465218311419147832147
74003130942944407137531510505316475042841
159819848160593032726584717409062104550132
5700007860560251989608104718347968735642475
43983373049782988651222694742053310200491418
863588405480343023964791498461218898945580264
8406113303807150001581953263761718561315680021
38450168036268440168979166079893774258519311891
845963565722703706788257300598498708086057505863
1759757312000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (49g 50g) Number of Trailing Zeros in N! - John Keith - 06-04-2022 06:53 PM



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