I use notepad++, but i'd like to use VSCode on mac :-)
I'll try it as soon as possible.
It's possible to execute the current line on newLISP REPL?
It's possible to execute the active selection on newLISP REPL?
Thanks again.
cameyo
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(define (maxProd lst)
(local (n maxprod pos neg)
(setq n (length lst))
(setq pos (array n '(0)))
(setq neg (array n '(0)))
(setq (pos 0) (lst 0)) ; pos[i] contains the positive product up to lst[i]
(setq (neg 0) (lst 0)) ; neg[i] contains the negative product up to lst[i]
(setq maxprod (lst 0))
(for (i 0 (- n 1))
; the maximum of the three values
(setq (pos i) (max (max (* (pos (- i 1)) (lst i)) (* (neg (- i 1)) (lst i))) (lst i)))
; the minimum of the three values
(setq (neg i) (min (min (* (pos (- i 1)) (lst i)) (* (neg (- i 1)) (lst i))) (lst i)))
(setq maxprod (max maxprod (pos i)))
)
maxprod
)
)
(setq lst '(6 -3 -10 0 2))
(maxProd lst)
;-> 180
Sublist: (6 -3 -10)
(setq lst '(-1 -3 -10 0 60))
(maxProd lst)
;-> 60
Sublist: (60)
(setq lst '(-2 -3 0 -2 -40))
(maxProd lst)
;-> 80
Sublist: (-2 -40)
(setq lst '(-1 -2 -3))
(maxProd lst)
;-> 6
(setq lst '(0 -1))
(maxProd lst)
;-> 0
(setq lst '(0 0 0 0))
(maxProd lst)
;-> 0
(define (take n lst) (slice lst 0 n))
(define (drop n lst) (slice lst n))
(define (group-by-num n lst)
(if (null? lst) '()
(cons (take n lst) (group-by-num n (drop n lst)))
)
)
(setq lst '(0 1 2 3 4 5 6 7 8 9))
(group-by-num 2 lst)
;-> ((0 1) (2 3) (4 5) (6 7) (8 9))
(group-by-num 3 lst)
;-> ((0 1 2) (3 4 5) (6 7 8) (9))
(setq lst '(1 2 3 4 5 6 7 8 9 10 11 12))
(group-by-num 2 (group-by-num 2 lst))
;-> (((1 2) (3 4)) ((5 6) (7 8)) ((9 10) (11 12)))
(define (nesting lst)
(cond ((null? lst) 0)
((atom? lst) 0)
(true (max (+ 1 (nesting (first lst)))
(nesting (rest lst))))
)
)
(nesting '(a (((b c (d)))) (e) ((f)) g))
;-> 5