Share Pastebin
Guest
Public paste!

free-zombie

By: a guest | Oct 27th, 2008 | Syntax: Lisp | Size: 0.55 KB | Hits: 64 | Expires: Never
Copy text to clipboard
  1. (defun with-unique-digits (to)
  2.   (let ((ndigits (ceiling (log to 10))))
  3.     (find-uniques to () ndigits 0)
  4.     ))
  5.  
  6.  
  7. (defun find-uniques (max forbidden ndigits add)
  8.   (cond
  9.     ((> add max) ())
  10.     ((= ndigits 0) (list add))
  11.     (t (append
  12.         (if (member 0 forbidden) ()
  13.             (find-uniques max (and forbidden (cons 0 forbidden)) (1- ndigits) add))
  14.         (loop for i from 1 to 9
  15.          append (if (member i forbidden) ()
  16.                  (find-uniques max (cons i forbidden) (1- ndigits)
  17.                                (+ add (* i (expt 10 (1- ndigits))))))
  18.              )
  19.          ))
  20.     ))