On 5 Oct 2015, at 11:45, andrea crotti <andrea.crott...@gmail.com> wrote:

> Hi everyone,
> 
> I was trying for fun to solve the following problem:
> 
> given a list of football players with some defined skills, find out which
> team selection would be balanced.
> 
> For example given just 4 players A, B, C, D there would be the following
> team selections:
> 
> - (A, B) vs (C, D)
> - (A, C) vs (B, D)
> - (A, D) vs (B, C)
> 
> So it's a combinatorial problem however both inside teams and inside the
> selection the order does not count, so the number of possible teams
> is a lot smaller than the actual all possible permutations.
> 
> I came up with a brute force solution here:
> 
> https://github.com/AndreaCrotti/football/blob/master/src/cljc/football/engine.cljc#L75
> 
> which however explodes already for 12 players because:
> 
> - it does all the possible permutations of teams (12! in that case)
> - partition accordingly (using sets to remove duplicates) and evaluate
>  every single one of them
> 
> Any idea how to make this faster?
> Other advices on the code are welcome as well..

I find your code unclear. I can’t tell what problem you’re trying to solve by 
reading the code or the comments. Do you have a specification of what problem 
you’re trying to solve? If not, you should write one before you do anything 
else.

Having said that, there is one way I can see that you might make the code 
slightly less bad. You define a field for your players called “:position” and 
then never use it. I know almost nothing about football, but I should think you 
might want the team to have at least one player in each position. So I might do 
something like (group-by :position players)

https://clojuredocs.org/clojure.core/group-by.

Then I might generate teams by picking one player in each position or something 
like that. This would reduce the number of combinations by some unknown amount. 
More generally, if you have too many combinations, introduce constraints in how 
you generate them.

Alan

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to