Created
December 22, 2015 21:24
-
-
Save sbenhaim/9325619cac1da72ac657 to your computer and use it in GitHub Desktop.
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
(ns advent.a16 | |
(:require [clojure.string :as str])) | |
(def sue | |
{:children 3 | |
:cats 7 | |
:samoyeds 2 | |
:pomeranians 3 | |
:akitas 0 | |
:vizslas 0 | |
:goldfish 5 | |
:trees 3 | |
:cars 2 | |
:perfumes 1}) | |
(defn compare [probable actual key] | |
(let [a (actual key) | |
p (probable key)] | |
(or (nil? a) (nil? p) | |
(condp = key | |
:cat (> p a) | |
:trees (> p a) | |
:pomeranians (< p a) | |
:goldfish (< p a) | |
(= p a))))) | |
(def sue-facts {:Sue1 { :cars 9 :akitas 3 :goldfish 0} | |
:Sue2 { :akitas 9 :children 3 :samoyeds 9} | |
:Sue3 { :trees 6 :cars 6 :children 4} | |
:Sue4 { :trees 4 :vizslas 4 :goldfish 9} | |
:Sue5 { :akitas 9 :vizslas 7 :cars 5} | |
... | |
}) | |
(first (filter (fn [[s sm]] (every? #(compare sm sue %) (keys sm))) sue-facts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment