>>32
>No dumb shit, I wanted to know whether or not OP was asking >for combinations or permutations, because I didn't read his >list of required outputs. However after reading the list it is >obvious that he is looking for all combinations with two >indices.
It's kind of funny how everyone, except for you, thought it was a permutation.
>You seem to be confused. In a permutation order matters, in a >combination order does not. Try and think before speaking you >mental midget.
Stop projecting. I was able to post working code that produced the correct output you didn't.
>>32
[quote]
No dumb shit, I wanted to know whether or not OP was asking for combinations or permutations, because I didn't read his list of required outputs. However after reading the list it is obvious that he is looking for all combinations with two indices.
[/quote]
It's kind of funny how everyone, except for you, thought it was a permutation.
[quote]
You seem to be confused. In a permutation order matters, in a combination order does not. Try and think before speaking you mental midget.
[/quote]
Stop projecting. I was able to post working code that produced the correct output. You didn't. Presumably because you are a clueless twat that doesn't have an ounce of programmers blood in them.
Name:
Anonymous2012-02-06 10:29
>>43
I swear this is the special olypmics of computer programmin. In on corner we have the homo who can't come up with a correct programming solution. In the other corner we have the minimum wage toilet scrubber who doesn't seem to understand the difference between a combination and a permutation.
Name:
Anonymous2012-02-06 10:30
>>45
And apparently I can't type for shit this morning.
Name:
Anonymous2012-02-07 7:33
This one might be more efficient than the binary recursive one. It still has an append though. And the sets are backwards, and it needs a cut off number for the size of the lists. It calculates each subset of n elements, giving it a best case running time of 2^n,
(define (combinations lis)
(letrec ((helper (lambda (lis accumulation)
(if (null? lis)
accumulation
(helper (cdr lis)
(append accumulation
(map (lambda (rest) (cons (car lis) rest))
accumulation)))))))
(helper lis (list '())))) ;; start with the empty set in accumulation
(combinations '(a b c d e))
:w !scm
#<unspecified>
(() (a) (b) (b a) (c) (c a) (c b) (c b a) (d) (d a) (d b) (d b a) (d c) (d c a) (d c b) (d c b a) (e) (e a) (e b) (e b a) (e c) (e c a) (e c b) (e c b a) (e d) (e d a) (e d b) (e d b a) (e d c) (e d c a) (e d c b) (e d c b a))
Name:
Anonymous2012-02-07 8:02
A zomg optimized version that avoids using append, but the ordering of the results becomes very strange. There's a lot of reused memory here. IE, (e c b) and (d c b) have the same cdr.
:w !scm
#<unspecified>
((e) (e a) (e b a) (e b) (e c b) (e c b a) (e c a) (e c) (e d c) (e d c a) (e d c b a) (e d c b) (e d b) (e d b a) (e d a) (e d) (d) (d a) (d b a) (d b) (d c b) (d c b a) (d c a) (d c) (c) (c a) (c b a) (c b) (b) (b a) (a) ())
Name:
Anonymous2012-02-07 8:42
So why aren't your solutions as easy as >>8?
I mean if your language is going to be slow as shit it might as well offer the things that Python offer.
>>51
I should have looked up what permutations() did in python. My apologies, I assumed it would be consistent with the mathematical definition. How foolish of me.