Last active
May 20, 2021 12:15
-
-
Save dra1n/bd603924a02560847a14d3d52fc7ca3b to your computer and use it in GitHub Desktop.
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
| (ns logical-boys-girls.core | |
| (:require [clojure.core.logic :as logic] | |
| [clojure.core.logic.fd :as fd])) | |
| (logic/run* | |
| [q] | |
| (let [students-count (fd/interval 1 100)] | |
| (logic/fresh [boys girls h-girls q-girls h-boys q-boys] | |
| ;; boring part | |
| ;; every lvar belongs to number from interval | |
| (fd/in boys students-count) | |
| (fd/in girls students-count) | |
| (fd/in h-girls students-count) | |
| (fd/in q-girls students-count) | |
| (fd/in h-boys students-count) | |
| (fd/in q-boys students-count) | |
| ;; fun part | |
| (fd/+ boys girls 48) ;; number of students in class | |
| (fd/* 2 h-girls girls) ;; divide girls in two groups | |
| (fd/* 2 q-girls h-girls) ;; rest should seat with each other, so divide one more time | |
| (fd/>= boys h-girls) ;; there should be enough boys to sit with half of girls | |
| (fd/* 2 h-boys boys) ;; same stuff for boys, see comments above | |
| (fd/* 2 q-boys h-boys) | |
| (fd/>= girls h-boys) | |
| (logic/== [boys girls] q)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment