Last active
May 5, 2022 06:44
-
-
Save righ1113/49f124d67c2c01477e2cb896b0a7eace to your computer and use it in GitHub Desktop.
SEND + MORE = MONEY
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
| ;; gosh> (gauche-version) | |
| ;; "0.9.5" | |
| ;; egison.scm は https://github.com/egison/egison-scheme/blob/master/egison.scm | |
| ;; から取得し、モジュール化しておく | |
| ;; > (add-load-path "./send") | |
| ;; > (use send) | |
| ;; リロード時 > (reload 'send) | |
| ;; モジュールのインタフェースの定義 | |
| (define-module send | |
| (use egison) | |
| (export | |
| test1 | |
| test2 | |
| send1 | |
| send2 | |
| ) | |
| ) | |
| ;; モジュール本体 | |
| (select-module send) | |
| (define test1 | |
| (match-all '(1 2 5 9 4) (Multiset Integer) [(cons x (cons `(+ x 1) _)) x]) ; (1 4) | |
| ) | |
| (define test2 | |
| (match-all '(1 2 5 9 4) (Multiset Integer) [(cons (and x (pred (lambda (y) (= y 4)))) _) x]) ; (4) | |
| ) | |
| (define (money1? xs) | |
| (let | |
| ( (s (list-ref xs 0)) | |
| (e (list-ref xs 1)) | |
| (n (list-ref xs 2)) | |
| (d (list-ref xs 3)) | |
| (o (list-ref xs 4)) | |
| (r (list-ref xs 5)) | |
| (y (list-ref xs 6)) ) | |
| (= | |
| (+ (+ (* 1000 s) (* 100 e) (* 10 n) d) (+ 1000 (* 100 o) (* 10 r) e)) | |
| (+ 10000 (* 1000 o) (* 100 n) (* 10 e) y) | |
| ) | |
| ) | |
| ) | |
| ;; 解を返す:((9 5 6 7 0 8 2)) | |
| (define send1 | |
| (filter money1? | |
| (match-all '(0 2 3 4 5 6 7 8 9) (Multiset Integer) | |
| [(cons (and s (not `0)) (cons e (cons n (cons d (cons o (cons r (cons y _))))))) (list s e n d o r y)] | |
| ) | |
| ) | |
| ) | |
| (define (money2? s e n d o r) | |
| (lambda (y) | |
| (= | |
| (+ (+ (* 1000 s) (* 100 e) (* 10 n) d) (+ 1000 (* 100 o) (* 10 r) e)) | |
| (+ 10000 (* 1000 o) (* 100 n) (* 10 e) y) | |
| ) | |
| ) | |
| ) | |
| ;; 解を返す:((9 5 6 7 0 8 2)) | |
| (define send2 | |
| (match-all '(0 2 3 4 5 6 7 8 9) (Multiset Integer) | |
| [(cons (and s (not `0)) (cons e (cons n (cons d (cons o (cons r | |
| (cons (and y (pred (money2? s e n d o r))) _))))))) (list s e n d o r y)] | |
| ) | |
| ) | |
| (provide "send") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment