Thanks a lot for the fast reply!
Now I have the vector as I wanted.

I have been playing with your code: (map #(/ votes %) (iterate inc 1))

user=> (take 10 (map #(/ 100 %) (iterate inc 1)))
(100 50 100/3 25 20 50/3 100/7 25/2 100/9 10)

I have managed to put that in a lazy sequence:
user=> (def ls (lazy-seq (map #(/ 100 %) (iterate inc 1))))
#'user/ls

And then retrieve the values I want with:
user=> (take 5 ls)
(100 50 100/3 25 20)


I don't know how to filter and work with the vector & map in order to
apply that function for each party, in each province.
I have been trying to use the filter function but I get the following
error:

user=> (filter #"A" [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"]
["B" "p2" "21"]])
java.lang.ClassCastException: java.util.regex.Pattern cannot be cast
to clojure.lang.IFn


Thanks again and I will be posting any advances!


On 20 Des, 22:44, Alan <a...@malloys.org> wrote:
> Since Ken doesn't mention it explicitly: there's a difference between
> vec and vector. (vec x) returns a vector containing all the elements
> of x - a vector "view" of x, I think the doc mentions. (vector x)
> returns a vector containing the single element x.
>
> On Dec 20, 1:33 pm, Ken Wesson <kwess...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Mon, Dec 20, 2010 at 4:28 PM, Anclj <anb...@gmail.com> wrote:
> > > Hi,
>
> > > I have some questions related with maps and vectors, if someone can
> > > help me I will appreciate it a lot.
>
> > > I have a vector like:
> > > ["a1" "a2" "a3" "b1" "b2" "b3" "c1" "c2" "c3"]
>
> > > And I would like to have:
> > > [["a1" "a2" "a3"] ["b1" "b2" "b3"] ["c1" "c2" "c3"]]
>
> > user=> (into [] (map vec (partition 3 [1 2 3 4 5 6 7 8 9])))
> > [[1 2 3]
> >  [4 5 6]
> >  [7 8 9]]
>
> > > I have a map that represents provinces and seats, like this:
> > > {"p1" "5", "p2" "8", "p3" "13", "p4" "11"}
>
> > > Which means that in "p1" 5 seats will be distributed, 8 for "p2", and
> > > so on.
>
> > > And a vector where its elements are vectors formed by a political
> > > party, a province and the votes he got. Like this:
> > > [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"] ["B" "p2" "21"] ...]
>
> > > I need, for each province, to distribute the seats among the parties
> > > according to the number of votes following this rule:
>
> > > For each party, i should get a lazy sequence with the values of:
> > > #votes/1, #votes/2, #votes/3, #votes/4, ...
>
> > > So, in this example, for the "p1" province I would have:
> > > For A party: 32, 16, 32/3, 8, ...
> > > And for B party: 55, 55/2, 55/3, 55/4, ...
>
> > (map #(/ votes %) (iterate inc 1))
>
> > > I'm not familiar with Clojure, and I don't know how to use many
> > > functions. Any reference to high-level functions that I should use,
> > > and how to use them will be appreciated.
>
> > Hope the above gets you started. Obviously it won't do any more than
> > that -- partly because I don't have much time right now and partly
> > because I suspect I might be doing your homework for you if I went
> > much further. :)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to