Trolling people looking for easy answers is pointless. Folks like this won't use a single source to send in their work. The problem with this approach is you often penalize people who are truly curious and not trolls. If you were to allow the masses to determine whether a question is a troll question or not, using an OR, allowing anyone to flip the bit, then almost every question would be considered a troll question.…
Trolling homework questions - sorting
41–50 of 51 posts
Re: Trolling homework questions - sorting
#42Earlier quoted context omitted.
yeah, that's why i don't code in perl
Claiming that Perl is a bad language because you can obfuscate it just means that you've never looked for "obfuscated ".
Re: Trolling homework questions - sorting
#43No one suggested sleep sort? That's the ultimate trolling-but-almost-legitimate sorting algorithm. :)
I noticed this myself and decided to write a glorious example in Objective C: http://codegolf.stackexchange.com/a/16390/11612
Re: Trolling homework questions - sorting
#44Trolling people looking for easy answers is pointless. Folks like this won't use a single source to send in their work. The problem with this approach is you often penalize people who are truly curious and not trolls. If you were to allow the masses to determine whether a question is a troll question or not, using an OR, allowing anyone to flip the bit, then almost every question would be considered a troll question.…
I downvoted because I disagree with asking for explanations of downvotes. I think the practice is bad for HN.
I was -1 when I edited the comment to include it and +22 now and a lot less confused.
Re: Trolling homework questions - sorting
#45Trolling people looking for easy answers is pointless. Folks like this won't use a single source to send in their work. The problem with this approach is you often penalize people who are truly curious and not trolls. If you were to allow the masses to determine whether a question is a troll question or not, using an OR, allowing anyone to flip the bit, then almost every question would be considered a troll question.…
Everything you say is true. Luckily, none of it applies because no one goes to CodeGolf for homework questions. CodeGolf will look at other SE sites, find homework questions, then take those questions back to codegolf. Thus, CodeGolf gets an interesting new flavour of challenge (provide the worst solution to a problem) and the person who originally asked the question doesn't have to deal with the codegolfing. They do…
Re: Trolling homework questions - sorting
#46Earlier quoted context omitted.
And it even has the best time bound you can get for a comparison based sort. Most OS schedulers would use a heap/priority queue internally for timers, which makes sleep sort O(n log n).
wouldn't sleep sort be O(k), where k is the largest element to be sorted? (Assuming the clock and scheduler are precise enough to achieve the correct answer the first attempt).
Re: Trolling homework questions - sorting
#47Sigh, don't have an SO account but if I did, I would suggest this code which I call randsort -- #include #include #include int main(int argc, char *argv[]) { int i, ndx; double my_numbers[10]; double sorted_numbers[10]; uint16_t picked; for (i = 1; i = 0; i--) { if (( i == -1) || (sorted_numbers[i] > sorted_numbers[i+1])) { break; } } if (i == -1) { printf(" Sorted: \n"); for (i = 0; i
Nice. Is that O(e^n)? Out of curiosity, why do you divide the rand() by 100 before applying the mod?
Re: Trolling homework questions - sorting
#481. Generate all permutations of the input. 2. Return the permutation that is in order. 3. Profit!
1. Output all permutations of the input 2. There is no step 2. You've technically outputted the input list in order...somewhere
Re: Trolling homework questions - sorting
#49Sigh, don't have an SO account but if I did, I would suggest this code which I call randsort -- #include #include #include int main(int argc, char *argv[]) { int i, ndx; double my_numbers[10]; double sorted_numbers[10]; uint16_t picked; for (i = 1; i = 0; i--) { if (( i == -1) || (sorted_numbers[i] > sorted_numbers[i+1])) { break; } } if (i == -1) { printf(" Sorted: \n"); for (i = 0; i
And since `srand(time(NULL))` isn't ever called, it's deterministic, too!
Re: Trolling homework questions - sorting
#50Earlier quoted context omitted.
Nice. Is that O(e^n)? Out of curiosity, why do you divide the rand() by 100 before applying the mod?
No reason on the divide. Just because. That is probably a reasonable guess on the big O value. Clearly O(rand) is cheeky but in accurate. And the PRNG will walk the number space so it will eventually succeed, but computing how long it will take for 'n' numbers eludes my math reasoning skills.
Are you sure? What if there's an infinite amount of tries to get to a certain number? You can of course reason about the average case, but maybe the worst case (when there's an input number which is never found by the PRNG) does never halt.
> O(rand)
For sorting algorithms we usually compare in the number of input elements. You can reason about the average case where the numbers are found in average time so you can consider the number of iterations to find the correct number a constant (a very large constant but a constant nonetheless).