Programming challenge: wildcard exclusion in cartesian products

joswig at corporate-world.lisp.de joswig at corporate-world.lisp.de
Mon Mar 20 15:25:22 EST 2006


> I had a crack at it in Lisp. My version doesn't work - but of greater
> concern to me is that it doesn't appear nearly as compact as the C
> version. Anyway, here's my Lisp code (no prizes for guessing that I'm a
> noob to Lisp):

Lot's of things you can write more compact.
But compact is not always the best way to
write source. For me the most important
criteria is that I can return to some source
after, say, a year absence and everything
is clear and readable again.

>
> (defconstant delta 2654435769 ) ; delta= 0x9E3779B9

(defconstant +delta+ #x9E3779B9)

> (defun floorn (n) (nth-value 0 (floor n)))

is above used?

> (defun >> (val num-bytes)
>    "Right-shift positive integer val by num-bytes"
>    (let* (t1 t2)
>      (setf t1 (expt 2 num-bytes))
>      (setf t2 (/ val t1))
>      (floor t2)))

(defun >> (val num-bytes)
  "Right-shift positive integer val by num-bytes"
  (floor (/ val (expt 2 num-bytes))))

> (defun transform (v1 v2 v3 v4)
>    (let (t1 t2 t3)
>      (setf t1 (<<4 v1))
>      (setf t2 (expt v2 v1))
>      (setf t3 (expt v3 (>> v2 5)))
>      (+ t1 t2 t3 v4)))
>

(defun transform (v1 v2 v3 v4)
  (+ (<<4 v1)
     (expt v2 v1)
     (expt v3 (>> v2 5))
     v4))

and so on...




More information about the Python-list mailing list