List Commands Library for 50g

09182018, 03:32 PM
(This post was last modified: 09202018 12:38 PM by John Keith.)
Post: #391




RE: List Commands Library for 50g
The discussion of LMRPT reminds me of the recently added command LRPC\>. While it is the complement to the command LRPCT which runlength encodes a list, it can be very useful in its own right.
As an example, this simple program Code:
returns the first T(n) terms of A002024, where T(n) is the nth triangular number. The above program is similar to the second Haskell program in the OEIS link. It is also quite fast: given an input of 100, it returns the first 5050 terms in less than 700 milliseconds. A longer (and clunkier) example Code:
returns the nth iteration of the Kolakoski sequence. The program is longer and more involved than the Haskell program in the Kolakoski link because the infinite lists and "lazy" evaluation of Haskell make the explicit calculation of list lengths unnecessary. (Edited to remove the CEIL command following DavidM's comments below) These programs also demonstrate the similarity of LMRPT and LRPC\> to the Haskell functions cycle and replicate respectively. 

« Next Oldest  Next Newest »

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