This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-15
Channels
- # admin-announcements (60)
- # adventofcode (37)
- # beginners (53)
- # boot (94)
- # bristol-clojurians (1)
- # cider (21)
- # clara (19)
- # cljsrn (1)
- # clojure (222)
- # clojure-chicago (1)
- # clojure-dev (2)
- # clojure-nl (11)
- # clojure-russia (301)
- # clojure-turkiye (1)
- # clojurecup (6)
- # clojurescript (30)
- # core-async (3)
- # cursive (64)
- # datascript (2)
- # datomic (55)
- # devops (16)
- # editors (1)
- # emacs (16)
- # ldnclj (6)
- # off-topic (18)
- # om (113)
- # onyx (3)
- # parinfer (1)
- # proton (48)
- # re-frame (20)
- # reagent (7)
mmm. nvm, there is this approach: http://stackoverflow.com/questions/14836414/can-i-make-a-deterministic-shuffle-in-clojure
someone who give me a tip for this challenge : http://www.4clojure.com/problem/63
@roelof: Off the top of my head I’d say you want a reduce
with an update-in
and fnil
...
reduce
because you’re transforming a sequence to a potentially shorter sequence, update-in
because you’ll be updating entries in a map data structure as you reduce the sequence, and fnil
because if the map entry is nil
, you’ll want to substitute []
before you conj
onto it.
Is that enough of a tip? Too much?
The part I do not see is one the first one how I can make a true / false part and on a calculating I see a 1/2 2/3
its looks to me I have to find a way I can check what the functions returns a boolean or a number
What is the function provided in that first problem? How does it apply to elements of the sequence provided?
(there is also the hint that you cannot use group-by
therefore you might assume you are being asked to implement group-by
)
So that first function is true
if its argument is greater than five, false
if its argument is five or less.
The second function returns a long, given a long.
The third function return a long, given a sequence.
Yes, I know but if I use a if then and only check for true/false then the others will not work
You’re overthinking.
Just apply the function to each element of the sequence. What do you get in each case?
first case true/ false . Second one I doubt. I do not fully understand what #(apply / %) does but I think a number and the 3rd one a number
This is one of those cases where types would be very, very helpful. You’re asked to write a function that takes (A->B) and [A] and returns {B : [A]}
(apply / [2 3 4])
is (/ 2 3 4)
which is 2/3/4
I know. But the types give you the generic shape of the result — for any input types.
In the 1st case you have (long -> bool) and [long] so you get {bool : [long]}
I know types a little when I tried Haskell for some days . I fight all the times against them
In the 2nd case you have ([num] -> num) and [[num]] so you get {num : [[num]]}
oke, so I have a function which inputs is a number. The functions output is a boolean and I want to represent it as a boolean and a list of numbers
In the 3rd case you have ([A] -> long) and [[A]] so you get {long : [[A]]}
Although they are ratios 1/2 and 2/3
But the types give you the hint: the results of the function you are passed (applied to each element of the sequence you are passed) are the keys of the map you produce.
thanks as I said earlier. Time to do some experiments and small steps to solve this one
When you solve it and look at the solutions, amalloy’s is very nice!
Bed time here. Good luck!
Hi... any suggestions on how to "transpose" a list of maps?
I.e convert this '({:a 10 :b 20} {:a 50 :b 75})
into this {:a '(10 50) :b '(20 75)}
oh... merge-with
does the trick, and even the next step I needed (to sum the lists), all in one step
@polymeris: I’m just curious, why quoted list and not vector? is there any difference here?