@Anonymous wrote:
Hello.
Can variable is getting lists individually in the loop that is "while" and "repeat" function?.
For example, If repeat function set 64, The variable that is (1 2) is getting list that is ((1 2) (2 3)) when the loop secondly repeat.
Therefore, 54s repeating variable list will be ((1 2) (2 3) (3 4) (4 5)................(53 54)).
I always thanks !.
Here is one that gives a result in which the second number of the last pair is the number you give it as an argument:
(defun listpairs (n)
(repeat (1- n)
(setq pairslist (cons (reverse (list n (setq n (1- n)))) pairslist))
)
)
USAGE:
(listpairs 13)
returns
((1 2) (2 3) (3 4) (4 5) (5 6) (6 7) (7 8) (8 9) (9 10) (10 11) (11 12) (12 13))
and saves that into the 'pairslist' variable.
HOWEVER, that may not be what you really want. It makes a list ending with the number given as the second number in the last pair, but that's only [in this case] 12 sublists, not 13. In the beginning of your description, the number of repeats is the first number in the last pair [on the 2nd repeat, the last pair starts with a 2 -- it doesn't end with a 2], so that with 54 repeats, the last pair should be (54 55) rather than (53 54). If that's really what you want, this will do it:
(defun listpairs (n)
(repeat n
(setq pairslist (cons (reverse (list (1+ n) (1+ (setq n (1- n))))) pairslist))
)
)
with which:
(listpairs 10)
returns
((1 2) (2 3) (3 4) (4 5) (5 6) (6 7) (7 8) (8 9) (9 10) (10 11))
[It could be a little shorter with the introduction of an additional variable, but I decided to try it without any variables, using only than the 'n' argument.]
Set the 'pairslist' variable to nil before every try, so that it doesn't keep adding more to previous lists, and if needed, build that in or make it a localized variable.
Kent Cooper, AIA