Guest User

Untitled

a guest
Jan 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. (defpackage #:snippets/cryptography-problem
  2. (:use #:cl #:screamer #:screamer+)
  3. (:shadowing-import-from #:screamer #:defun))
  4.  
  5. (in-package #:snippets/cryptography-problem)
  6.  
  7. ;; S E N D
  8. ;; M O R E
  9. ;; =========
  10. ;; M O N E Y
  11.  
  12. (defmacro as-integer (&rest digits)
  13. `(+v ,@(loop for d in digits
  14. for i from (- (length digits) 1) downto 0
  15. collect `(*v ,d ,(expt 10 i)))))
  16.  
  17. (defun cryptography-problem ()
  18. (let ((vars (loop repeat 8 collect (an-integer-betweenv 0 9))))
  19. (destructuring-bind (s e n d m o r y) vars
  20. (assert! (all-differentv s e n d m o r y))
  21. (assert! (=v (+v (as-integer s e n d)
  22. (as-integer m o r e))
  23. (as-integer m o n e y)))
  24. (solution vars (static-ordering #'linear-force)))))
  25.  
  26. ;; (one-value (cryptography-problem))
  27. ;; ==> (2 8 1 7 0 3 6 5)
  28. ;;
  29. ;; (all-values (cryptography-problem))
  30. ;; ==> ((2 8 1 7 0 3 6 5) (2 8 1 9 0 3 6 7) (3 7 1 2 0 4 6 9) (3 7 1 9 0 4 5 6)
  31. ;; (3 8 2 1 0 4 6 9) (3 8 2 9 0 4 5 7) (5 7 3 1 0 6 4 8) (5 7 3 2 0 6 4 9)
  32. ;; (5 8 4 9 0 6 3 7) (6 4 1 5 0 7 3 9) (6 4 1 9 0 7 2 3) (6 5 2 4 0 7 3 9)
  33. ;; (6 8 5 1 0 7 3 9) (6 8 5 3 0 7 2 1) (7 3 1 6 0 8 2 9) (7 4 2 9 0 8 1 3)
  34. ;; (7 5 3 1 0 8 2 6) (7 5 3 4 0 8 2 9) (7 5 3 9 0 8 1 4) (7 6 4 3 0 8 2 9)
  35. ;; (7 6 4 9 0 8 1 5) (8 3 2 4 0 9 1 7) (8 4 3 2 0 9 1 6) (8 5 4 2 0 9 1 7)
  36. ;; (9 5 6 7 1 0 8 2))
Add Comment
Please, Sign In to add comment