Created
July 30, 2017 12:01
-
-
Save kencoba/05424572cbcd5f06aafa8e988e00f00c to your computer and use it in GitHub Desktop.
Magic hexagram
This file contains 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 util.combinations) | |
(use gauche.collection) | |
; Magic hexagram | |
; | |
; a | |
; / \ | |
; b---c---d---e | |
; \ / \ / | |
; f g | |
; / \ / \ | |
; h---i---j---k | |
; \ / | |
; l | |
(define (nth lst n) | |
(vector-ref (list->vector lst) n)) | |
(permutations*-for-each | |
(lambda (lst) | |
(let ((a (nth lst 0)) | |
(b (nth lst 1)) | |
(c (nth lst 2)) | |
(d (nth lst 3)) | |
(e (nth lst 4)) | |
(f (nth lst 5)) | |
(g (nth lst 6)) | |
(h (nth lst 7)) | |
(i (nth lst 8)) | |
(j (nth lst 9)) | |
(k (nth lst 10)) | |
(l (nth lst 11))) | |
(when (= (+ a c f h) | |
(+ e g j l) | |
(+ b c d e) | |
(+ h i j k) | |
(+ a d g k) | |
(+ b f i l)) | |
(print lst)))) | |
'(1 2 3 4 5 6 7 8 9 10 11 12)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment