-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler062.lisp
45 lines (39 loc) · 1.27 KB
/
euler062.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;;;
;;;; Project Euler - Problem 62
;;;;
(load "permutations")
(defparameter *cube-hash* (make-hash-table :test #'equal))
(defparameter *cube-list* nil)
(defparameter *limit* 5)
(defparameter *end* 10000)
(defun euler062 ()
(let ((current-length 0))
(do ((n 1 (1+ n)))
((> n *end*) 'end)
(let* ((c (cube n))
(c-list (number-to-list c))
(c-length (length c-list)))
(if (= current-length c-length)
(let ((result (compare c-list)))
(if (not (null result))
(return-from euler062 (list-to-number result))))
(progn
(reset-list)
(setf current-length c-length)))))))
(defun compare (c-list)
(dolist (c-to-compare *cube-list*)
(if (permutation? c-to-compare c-list)
(progn
(if (null (gethash c-to-compare *cube-hash*))
(setf (gethash c-to-compare *cube-hash*) 2)
(incf (gethash c-to-compare *cube-hash*)))
(if (>= (gethash c-to-compare *cube-hash*) *limit*)
(return-from compare c-to-compare)))))
(push c-list *cube-list*)
nil)
(defun reset-list ()
;(print *cube-hash*)
(setf *cube-hash* (make-hash-table :test #'equal))
(setf *cube-list* nil))
(defun cube (n)
(* n n n))