@monoarch_dodra
I solved BogoSort
import std.stdio, std.algorithm, std.random;
void bogoSort(T)(T[] data) {
while (!isSorted(data))
randomShuffle(data);
}
void main() {
auto array = [2, 7, 41, 11, 3, 1, 6, 5, 8];
bogoSort(array);
writeln(array);
}
https://github.com/ag
On Sunday, 8 June 2014 at 08:44:42 UTC, monarch_dodra wrote: of.
If you want to use a bad algorithm, you could also go for
bogosort:
void main() {
auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];
while (!isSorted(data))
randomShuffle(data);
data.writeln;
}
I'm partial to Mi
On Saturday, 7 June 2014 at 22:01:25 UTC, Ali GOREN wrote:
Thank you. I can not resolve it in quicker time, right?
Depends what exactly you want to achieve. This will achieve the
same result in a fraction of the time.
void main() {
auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];
sort
Thank you Chris. Now I understand. I thought myself incorrectly
but this was a normal.
On Saturday, 7 June 2014 at 22:09:11 UTC, Chris Cain wrote:
On Saturday, 7 June 2014 at 22:01:25 UTC, Ali GOREN wrote:
Thank you. I can not resolve it in quicker time, right?
You might be able to come up w
On Saturday, 7 June 2014 at 22:01:25 UTC, Ali GOREN wrote:
Thank you. I can not resolve it in quicker time, right?
You might be able to come up with a faster way to permute, but
it's mostly pointless because it will always be very slow. Use
std.algorithm.sort if you want to sort quickly, as t
Thank you. I can not resolve it in quicker time, right?
Also:
dlang online compiler and dpaste:
return code: 9 killed
why?
thank you
On Saturday, 7 June 2014 at 21:57:31 UTC, Chris Cain wrote:
On Saturday, 7 June 2014 at 21:40:08 UTC, Agora wrote:
Why is running slow?
One of the main rea
On Saturday, 7 June 2014 at 21:40:08 UTC, Agora wrote:
Why is running slow?
One of the main reasons is because the number of permutations an
array has is n!. Thus the expected runtime is O(n!). That's a
slow, slow algorithm in general. In particular, your array with
length 11 has 39,916,800
Hi.
I've found some code
import std.stdio, std.algorithm;
void permutationSort(T)(T[] items) pure nothrow {
while (items.nextPermutation) {}
}
void main() {
auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];
data.permutationSort;
data.writeln;
}
This code is running very slow
R