mingchuno / ABCDEFGHPPP

(AB - CD = EF) + GH = PPP problem
MIT License
47 stars 39 forks source link

I don't know how to use Github and I found a solution of Lisp-bruteforce #36

Closed xnastudio closed 8 years ago

xnastudio commented 8 years ago
(DEFUN FIND-AUX (N ANSWER) ; find the nth digi of answer
  (COND ((= N 9)(PRINT ANSWER))
        (T (FIND-SUB N 0 ANSWER))))
(DEFUN FIND-SUB (N M ANSWER) ;try to append nth digi as m to answer list
  (COND ((= M 10)'END)
        ((AND (= M 0) (EVENP N))(FIND-SUB N (+ M 1) ANSWER)) ;A C E G P <>0
        (T (COND ((MEMBER M ANSWER)) ; each digi only appears once in answer
                 ((NOT (PASS-RULE1P (APPEND ANSWER (LIST M)))))
                 ((NOT (PASS-RULE2P (APPEND ANSWER (LIST M)))))
                 (T (FIND-AUX (+ N 1) (APPEND ANSWER (LIST M)))))
           (FIND-SUB N (+ M 1) ANSWER))))
(DEFUN FIND-ANSWER () (FIND-AUX 0 NIL)) ;find answer list (A B C D E F G H P)
(DEFUN PASS-RULE1P (ANSWER) ;pass-rule1 : AB - CD = EF
  (COND ((>= (LENGTH ANSWER) 6)
         (= (- (+ (* (NTH 0 ANSWER) 10)
                  (NTH 1 ANSWER))
               (+ (* (NTH 2 ANSWER) 10)
                  (NTH 3 ANSWER)))
            (+ (* (NTH 4 ANSWER) 10)
               (NTH 5 ANSWER))))
        (T T)))
(DEFUN PASS-RULE2P (ANSWER) ;pass-rule2 : EF + GH = PPP
  (COND ((>= (LENGTH ANSWER) 9)
         (= (+ (+ (* (NTH 4 ANSWER) 10)
                  (NTH 5 ANSWER))
               (+ (* (NTH 6 ANSWER) 10)
                  (NTH 7 ANSWER)))
            (LET ((P (NTH 8 ANSWER)))
                 (+ (* P 100) (* P 10) P))))
        (T T)))

lisp-brueforce

gaplo917 commented 8 years ago

Thanks! can you repost the code with markdown "insert code" features

It will keep the indentation of the code

xnastudio commented 8 years ago

And the Scheme-bruteforce version, same as the Lisp version

(define (pass-rule1? answer) ;PASS-RULE1? AB - CD = EF
  (cond ((>= (length answer) 6)
         (= (- (+ (* (list-ref answer 0) 10)
                  (list-ref answer 1))
               (+ (* (list-ref answer 2) 10)
                  (list-ref answer 3)))
            (+ (* (list-ref answer 4) 10)
               (list-ref answer 5))))
        (else #t)))
(define (pass-rule2? answer) ;PASS-RULE2? EF + GH = PPP
  (cond ((>= (length answer) 9)
         (= (+ (+ (* (list-ref answer 4) 10)
                  (list-ref answer 5))
               (+ (* (list-ref answer 6) 10)
                  (list-ref answer 7)))
            (let ((p (list-ref answer 8)))
              (+ (* p 100) (* p 10) p))))
        (else #t)))
(define (find-aux n answer) ;FIND THE Nth DIGI OF ANSWER
  (cond ((= n 9) (display answer)(newline))
        (else (find-sub n 0 answer))))
(define (find-sub n m answer) ;TRY TO APPEND THE Nth DIGI AS M TO ANSWER 
  (cond ((= m 10)'END)
        ((and (= m 0)(even? n))(find-sub n (+ m 1) answer)) ;A,C,E,G,P <> 0
        (else (cond ((memv m answer))  ; EACH DIGI APPEARS ONLY  ONCE
                    ((not (pass-rule1? (append answer (list m)))))
                    ((not (pass-rule2? (append answer (list m)))))
                    (else (find-aux (+ n 1) (append answer (list m)))))
              (find-sub n (+ m 1) answer))))
(define (find-answer) (find-aux 0 '())) ;FIND ANSWER LIST (A B C D E F G H P)

scheme

gaplo917 commented 8 years ago

Great, would you like to share where to find your solutions?

I will quote it on the top of the files to credit the creator

dng8888 commented 8 years ago

The lisp version need a bit shuffle around to avoid looking-ahead (similar to the one under the scheme version i.e. pass-rule1p and pass-rule2p is defined first). At least my Clozure CL needed that. The result conform. Hence, it is is a minor issue.

I cannot compile the scheme version under Racket (using scheme language) especially these 2 lines:

(cond ((= n 9) (display answer)(newline))

    (else (cond ((memv m answer))  ; EACH DIGI APPEARS ONLY  ONCE

May be Racket issue. not sure.

xnastudio commented 8 years ago

Please add the following code to first line of Dr.racket . display newline and memv are functions of Scheme. If stil can't run, change display to the right print function and delete newline, and you can change memv to member .

#lang scheme

xnastudio commented 8 years ago

change some codes in pass-rule to make it easy to read.

#lang scheme
(define (pass-rule1? answer) ;PASS-RULE1? AB - CD = EF
  (cond ((>= (length answer) 6)
         (let ((a (list-ref answer 0))
               (b (list-ref answer 1))
               (c (list-ref answer 2))
               (d (list-ref answer 3))
               (e (list-ref answer 4))
               (f (list-ref answer 5)))
           (= (- (+ (* a 10) b) (+ (* c 10) d)) (+ (* e 10) f))))
        (else #t)))
(define (pass-rule2? answer) ;PASS-RULE2? EF + GH = PPP
  (cond ((>= (length answer) 9)
         (let ((e (list-ref answer 4))
               (f (list-ref answer 5))
               (g (list-ref answer 6))
               (h (list-ref answer 7))
               (p (list-ref answer 8)))
           (= (+ (+ (* e 10) f) (+ (* g 10) h)) (* 111 p)))) ;100p + 10p + p = 111p
        (else #t)))
(define (find-aux n answer) ;FIND THE Nth DIGI OF ANSWER
  (cond ((= n 9) (display answer)(newline))
        (else (find-sub n 0 answer))))
(define (find-sub n m answer) ;TRY TO APPEND THE Nth DIGI AS M TO ANSWER 
  (cond ((= m 10) 'END)
        ((and (= m 0)(even? n))(find-sub n (+ m 1) answer)) ;A,C,E,G,P <> 0
        (else (cond ((memv m answer))  ; EACH DIGI APPEARS ONLY  ONCE
                    ((not (pass-rule1? (append answer (list m)))))
                    ((not (pass-rule2? (append answer (list m)))))
                    (else (find-aux (+ n 1) (append answer (list m)))))
              (find-sub n (+ m 1) answer))))
(define (find-answer) (find-aux 0 '())) ;FIND ANSWER LIST (A B C D E F G H P)
xnastudio commented 8 years ago

core codes reduce to 9 lines. use (find 0 0 '()) to get the answer.

#lang scheme
(define (pass-rule1? answer) ;answer pass-rule1? AB - CD = EF
  (cond ((< (length answer) 6) #t)
        (else (let ((a (list-ref answer 0))
                    (b (list-ref answer 1))
                    (c (list-ref answer 2))
                    (d (list-ref answer 3))
                    (e (list-ref answer 4))
                    (f (list-ref answer 5)))
                (= (- (+ (* a 10) b) (+ (* c 10) d)) (+ (* e 10) f)))))) 
(define (pass-rule2? answer) ;answer pass-rule2? EF + GH = PPP ( 100P + 10P + P = 111P)
  (cond ((< (length answer) 9) #t)
        (else (let ((e (list-ref answer 4))
                    (f (list-ref answer 5))
                    (g (list-ref answer 6))
                    (h (list-ref answer 7))
                    (p (list-ref answer 8)))
                (= (+ (+ (* e 10) f) (+ (* g 10) h)) (* 111 p))))))
(define (find n m answer) ;find answer list (A B C D E F G H P)
  (cond ((= n 9)(display answer)(newline)) 
        ((= m 10))
        ((and (= m 0) (even? n)) (find n 1 answer)) ;A,C,E,G,P != 0
        (else (cond ((memv m answer)) ;each digi appears onlly once
                    ((not (pass-rule1? (append answer (list m)))))
                    ((not (pass-rule2? (append answer (list m)))))
                    (else (find (+ n 1) 0 (append answer (list m)))))
              (find n (+ m 1) answer))))

ppp

dng8888 commented 8 years ago

Thanks.

The lisp code under clozure cl need re-order to avoid compiler warning but it is fine.

May I suggest add your execute function as well i.e.

(time (find-answer))

I would also suggest to one more line on the bottom of .scm to ease the test:

(time (find 0 0 '()))

Sorry but I am just a pedestrian here. The guy in charge is asking a question for your answer:

"Great, would you like to share where to find your solutions?

I will quote it on the top of the files to credit the creator"

May I suggest you answer him. Cheers!

gaplo917 commented 8 years ago

@xnastudio the scheme version is created by yourself , right ?

Please provide a output.txt for us. I will merge it to master

xnastudio commented 8 years ago

Stupid brute-force recursion method , take about 145S to solve Base 34 AB - CD = EF, EF - GH = PPP (Width = 2) with config: Windows 10 , Intel Core i3-4000M CPU @ 2.40GHz 4.G RAM LISP SBCL 1.3.3

(T-SEARCH) to run , (length all) to find solution's size , (all) to display all the solution

(SETQ BASE 34)
(SETQ PPP (+ (* BASE BASE) BASE 1))
(DEFUN PASS-RULE1? (ANSWER)
  (COND ((< (LENGTH ANSWER) 6) T)
        (T (LET ((A (NTH 0 ANSWER))
                 (B (NTH 1 ANSWER))
                 (C (NTH 2 ANSWER))
                 (D (NTH 3 ANSWER))
                 (E (NTH 4 ANSWER))
                 (F (NTH 5 ANSWER)))
                (= (- (+ (* A BASE) B) (+ (* C BASE) D)) (+ (* E BASE) F))))))
(DEFUN PASS-RULE2? (ANSWER)
  (COND ((< (LENGTH ANSWER) 8) T)
        (T (LET ((E (NTH 4 ANSWER))
                 (F (NTH 5 ANSWER))
                 (G (NTH 6 ANSWER))
                 (H (NTH 7 ANSWER)))
        (= (+ (+ (* E BASE) F) (+ (* G BASE) H))
           PPP)))))
(DEFUN R-SEARCH (ANSWER N M)
  (COND ((= N 8)(SETQ ALL (CONS ANSWER ALL)))
    ((= M BASE))
    ((= M 1) (R-SEARCH ANSWER N 2))
    ((AND (= M 0)(EVENP N))(R-SEARCH ANSWER N 2))
    (T (COND ((MEMBER M ANSWER))
         ((NOT (PASS-RULE1? (APPEND ANSWER (LIST M)))))
         ((NOT (PASS-RULE2? (APPEND ANSWER (LIST M)))))
         (T (R-SEARCH (APPEND ANSWER (LIST M)) (+ N 1) 0)))
       (R-SEARCH ANSWER N (+ M 1)))))
(DEFUN T-SEARCH () (SETQ ALL NIL) (TIME (R-SEARCH NIL 0 0)))

adv

jackhftang commented 8 years ago

You can press the top right button to fork this repo, and then download and install github client https://desktop.github.com/ add the forked repo. And then submit pull request. This process is easy and useful.

gaplo917 commented 8 years ago

Not bad. some of the pure brute force not able to complete the result within 10 minutes XD

Best Regards, Gary

On 28 Mar 2016, at 21:19, xnastudio notifications@github.com wrote:

Stupid brute-force recursion method , take about 145S to solve Base 34 AB - CD = EF, EF - GH = PPP (Width = 2) with config: Windows 10 , Intel Core i3-4000M CPU @ 2.40GHz 4.G RAM LISP SBCL 1.3.3

(T-SEARCH) to run , (length all) to find solution's size , (all) to display all the solution

(SETQ BASE 34) (SETQ PPP (+ (* BASE BASE) BASE 1)) (SETQ ALL NIL) (DEFUN PASS-RULE1? (ANSWER) (COND ((< (LENGTH ANSWER) 6) T) (T (LET ((A (NTH 0 ANSWER)) (B (NTH 1 ANSWER)) (C (NTH 2 ANSWER)) (D (NTH 3 ANSWER)) (E (NTH 4 ANSWER)) (F (NTH 5 ANSWER))) (= (- (+ (* A BASE) B) (+ (* C BASE) D)) (+ (* E BASE) F)))))) (DEFUN PASS-RULE2? (ANSWER) (COND ((< (LENGTH ANSWER) 8) T) (T (LET ((E (NTH 4 ANSWER)) (F (NTH 5 ANSWER)) (G (NTH 6 ANSWER)) (H (NTH 7 ANSWER))) (= (+ (+ (* E BASE) F) (+ (* G BASE) H)) PPP))))) (DEFUN R-SEARCH (ANSWER N M) (COND ((= N 8)(SETQ ALL (CONS ANSWER ALL))) ((= M BASE)) ((= M 1) (R-SEARCH ANSWER N 2)) ((AND (= M 0)(EVENP N))(R-SEARCH ANSWER N 2)) (T (COND ((MEMBER M ANSWER)) ((NOT (PASS-RULE1? (APPEND ANSWER (LIST M))))) ((NOT (PASS-RULE2? (APPEND ANSWER (LIST M))))) (T (R-SEARCH (APPEND ANSWER (LIST M)) (+ N 1) 0))) (R-SEARCH ANSWER N (+ M 1))))) (DEFUN T-SEARCH () (TIME (R-SEARCH NIL 0 0)))

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

xnastudio commented 8 years ago

Today I reduct 100s to solve Base 34 AB - CD = EF, EF - GH = PPP (Width = 2) Still a slow brute-force recursion method. Minor change to pass-rule? and change append to cons.(speed up 100s). So (CONS M ANSWER) is faster than (APPEND ANSWER (LIST M)) .

N = 0 ,try to insert H to make answer (H) N = 1, try to insert G to make answer (G H) N = 2, try to insert F to make answer (F G H) N = 3 ,try to insert E to make answer (E F G H) you need to check E F + GH = PPP (at that time E 's try value is M , answer = (F G H) ) ....................

(DEFUN PASS-RULE1? (ANSWER N M)
  (IF (= N 7)
      (LET ((B (NTH 0 ANSWER))
        (C (NTH 1 ANSWER))
        (D (NTH 2 ANSWER))
        (E (NTH 3 ANSWER))
        (F (NTH 4 ANSWER)))
       (= (- (+ (* M BASE) B) (+ (* C BASE) D)) (+ (* E BASE) F)))
      T))
(DEFUN PASS-RULE2? (ANSWER N M)
  (IF (= N 3)
      (LET ((F (NTH 0 ANSWER))
        (G (NTH 1 ANSWER))
        (H (NTH 2 ANSWER)))
       (= (+ (+ (* M BASE) F) (+ (* G BASE) H)) PPP))
      T))
(DEFUN R-SEARCH (ANSWER N M)
  (COND ((= N 8)(SETQ ALL (CONS ANSWER ALL)))
    ((= M BASE))
    ((AND (= M 0) (ODDP N)) (R-SEARCH ANSWER N 2))
    ((= M 1) (R-SEARCH ANSWER N 2))
    (T (COND ((MEMBER M ANSWER))
         ((NOT (PASS-RULE1? ANSWER N M)))
         ((NOT (PASS-RULE2? ANSWER N M)))
         (T (R-SEARCH (CONS M ANSWER) (+ N 1) 0)))
       (R-SEARCH ANSWER N (+ M 1)))))
(DEFUN T-SEARCH ()
  (SETQ BASE (READ))
  (SETQ PPP (+ (* BASE BASE) BASE 1))
  (SETQ ALL NIL)
  (TIME (R-SEARCH NIL 0 0)))

new

dng8888 commented 8 years ago

not sure about the last 2 lisp version

I cannot run the last two version of lisp. As said below, the lisp file would be better not working on interactive mode (to avoid it take earlier info) but instead it should be executable under say

sbcl --script xxxx.lisp

It would avoid any left behind in the lisp environment by earlier execution which is hidden.

for the lisp and scheme update

For the lisp and scheme, may be I should sit and wait for this to evolve. But given the older version can work and if no more waiting as I really think we should have the lisp and scheme version up first, I tried 3 things for your guys to consider:

1. Wait for xnastudio to use the GIT Desktop

But may I still suggest xnastudio to consider my suggestions especially added a fully functional one e.g. add the (find-answer) and (time (find 0 0 '())). You may check my sbcl --script command as it would ensure your source is completed.

(I noted the latest version, function order has been changed, btw).

2. use the old version first

Use the older versions and my amended .lisp/.scheme plus the output and a little readme.md to create one version for xnastudio to update.

Other than I was forced to use .txt, I upload the 3 files for lisp (.lisp for the source, .output.txt for the output and readme.md for the explanation). Similarly for the scheme.

I think that the order of the functions should be amended on the lisp file, but I have not done that. Still, I need to add one more line to it as that is needed for batch mode under sbcl (and also avoid the warning message under the interactive closure cl).

I can do it first on behave of xnastudio or better ... gaplo

3. (Optional) Try my little cheatsheet

I have a cheatsheet for git and I tried to update it for xnastudio.

As Mr. Tang said that it is usually easier to use Git desktop, try that first. If not, see whether my cheatsheet is useful. It may not be as it is only useful for myself. Good luck in using it.

Finally

Hope I am not stepping on anyone's toe. Cheers!

=== lisp ====

lisp-2016-03-27.lisp.readme.md.txt

lisp-2016-03-27.lisp.txt

lisp-2016-03-27.lisp.output.txt

=== scheme ====

scheme-2016-03-27.scm.readme.md.txt

scheme-2016-03-27.scm.txt

scheme-2016-03-27.scm.output.txt

==== git pull request cheatsheet ====

github-pull-request-cheatsheet.md.txt

xnastudio commented 8 years ago

I check the code with clozure CL,it is ok. The the speed is Sbcl >. Clozure > clisp

how to run the lisp code:

  1. Save the code for example to c:/code/search.lisp
  2. Enter lisp interpreter, for example, clisp,clozure,sbcl
  3. Use function: (load "c:/code/search.lisp")
  4. Then. (T-SEARCH) 5.input base number: 10 And press enter If you input 34 will take 40s to search the solution 6.then. (length all) To get the size of solution
  5. Input. all Will print out all the solution
  6. To print for example the 4th answer (nth 3 all)
  7. Input (T-SEARCH) again,the you can input another base number, for example input 16 and press enter
xnastudio commented 8 years ago

Sorry guys just too busy to learn to use GitHub. I just don't understand that: fork me ,pull GitHub jargon.

dng8888 commented 8 years ago

In short can I publish for you with no license issue (or under open source license).

The current status of your code, my modification to your code and my own lisp-9-loop code

I found it hard to learn github as well, hence the cheatsheet. In fact in the future if Gary asked to do something about HEAD and re-something as he is asking others, I would raise my hand up.

Still, I took the effort as the github is a joint effort to solve something. It assumes you get it out, other changes it and evolve the solution. It is a habitat for joint effort to do things, even funny things like solving a primary one homework.

In that case if you really do not bother, do you mind me to publish your solution for you, assume it is open source and no license issues to bother future collaborator like me.

Well, why need collaboration? Because I really have some minor need to work on your code as I still cannot run yours. Also, the advance rule require to print first 50 solution (and your all list is so many more and cannot be printed).

Hence, I take some liability to make some cosmetic changes, make the program run and do the first50 printing. (In fact, if you have time to explain it, I would be interest to evolve it or wait for you to evolve it into abcd-efgh=ijkl+mnop=qqqqq version.)

Sorry I need to show some humour on comparing my to-be-published lisp-9-loop. I think 小無相功 (the one which a monk tried to cheat the Shanglin that they should burn their books) cannot really compare with 72 Shangling extreme technique. You cannot keep on copy fortran brutal force and migrate to cobol then lisp. Well, still to show off my 小無相功 and for fun, please see my horrible lisp-9-lisp version.

(Due to obvious reason, they do not allow publish code but only .txt file.)

==== error message to be debug under sbcl ====

lisp-2016-03-29-sbcl-err-message.lisp.txt

lisp-2016-03-29-sbcl-err-message.output-2.txt

==== modify version with first50 printed ====

abcdefghppp-03-29-print.lisp.txt

abcdefghppp-03-29-print.lisp.output.txt

abcdefghppp-03-29-print.lisp.readme.md.txt

==== the horrible lisp-9-loop (from fortran to cobol to lisp, what do you expect) ====

abcdefghppp-dolist-p=1.lisp.txt

abcdefghppp-dolist-p=1.lisp.up to 22.output.txt

abcdefghppp-dolist-p=1.lisp.readme.md.txt

xnastudio commented 8 years ago

No copy right of the code. Just copy and use. It is free. I can't make the search run fast with lisp anymore.I think the reason is that Lisp is for symbolic manipulation not for calculation. I will try to use another language to test the algorithm.

1 2 3

xnastudio commented 8 years ago

Nothing new here. Just post the lisp code that can generate output.txt Now you can : sbcl --script search.lisp > output.txt

(DECLAIM (OPTIMIZE (SPEED 3)
           (COMPILATION-SPEED 0)
           (SAFETY 0)
           (DEBUG 0)))
(DEFVAR BASE 10)
(DEFVAR PPP 111)
(DEFVAR ALL NIL)
(DEFUN PASS-RULE1? (ANSWER N M)
  (IF (= N 7)
      (LET ((B (NTH 0 ANSWER))
        (C (NTH 1 ANSWER))
        (D (NTH 2 ANSWER))
        (E (NTH 3 ANSWER))
        (F (NTH 4 ANSWER)))
       (= (- (+ (* M BASE) B) (+ (* C BASE) D)) (+ (* E BASE) F)))
      T))
(DEFUN PASS-RULE2? (ANSWER N M)
  (IF (= N 3)
      (LET ((F (NTH 0 ANSWER))
        (G (NTH 1 ANSWER))
        (H (NTH 2 ANSWER)))
       (= (+ (+ (* M BASE) F) (+ (* G BASE) H)) PPP))
      T))
(DEFUN R-SEARCH (ANSWER N M)
  (COND ((= N 8)(SETF ALL (CONS ANSWER ALL)))
    ((= M BASE))
    ((AND (= M 0) (ODDP N)) (R-SEARCH ANSWER N 2))
    ((= M 1) (R-SEARCH ANSWER N 2))
    (T (COND ((MEMBER M ANSWER))
         ((NOT (PASS-RULE1? ANSWER N M)))
         ((NOT (PASS-RULE2? ANSWER N M)))
         (T (R-SEARCH (CONS M ANSWER) (+ N 1) 0)))
       (R-SEARCH ANSWER N (+ M 1)))))
(DEFUN I-SEARCH ()
  (SETF BASE (READ))
  (SETF PPP (+ (* BASE BASE) BASE 1))
  (SETF ALL NIL)
  (TIME (R-SEARCH NIL 0 0)))
(DEFUN BASE-N (X)
  (SETF BASE X)
  (SETF PPP (+ (* X X) X 1))
  (SETF ALL NIL)
  (TIME (R-SEARCH NIL 0 0))
  (FORMAT T "BASE:~A ANSWER:~A~%~%~%" BASE (LENGTH ALL)) 
  (DO ((N 1 (+ N 1)))
      ((> N 50))
      (FORMAT T "~A~%" (NTH (RANDOM (LENGTH ALL)) ALL)))
  (PRINT '++++++++++++++++++++++++++++++++++++++++++++++++++))
(BASE-N 16)
(BASE-N 28)
(BASE-N 34)

Evaluation took: 0.093 seconds of real time 0.093750 seconds of total run time (0.093750 user, 0.000000 system) 101.08% CPU 222,074,124 processor cycles 2,031,616 bytes consed

BASE:16 ANSWER:1794

(10 6 4 14 5 8 11 9) (14 11 4 12 9 15 7 2) (9 15 4 8 5 7 11 10) (6 9 3 13 2 12 14 5) (11 14 8 12 3 2 13 15) (14 5 10 12 3 9 13 8) (11 10 9 6 2 4 14 13) (14 9 8 7 6 2 10 15) (10 13 5 15 4 14 12 3) (7 13 2 10 5 3 11 14) (12 15 3 4 9 11 7 6) (10 0 6 4 3 12 13 5) (8 11 5 9 3 2 13 15) (15 3 9 12 5 7 11 10) (14 3 7 4 6 15 10 2) (14 15 3 8 11 7 5 10) (7 10 4 15 2 11 14 6) (13 5 3 10 9 11 7 6) (7 3 4 8 2 11 14 6) (12 3 6 15 5 4 11 13) (7 5 4 10 2 11 14 6) (12 2 6 4 5 14 11 3) (14 0 2 7 11 9 5 8) (7 14 3 8 4 6 12 11) (9 11 2 13 6 14 10 3) (13 9 7 4 6 5 10 12) (13 10 3 14 9 12 7 5) (8 3 5 9 2 10 14 7) (15 0 5 12 9 4 7 13) (8 4 5 9 2 11 14 6) (9 14 6 12 3 2 13 15) (10 3 2 15 7 4 9 13) (10 4 7 9 2 11 14 6) (13 15 11 6 2 9 14 8) (14 0 3 12 10 4 6 13) (10 15 8 4 2 11 14 6) (15 8 2 10 12 14 4 3) (15 11 5 3 10 8 6 9) (7 11 4 6 3 5 13 12) (12 0 8 6 3 10 13 7) (10 11 2 13 7 14 9 3) (11 9 8 15 2 10 14 7) (12 11 5 13 6 14 10 3) (12 8 9 2 3 6 13 11) (10 14 7 9 3 5 13 12) (13 8 7 9 5 15 11 2) (10 12 2 15 7 13 9 4) (13 11 6 8 7 3 9 14) (15 3 8 7 6 12 10 5) (11 10 7 8 4 2 12 15)

++++++++++++++++++++++++++++++++++++++++++++++++++ Evaluation took: 8.537 seconds of real time 8.468750 seconds of total run time (8.453125 user, 0.015625 system) 99.20% CPU 20,439,280,922 processor cycles 92,798,976 bytes consed

BASE:28 ANSWER:73812

(24 3 10 20 13 11 15 18) (26 21 17 27 8 22 20 7) (25 8 4 3 21 5 7 24) (17 22 13 8 4 14 24 15) (13 22 5 16 8 6 20 23) (15 14 6 3 9 11 19 18) (26 3 15 22 10 9 18 20) (21 9 3 5 18 4 10 25) (14 27 2 20 12 7 16 22) (25 14 16 6 9 8 19 21) (20 9 3 10 16 27 12 2) (9 13 5 10 4 3 24 26) (12 2 6 11 5 19 23 10) (25 5 6 26 18 7 10 22) (24 5 8 11 15 22 13 7) (22 10 2 25 19 13 9 16) (27 11 8 5 19 6 9 23) (22 18 7 12 15 6 13 23) (18 24 15 2 3 22 25 7) (18 10 5 23 12 15 16 14) (27 26 15 7 12 19 16 10) (13 18 4 27 8 19 20 10) (18 19 9 24 8 23 20 6) (14 23 10 11 4 12 24 17) (27 21 3 12 24 9 4 20) (21 7 4 11 16 24 12 5) (10 14 6 24 3 18 25 11) (17 11 9 26 7 13 21 16) (25 21 16 4 9 17 19 12) (11 15 7 20 3 23 25 6) (15 6 11 18 3 16 25 13) (9 14 3 26 5 16 23 13) (26 11 6 25 19 14 9 15) (23 18 2 27 20 19 8 10) (24 15 17 11 7 4 21 25) (26 12 19 25 6 15 22 14) (26 23 8 3 18 20 10 9) (21 6 3 9 17 25 11 4) (20 0 17 12 2 16 26 13) (16 9 12 26 3 11 25 18) (26 23 16 6 10 17 18 12) (19 20 9 3 10 17 18 12) (27 21 17 8 10 13 18 16) (18 9 14 2 4 7 24 22) (13 10 4 24 8 14 20 15) (23 9 11 5 12 4 16 25) (13 21 10 12 3 9 25 20) (25 15 18 3 7 12 21 17) (14 18 5 24 8 22 20 7) (25 7 13 15 11 20 17 9)

++++++++++++++++++++++++++++++++++++++++++++++++++ Evaluation took: 35.526 seconds of real time 35.250000 seconds of total run time (35.187500 user, 0.062500 system) [ Run times consist of 0.110 seconds GC time, and 35.140 seconds non-GC time. ] 99.22% CPU 85,067,662,722 processor cycles 302,806,656 bytes consed

BASE:34 ANSWER:214033

(24 17 18 14 6 3 28 32) (25 15 14 13 11 2 23 33) (25 32 2 4 23 28 11 7) (28 29 26 15 2 14 32 21) (29 2 25 28 3 8 31 27) (23 20 17 9 6 11 28 24) (20 28 18 9 2 19 32 16) (7 15 5 11 2 4 32 31) (24 4 9 28 14 10 20 25) (27 26 24 19 3 7 31 28) (13 9 8 31 4 12 30 23) (26 15 14 13 12 2 22 33) (17 28 9 15 8 13 26 22) (25 29 10 32 14 31 20 4) (23 0 15 32 7 2 27 33) (21 5 6 27 14 12 20 23) (18 28 4 9 14 19 20 16) (29 30 26 14 3 16 31 19) (30 25 10 3 20 22 14 13) (30 16 8 26 21 24 13 11) (16 5 3 19 12 20 22 15) (10 29 2 16 8 13 26 22) (33 29 18 16 15 13 19 22) (33 21 26 6 7 15 27 20) (24 20 19 26 4 28 30 7) (29 10 15 2 14 8 20 27) (25 15 14 2 11 13 23 22) (12 9 8 14 3 29 31 6) (19 14 16 5 3 9 31 26) (29 14 20 6 9 8 25 27) (29 25 17 27 11 32 23 3) (22 26 7 21 15 5 19 30) (18 19 4 30 13 23 21 12) (31 4 16 28 14 10 20 25) (23 19 18 10 5 9 29 26) (22 0 12 15 9 19 25 16) (10 29 3 30 6 33 28 2) (31 28 24 5 7 23 27 12) (31 32 17 5 14 27 20 8) (22 7 3 17 18 24 16 11) (26 27 2 12 24 15 10 20) (16 15 9 13 7 2 27 33) (31 8 7 26 23 16 11 19) (29 22 23 8 6 14 28 21) (19 0 6 9 12 25 22 10) (19 20 3 12 16 8 18 27) (17 3 12 16 4 21 30 14) (29 13 17 28 11 19 23 16) (11 15 7 13 4 2 30 33) (15 20 7 2 8 18 26 17)

++++++++++++++++++++++++++++++++++++++++++++++++++

dng8888 commented 8 years ago

I would do the pull request tonight for both my silly 9-loop and yours fixing a minor bug - the print part does not handle <50 solution as required by the non-Advance version. Should be (< (min ( 50 (length all)))).

For optimisation for yours, I suspect the next stage usually for lisp is move to fixed data type array e.g. the answer list and not using cons may help. But given it is under a recursive style, it is a challenge.

For mine, I guess I can learn from your algorithm first by looking into eliminating some the loop earlier, like what you have done in your test path.

But program is like water, you cannot dip into it twice. It is ever-changing. Hence, I would do one version first and let the world evolve.

See you around.

dng8888 commented 8 years ago

Submitted the lisp codes and once that is ok, I would submit the scheme version. I am less interest in scheme and hence other than adding the running command (time (find 0 0 '())) it is the same as yours (and what I have uploaded earlier). But to avoid those rebase etc., I wait for lisp to clear first.

dng8888 commented 8 years ago

Done and thanks all.