-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path062.scm
executable file
·45 lines (31 loc) · 991 Bytes
/
062.scm
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
(define (num->list num)
(if (< num 10)
(list num)
(append (num->list (floor (/ num 10)))
(list (- num (* 10 (floor (/ num 10))))))))
(define (list->num list)
(if (null? list)
0
(+ (car list) (* 10 (list->num (cdr list))))))
(define (create-basic-permutation n)
(list->num (sort (num->list n) <)))
(define (update l)
(cons (+ 1 (car l))))
(define ht (make-hash-table))
(define (magic cube)
(let ((basic-permutation (create-basic-permutation cube)))
(if (hash-table-exists? ht basic-permutation)
(let ((element (hash-table-ref ht basic-permutation)))
(if (< (car element) 4)
(hash-table-set! ht basic-permutation (cons
(+ 1 (car element))
(min cube (cdr element))))
(list (min cube (cdr element)))))
(hash-table-set! ht basic-permutation (cons 1 cube)))))
(define (cycle n)
(let ((result (magic (expt n 3))))
(if (list? result)
result
(cycle (+ 1 n)))))
(define (euler62)
(cycle 1))