\ Structure and Interpretation of Computer Programs, Exercise 3.56 \ enumerate, in ascending order with no repetitions, all positive \ integers with no prime factors other than 2, 3, or 5. 0 value seq variable seqlast 0 seqlast ! : lastseq ( -- u ) \ last stored number in the sequence seq seqlast @ th @ ; : genseq ( u1 "name" -- ) \ u1 is the factor for the sequence create , 0 , \ factor and index of element used for last return does> ( -- u2 ) \ u2 is the next number resulting from multiplying u1 with numbers \ in the sequence that is larger than the last number in the \ sequence dup @ lastseq { u1 l } cell+ dup @ begin ( index-addr index ) seq over th @ u1 * dup l u<= while drop 1+ repeat >r swap ! r> ; 2 genseq s2 3 genseq s3 5 genseq s5 : nextseq ( -- ) s2 s3 umin s5 umin , 1 seqlast +! ; : nthseq ( u1 -- u ) \ the u1 th element in the sequence dup seqlast @ u+do nextseq loop 1- 0 max cells seq + @ ; : .nseq ( u1 -- ) dup seqlast @ u+do nextseq loop 0 u+do seq i th @ u. loop ; here to seq 1 , \ usage: 1000 .nseq \ 1000 nthseq .