This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-20
Channels
- # aws (1)
- # beginners (14)
- # boot (30)
- # cider (6)
- # clara (9)
- # cljsjs (3)
- # cljsrn (22)
- # clojure (247)
- # clojure-dusseldorf (75)
- # clojure-france (38)
- # clojure-italy (6)
- # clojure-japan (8)
- # clojure-nl (3)
- # clojure-russia (16)
- # clojure-serbia (4)
- # clojure-spec (1)
- # clojure-uk (53)
- # clojurescript (168)
- # consulting (3)
- # copenhagen-clojurians (1)
- # core-async (7)
- # css (1)
- # datascript (3)
- # datomic (8)
- # dirac (22)
- # events (1)
- # hoplon (2)
- # jobs (1)
- # jobs-discuss (2)
- # leiningen (4)
- # lumo (138)
- # mount (13)
- # nyc (1)
- # off-topic (24)
- # om (34)
- # onyx (15)
- # pedestal (30)
- # re-frame (9)
- # reagent (23)
- # ring (1)
- # ring-swagger (24)
- # rum (6)
- # spacemacs (6)
- # specter (51)
- # uncomplicate (14)
- # unrepl (1)
- # untangled (17)
- # yada (12)
morning!
rcfotd:
-------------------------
clojure.core/get-method
([multifn dispatch-val])
Given a multimethod and a dispatch value, returns the dispatch fn
that would apply to that value, or nil if none apply and no default
really? it seems pretty niche
@yogidevbear I solved the puzzle here: https://gist.github.com/madstap/a01600d9243a6229e6689d24d9deb275
@madstap That's awesome π Thanks for taking the time to look into it π
I feel like a #friday-puzzler channel in this slack group could be really interesting (esp. with so many active members)
(defn f [ns total]
(get (group-by #(reduce + %)
(mapcat clojure.math.combinatorics/combinations
(repeat ns)
(range 1 (inc (count ns)))))
total))
?@madstap so when looking at the results of (f [1 2 3 4 5] 5)
and getting #{{3 1, 2 1} {4 1, 1 1} {5 1}}
, am I reading the results correctly that it's one instance of 3 (`#{{3 1,`...) plus one instance of 2 (...`2 1},`...) equals 5?
@peterwestmacott If I want to include the combinations namespace within a lein repl
, do you know what the command is?
(require 'clojure.math.combinatorics)
but you maybe want to alias it to something: (require '[clojure.math.combinatorics :as combos])
https://github.com/clojure/math.combinatorics looks like you need to depend on it?
FileNotFoundException Could not locate clojure/math/combinatorics__init.class or clojure/math/combinatorics.clj on classpath. clojure.lang.RT.load (RT.java:456)
you might need this in your project.clj: [org.clojure/math.combinatorics "0.1.4"]
Yeah, I'm trying to get it as an entire script I can drop into a repl for simplicity sake for demoing to people that haven't got an environment set up
(eval (slurp "raw.githubusercontent.com..."))
?
@peterwestmacott That just returns a string of the file...
yeah, sorry
in my haste I forgot the call to read-string
the point is that there will be a way to load the ns from a URL - but it probably isnβt what you actually want to do
But if I wanted to do that hack, how do I read all the forms to pass to eval? read-string just reads the first form
I'm not sure its going to work - the file you need
is a cljc file and it doesn't seem to read
nicely.
how much setup are you prepared to accomodate?
if they have a repl running, did they install leiningen?
if you can slurp/spit the content to the right place (somewhere on the classpath, with the right filename for the namespace) then you can require
it as normal.
If you use boot it's just boot -d org.clojure/math.combinatorics:0.1.4 --file main.clj
π
#!/usr/bin/env boot
(set-env! :dependencies '[[org.clojure/math.combinatorics "0.1.4"]])
(require 'clojure.math.combinatorics)
(defn variations
[numbers sum]
(filter #(= sum (apply + %)) (clojure.math.combinatorics/subsets numbers)))
(defn -main [& args]
(prn (variations [1 2 2 3 5] 5)))
Save this as "anything.clj" and either do boot -f anything.clj
or chmod +x anything.clj
followed by ./anything.clj
πI have a feeling I missed something given @peterwestmacott's solution being different to mine, that I've missed something. Not sure though π
Thanks Dominic π I'll give it a go later and share the solution on the puzzle gist if you're okay with me sharing π
@jonpither I really enjoyed the article, thanks for the link earlier...
@jonpither Hmmm... I can't find it...