This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-23
Channels
- # admin-announcements (1)
- # arachne (3)
- # aws (1)
- # bangalore-clj (2)
- # beginners (209)
- # boot (81)
- # capetown (2)
- # cider (16)
- # clara (13)
- # cljsjs (16)
- # cljsrn (6)
- # clojure (217)
- # clojure-czech (1)
- # clojure-greece (4)
- # clojure-italy (3)
- # clojure-korea (3)
- # clojure-russia (3)
- # clojure-sg (3)
- # clojure-spec (104)
- # clojure-uk (23)
- # clojurescript (7)
- # component (7)
- # cursive (18)
- # datomic (12)
- # devcards (34)
- # dirac (17)
- # editors (3)
- # emacs (1)
- # events (1)
- # hoplon (62)
- # immutant (12)
- # incanter (1)
- # jobs (1)
- # klipse (2)
- # ldnclj (1)
- # luminus (1)
- # mount (1)
- # off-topic (8)
- # om (50)
- # onyx (46)
- # parinfer (5)
- # pedestal (4)
- # perun (2)
- # reagent (1)
- # rum (1)
- # schema (5)
- # specter (30)
- # untangled (5)
- # vim (46)
небольшой off про кложу и алгоритмы. вот например решение knapsack подсмотренное на hackerrank. их всего два там. русский и американец)
(ns hackerrank.knapsack
(:require [clojure.set :refer [union]]
[clojure.string :refer [split]])
(:import java.util.PriorityQueue))
(defn read-ints [] (map #(Long/parseLong %) (split (read-line) #"\s+")))
(dotimes [t (first (read-ints))]
(let [[n k] (read-ints)
xs (read-ints)
q (PriorityQueue. [0])]
(println (loop [prev nil] (if (empty? q) prev
(let [next (.poll q)]
(when-not (= next prev) (some->> (filter #(<= % k) (map #(+ next %) xs)) (.addAll q)))
(recur next)))))))
(defn solve [n W ws]
(letfn [(subsolve [m w]
(->> ws
(filter (partial >= w))
(map #(+ (m (- w %)) %))
(reduce max 0)
(conj m)))]
((reduce subsolve [0] (range 1 (inc W))) W)))
(dotimes [_ (read-string (read-line))]
(let [[n W] (read-string (str "[" (read-line) "]"))
ws (read-string (str "[" (read-line) "]"))]
(println (solve n W ws))))