Live data from Hacker News

Trolling homework questions - sorting

codegolf.stackexchange.com

41–50 of 51 posts

Re: Trolling homework questions - sorting

#41

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.…

I downvoted because I disagree with asking for explanations of downvotes. I think the practice is bad for HN.

Re: Trolling homework questions - sorting

#42

Earlier 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 ".

I've looked quite hard for obfuscated Python (and there are a couple of other answers to this question using it). It's always been much more readable than that perl.

Re: Trolling homework questions - sorting

#43

No 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

I wrote a version in Go http://codegolf.stackexchange.com/a/16468/11452

Re: Trolling homework questions - sorting

#44
post #41

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.…

I downvoted because I disagree with asking for explanations of downvotes. I think the practice is bad for HN.

Makes sense. But for folks who are downvoted it can be helpful to know some context, I've noticed that when you ask for feedback you get it and when you don't you end up confused and a bit pissed which is toxic over time.

I was -1 when I edited the comment to include it and +22 now and a lot less confused.

Re: Trolling homework questions - sorting

#45
post #30

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.…

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…

Yep, this context helps a lot, I don't know enough about codegolf, thanks!

Re: Trolling homework questions - sorting

#46

Earlier 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).

You could keep it linear by first going through the list to find the max, then scaling down.

Re: Trolling homework questions - sorting

#47

Sigh, 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?

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.

Re: Trolling homework questions - sorting

#48
post #3

1. 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

I love this answer and it's probably worth creating an account for you to post it.

Re: Trolling homework questions - sorting

#49
post #40

Sigh, 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!

Is that the case for all platforms and C libraries? Also, isn't seeding with the current time a way to guarantee deterministic behavior? An attacker of such an algorithm probably knows what time it is, and users probably don't expect all invocations within a given second to return the same results.

Re: Trolling homework questions - sorting

#50

Earlier 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.

> the PRNG will walk the number space

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).

Post reply on HN