Last active
March 25, 2016 11:11
-
-
Save zerg000000/b446ac9459f6347222c9 to your computer and use it in GitHub Desktop.
考起碩士生的小一數學題(ppp)解法 - 香港高登 http://m2.hkgolden.com/view.aspx?message=6307521&type=SW&page=1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.core.logic) | |
(require '[clojure.core.logic.fd :as fd]) | |
(def result | |
(run* [q] | |
(fresh [a b c d e f g h p ab cd ef gh ppp] | |
(fd/in a b c d e f g h p (fd/interval 1 9)) ; why not zero? | |
(fd/in ab cd ef gh (fd/interval 10 99)) | |
(fd/in ppp (fd/interval 100 999)) | |
(fd/eq | |
(= ab (+ (* a 10) b)) | |
(= cd (+ (* c 10) d)) | |
(= ef (+ (* e 10) f)) | |
(= gh (+ (* g 10) h)) | |
(= ppp (+ (* p 100) (* p 10) p)) | |
(= ppp (+ gh ef)) | |
(= ef (- ab cd))) | |
(fd/distinct [a b c d e f g h p]) | |
(== q [a b c d e f g h p]) | |
)) | |
) | |
(map | |
(fn [[a b c d e f g h p]] | |
(println " " a b "\n" | |
"-" c d "\n" | |
" ---\n" | |
" " e f "\n" | |
"+" g h "\n" | |
" ----\n" | |
p p p)) | |
result) | |
; result | |
; 8 5 | |
; - 4 6 | |
; ---- | |
; 3 9 | |
; + 7 2 | |
; ---- | |
; 1 1 1 | |
; 9 5 | |
; - 2 7 | |
; ---- | |
; 6 8 | |
; + 4 3 | |
; ---- | |
; 1 1 1 | |
; 8 6 | |
; - 5 4 | |
; ---- | |
; 3 2 | |
; + 7 9 | |
; ---- | |
; 1 1 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment