constraint programming - Finding similar sets with clojure's core.logic / minikanren -
this first question on stack overflow.
i’m new logic programming , trying evaluate if can used solve matching problems i’m working on.
problem:
lets have set looks this.
a = {1, 2, 3, 4}
and have other sets looks this.
b = {1, 2} c = {3, 5, “banana"} d = {2, 3, 4}
the problem i’m trying solve is,
"find me set share members set a, compared other sets know about."
the answer in case should set d, because shares 3 members set a. compared other sets share 2 , 1 member a.
question 1:
can logic programming solve types of problems?
question 2:
if can, how in example clojure’s core.logic?
qeshi
the following shows getting best fit result using clojure.set
:
(ns sample.sandbox (:require [clojure.set :as set]) ) (def #{ 1, 2, 3, 4}) (def b #{1, 2}) (def c #{3, 5, "banana"}) (def d #{2, 3, 4}) (defn best-fit-set [control & sets] (apply max-key count (map #(set/intersection control %) sets ))) (best-fit-set b c d) => #{4 3 2}
Comments
Post a Comment