4 ms·
> All you have to do is "compare and swap" and loop through until you are done, this is way easier than Fizzbuzz. I think you have this wrong, Fizzbuzz is actu
by kaashif 3y ago
> All you have to do is "compare and swap" and loop through until you are done, this is way easier than Fizzbuzz.
I think you have this wrong, Fizzbuzz is actually completely trivial to the point where the problem statement is almost literally (modulo modulo) a description of the algorithm.
Bubble sort is very easy but it's not literally trivial to the same degree as Fizzbuzz!
- cdelsolar 3y agofor i = 0 to n { for j = i to n { if n[j] > n[i] { swap(n[i], n[j] }}}
- sergiosgc 3y ago1 point for having a good reply. 100 points for doing it in code. Well done!
- btdmaster 3y agoExcept that sorts the list in reverse: https://tio.run/##Vc6xDsIwDATQPV9xYyJ5od2Qyo9UGYhIwFXkVlY68PUhKSDEctb5Lbc9y2OVsdZbTAh7CDlacWcDpFXBYIFe5R5tjtLgkLctP2P6U4ATZF48Lu2w/35xNOoy9aBem2ksuwrE5Gk@0UAjDd5sylLsZ1F2rtYX https://tio.run/##Vc6xDsIwDATQPV9xYyJ5od2Qyo9UGYhIwFXkVlY68P... (Also a subtle off-by-one error, it should be 0 to |n|-1 and i to |n|-1.)
- cdelsolar 3y agoThanks for catching the reverse. I was aware of the off by one but thought the “to” operator I invented would be exclusive of the second operand (kinda like range in Python) :)
- Jensson 3y ago> Fizzbuzz is actually completely trivial to the point where the problem statement is almost literally (modulo modulo) a description of the algorithm. Fizzbuzz requires you to read and understand a few lines of requirements. That is much harder than just "order these elements, runtime isn't important", you can easily miss some part of the problem statement or misunderstand it for Fizzbuzz and fail, you shouldn't but it can happen, no such thing for a quadratic sort.