; Author: Yoonsuck Choe ; ; Given a pair of numbers, generate a sequence of pairs ; where the sum of the numbers in the pairs monotonically ; increases ; ; The pair should begin from '(0 1). (defun gen-next (pair) (let* ((i (1+ (first pair))) (j (1+ (second pair))) (sum (+ i j))) (if (= i (1- sum)) (list 0 (1- sum)) (list i (- j 2))))) ; Test routines (setq pair '(0 1)) (setq pair (gen-next pair)) (setq pair (gen-next pair)) (setq pair (gen-next pair)) ; see how the pair evolves (the sum will monotonically increase) ; Test routines ; 1. Set up your array (setq test-array '(1 2 2 2 3 3 4 5 5 5 7 7 9 9 10)) (setq pair '(0 1)) ; 2. Calculate the sum of the given pairs in list test-array. (+ (nth (+ (first pair) 1) test-array) (nth (+ (second pair) 1) test-array) ) ; 3. Generate the next pair, and repeat (setq pair (gen-next pair)) (+ (nth (+ (first pair) 1) test-array) (nth (+ (second pair) 1) test-array) )