Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

A Fortran compiler is the hobgoblin of little minis.


devel / comp.lang.lisp / take a sequence of numbers 2 at a time, print numbers and

SubjectAuthor
o take a sequence of numbers 2 at a time, print numbers andRobert L.

1
take a sequence of numbers 2 at a time, print numbers and

<sufsgo$1iv$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16841&group=comp.lang.lisp#16841

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!lGyb73wigMD32okL3FqcYA.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: take a sequence of numbers 2 at a time, print numbers and
Date: Tue, 15 Feb 2022 09:41:46 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sufsgo$1iv$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="1631"; posting-host="lGyb73wigMD32okL3FqcYA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Tue, 15 Feb 2022 09:41 UTC

Rainer Joswig wrote:

> > How would you take a sequence of numbers in groups of 2 and print out
> > the numbers and their product?
> >
> > Here is my solution, but I'm sure some li5p h4x0r has a much more 1337
> > solution :)
> >
> > (setf nums (vector 21 47
> > 23 43
> > 24 29
> > 22 28
> > 22 53
> > 31 36
> > 22 56
> > 31 72))
>
> Remember that variables are introduced with DEFPARAMETER (or DEFVAR)
> and not with SETF.
>
> Also remember that all top-level variables should be by convention
> written like this: *nums*
>
> >
> > (loop for i from 0 below (car (array-dimensions nums)) by 2
> > do (progn
> > (let ((a (aref nums i))
> > (b (aref nums (1+ i))))
> > (format t "~A * ~A = ~A~%" a b (* a b)))))
>
> ARRAY-DIMENSION is not the best operation for a vector in
> general, since the vector could be one with a fill-pointer.
> LENGTH will give you the real used length of a vector.
>
> This solution is basically the same as yours but a bit
> differently written:
>
> (loop with size = (length *nums*)
> for i from 0 below size by 2
> for j from 1 below size by 2
> for a = (aref *nums* i) and b = (aref *nums* j)
> do (format t "~A * ~A = ~A~%" a b (* a b)))

(use srfi-43) ;; vector->list for Gauche
or
(require srfi/43) ;; vector->list for Racket

(require srfi/48) ;; format for Racket

(define nums
(vector 21 47
23 43
24 29
22 28
22 53
31 36
22 56
31 72))

(do ((i 0 (+ i 2)))
((= i (vector-length nums)))
(let ((both (vector->list nums i (+ i 2))))
(apply format #t "~a * ~a = ~a~%" `(,@both ,(apply * both)))))

21 * 47 = 987
23 * 43 = 989
24 * 29 = 696
22 * 28 = 616
22 * 53 = 1166
31 * 36 = 1116
22 * 56 = 1232
31 * 72 = 2232


devel / comp.lang.lisp / take a sequence of numbers 2 at a time, print numbers and

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor