HN user

efdb

3 karma
Posts1
Comments12
View on HN
Pythonic monotonic 5 years ago

self documenting code ;-)

  def descending(lst):
    if len(lst) < 2:
        return False
    first, second = lst[:2]
    if first > second:
        return False
    if first < second:
        return True
    descending(lst[1:])

  def monotonic(lst):
    if len(lst) < 2:
        return lst
    result = []
    status = 0
    temp = [lst[0]]
    for v in lst[1:]:
        if v >= temp[-1] and status >= 0:
            if v > temp[-1]:
                status = 1
            temp.append(v)    
            continue
        if v <= temp[-1] and status <= 0:
            if v < temp[-1]:
                status = -1
            temp.append (v)    
            continue
        result.append(temp)
        temp = [v]
        status = 0
    result.append(temp)          
    return [list(reversed(x)) if descending(x) else x for x in     result]

In addition to this question I would like to know if you can in general say/proof that for every sequence which has some relation between the successive numbers there is a rational number whose decimal expansion is the same as the sequence.

NewLisp 6 years ago

Indeed great and very simple interop with C libs. I have looked and played with CL, Scheme, pico lisp, Clojure and Janet but keep coming back to Newlisp, because 'it just works' (for me), documentation is very good and has a lot of inbuild functions. Regarding the C interop I made some bindings for duckdb, termbox and libui at https://github.com/luxint.