Looking solutions up

Am I brainlet for not being able to come up with a double for loop to sort an array as a beginner? Did you have to learn those basic logic algorithms or did you come up with them by yourself.

Inb4 yes I hate being a brainlet

Sorting is a hard problem and it took many years to get to the point we are at now.
However once you understand the different solutions you should be able to reproduce the simpler ones without too much effort.

But should an aspiring programmer be able to figure things like sorting wih a double loop alone out or do most programmers need to learn them as beginners?

I want to gauge my abilities.

In my 2nd semester of CS (C++ programming) I came up with my own way to sort arrays using 2 pointers, one to the lowest and highest items seen. Then it places them in the appropriate positions, and decrease the search bounds by 2 (one on each side). I made my bubble sorting 2 times as efficient. I went online only to find out I was about 5 years too late, somebody beat me to it.

If you can't picture the solution, you are either a really early beginner, or need to seriously buckle down and learn.

I would definitely expect you to be able to write a sequence of steps in plain English that would explain how to sort a line made out of pieces of paper with numbers written on them.
If you can do that then it's just a matter of understanding your programming language of choice well enough to be able to translate to it from English.

You should be able to come up with a sort algorithm by yourself.

But I find it weird to restrict you to using exactly two for loops.
In real life you're hardly ever restricted, that's what's nice about programming IMO: you come up with a solution and then you build it.

After you told be I should be able to do it myself, I actually did it. Why couldnt I come up with this last week, and now it is different than the double foor loop I looked up.

Guess I m not a complete brainlete after all.

BUT, it only worked after I wrote i=-1 with i=0, the first number didnt change could someone explain to me why?

sorry forgot the picture here
30s...20s....10s.............321

At the end of your for loop, "i" will be incremented by one, thus making i=1 if you make i=0.

This sorting algorithm is pretty inefficient though. It's pretty much as bad as bubble sort. Check out quick sort or merge sort.

Ohh okay thank you
Yes i believe but it was just a test to see if I could come up with my own way of sorting after looking up a double for loop

Did you even test it? That doesn't work at all.

You're doing what many beginners do which is trying to code before you have any strategy at all prepared. You put two for loops, because it says two for loops, without thinking about why you'd need them.

Your second for loop just prints an array. It has nothing to do with sorting.

What you have there (if you remove i=-1, which makes absolutely no sense if you take the time to think about it) is one round of bubblesort.

THINK. How would you sort a list of numbers?

Look at it again. I don't think OP came up with an O(n) sorting algorithm.

Yeah, I said it was inefficient

It's not inefficient, it doesn't even work.

It does work
And I the print loop was just there to see that that I successfully rearranged the array

lol, no it doesn't. I dunno how the fuck you got that output, but it does not.

Work through your algo yourself on a piece of paper. No way you will end with a sorted array.

>Am I brainlet for not being able to come up with a double for loop to sort an array as a beginner?
Yes.

ps, if you're still convinced you found an O(n) comparison sort, please head to your local university for your complimentary PhD

Lol it does work. I dunno how the fuck you didnt get that output, but it does.
Seriously you can see the screenshot and no matter how I type in the numbers it does work

Inever said anything about O(n) etc I just said I found a way to sort an array on my own without having to use the double for loop

nice, bait. you got me

No. Theres a reason all algorithms books teach basic sorting algorithms. Theres no reason someone should be expected to figure out sorting algorithms on their own.

Did you try to run that program? It will not work, {5,8,1} will just become {5,1,8}.
>being such a brainlet you don't realize it

You need to read about algorithms in general and some famous ones (qsort, mergesort, sieve of erastothenes etc). Understand them, try to adapt them to your needs and learn to think in a way so you can create something similar.

It is mostly practice, but will be easier for some than for others, as with everything.

That's horseshit. If I gave you a list of numbers, surely you could find SOME way of sorting it. Obviously, you'd come up with a terrible inefficient algo, but you could come up with something.

It actually work because of the i=-1; which looks like a -=1 at first. That way he restarts at the first element after every switch, making it terribly inefficient, off the top of my headI think O(n*!(n-1)), but not sure.

Everyone here is trolling. Nope, it works.

Still, this is the definition of bogosort, a piece of shit sorting algorithm only good for academic purposes.

Stop samefagging, we know it's bait.

Confirmed, user doesn't know how python for loops/range statements

... work.

Seriously, the fact that people in this thread are saying that this algorithm doesn't work really proves the current state of Sup Forums's critical thinking skills.

This algorithm sucks ass, but it works.

you do both user, it's a very good start to start learning algorithms like sorting as you describe here and implement them your self

That is not something new
Dont call anything you make your own without a PhD and a Thesis to back it, kiddo

Sorry user, you're wrong

what editor is this?

Vim + airline + conqueterm + a bunch of other plugins