Skip to content

Instantly share code, notes, and snippets.

@chopmo
Last active October 5, 2016 18:34
Show Gist options
  • Save chopmo/654d8112b48585f929eae21650b3bd9a to your computer and use it in GitHub Desktop.
Save chopmo/654d8112b48585f929eae21650b3bd9a to your computer and use it in GitHub Desktop.
(ns Player
(:require [clojure.set :as s])
(:gen-class))
(defn node-filter [nodes]
(fn [link]
(not-empty
(s/intersection
(set link)
(set nodes)))))
(defn -main [& args]
(let [num-nodes (read)
num-links (read)
num-gateways (read)
links (doall (repeatedly num-links (fn [] [(read) (read)])))
gateways (doall (repeatedly num-gateways read))]
(while true
(let [si (read)
si-links (filter (node-filter [si]) links)
si-gw-links (filter (node-filter gateways) si-links)
link-to-sever (first (concat si-gw-links si-links))]
(apply println link-to-sever)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment