This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-14
Channels
- # aleph (3)
- # beginners (25)
- # cider (12)
- # clojure (42)
- # clojure-canada (3)
- # clojure-nl (1)
- # clojure-russia (2)
- # clojure-spec (13)
- # clojure-uk (24)
- # clojurescript (23)
- # cloverage (1)
- # datomic (7)
- # figwheel-main (3)
- # jobs-discuss (14)
- # onyx (48)
- # parinfer (3)
- # re-frame (20)
- # reitit (28)
- # shadow-cljs (3)
- # testing (1)
- # vim (37)
@ryan.russell011 As long as you are happy. I began on Emacs with no more than the Brave Clojure emacs setup and was quickly productive aside from never knowing what the hell buffer Emacs would select when I navigated. Then an ex-friend recommended Spacemacs and pretty soon I was on IntelliJ. 🙂
btw, not sure where your sticking points are, but if the keychords are a problem just hang in there. That much I love. Try to learn a new one every week over the morning coffee.
mostly I am just trying to get into a good Clojure environment.. and since Emacs is the one thing I haven't used much figured I'd give it a go. I decided to ditch Spacemacs... it has a feel to it that I didn't much care for.. so I just embarked on the journey of Emacs configuration and all it's "glory" lol
Evil mode will have to be installed... not having Vim commands is something that I'm not sure I could live with lol
@parth.12282 looks like what's going wrong is that you're expecting calling dissoc
and assoc
on major-data
, minor-data
, major-only
and minor-only
is going to modify those things like variables. Clojure has immutable data. When you call assoc
on a binding like minor-only
, it returns the result of that - a new map with the key assoced in - but minor-only
doesn't change.
For what you're trying to do there, you probably want to do a reduce
to build up the new map data structure that you return, rather than map
@michael.gaare Thanks for the help. I am trying to do it with using reduce
, but it is not getting iterated in any of the http://condition.Do I also need to change anything else with the change of replacing map
with reduce
?
If the key-value pair of major-data is not present in the minor-data then that entry should be considered in major-only (because it is present in only major data). And if the major-data's value for a particular key is not a subset of the minor's value for that same key then it should be included in minor-only.
so you want an end result in the shape of { :minor-only {200 {...}, 201 {...}}, :major-only {200 {...}, 201 {...}}, :both {200 {...}, 201 {...}} }
?
In end result even if i have only map as { :minor- only value-of-minor-only :major-only value-of-major-only }
it should be fine, Since we are going to have values in both of them when subset condition fails, so no need to have an extra both to the end result.
>we are going to have values in both of them when subset condition fails i don't understand what you're trying to achieve
Okay.Sorry for not explaining properly. For example, i have this data
`{"Major" { [200 {1 5,2 10, 3 10} ] [201 {1 5,2 10,4 10,6 10} [204 {1 4,2 5,3 8,4 9}]]}
"Minor" {[200 {1 5,2 10,3 10,4 10}] [203 {1 5,2 10,3 10}] [204 {1 4,2 5,3 8}]}})`
- major-only
will be:-` {201 value} (because it doesn't exists in minor), 204 (since the major's value is not subset of minor's value for key 204)`
- minor-only
will be :-`{203 value} (Since it does not exists in major),204 entry(because the subset condition failed`)
my very inefficient and naive solution would be to reduce first to produce major-only by iterating over major's keys, then doing the same for minor-only with minor's keys
Can anyone see what's wrong with this function? I keep getting the error: IllegalArgumentException Don't know how to create ISeq from: clojure.core$array_map clojure.lang.RT.seqFrom
I've already exhausted everything I would know to do to debug this 😥
(defn find-even-index "You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1." [arr] (if (= 0 (reduce + array-map)) 0 (loop [i 1 a arr] (cond (= i (count a)) -1 (= (reduce + (take i a)) (reduce + (drop (dec i) a))) i :else (recur a (inc i))))))
(defn find-even-index
"You are going to be given an array of integers. Your job is to take
that array and find an index N where the sum of the integers to the left
of N is equal to the sum of the integers to the right of N. If there is
no index that would make this happen, return -1."
[arr]
(if (= 0 (reduce + array-map)) 0
(loop [i 1
a arr]
(cond
(= i (count a)) -1
(= (reduce + (take i a)) (reduce + (drop (dec i) a))) i
:else
(recur a (inc i))))))
sorry here's the same code w/ better formattingand here's the codewar question i'm trying (but failing) to implement: https://www.codewars.com/kata/5679aa472b8f57fb8c000047/train/clojure
the signature of reduce is ([f coll] [f val coll])
. array-map
is a function not a collection
and it mirrors exactly your message: IllegalArgumentException Don't know how to create ISeq from: clojure.core$array_map clojure.lang.RT.seqFrom
Illegal argument: I need an iseq (read collection type (first and rest i believe). and you gave me the function clojure.core$array_map (clojure.core/array-map)
wow! @dpsutton thank so much! i see now that i accidentally autocompleted that line and somehow did not notice that when I reviewed it many times