Live data from Hacker News

Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

news.ycombinator.com

301–310 of 363 posts

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#301
post #152

Earlier quoted context omitted.

How well does the ability to write well correlate with the ability to articulate rules for writing well? The short answer is "pretty well." Usually I ask specifically for major comma rules, which I'd tend to define as: * Connecting independent clauses with a conjunction * As part of a list * To offset a word or phase at the start of a sentence. * Like parentheses (or, in the lingo, an appositive phrase). If they say,…

Known the rules is necessary but not sufficient for an A+ writer.

It's arguable (though I'm not sure it's actually true) that being able to write perfectly, and consistently, correctly is necessary for "an A+ writer".

But that is not the same thing as "knowing the rules". A writer may be able to write perfectly correctly without being able to enunciate any rules accurately at all.

Perhaps you play one or more sports. Could you write down accurate rules telling you how to hold and move a tennis racquet, or exactly how to flex the relevant joints when kicking a soccer ball? Of course writing is more deliberative than tennis or soccer, but a good writer isn't thinking about grammar and punctuation much more than a good sports player is thinking about joint angles and muscle groups.

Also, of course, there isn't universal agreement about what is and isn't correct, nor about what the best set of rules is for describing what's correct. For instance, if you compare the famous "Comprehensive Grammar of the English Language" by Quirk and Greenbaum, and the more recent "Cambridge Grammar of the English Language" by Huddleston and Pullum, you'll find that their analyses are sometimes very different. Totally different rules, even though they're describing substantially the same language.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#302
post #250

Earlier quoted context omitted.

I'd give half marks for this, because it optimizes (meaninglessly) for processes, at the risk of ending up with "rm: Too many arguments" in a directory tree containing a sufficiently large number of MP3 files.

xargs knows the maximum command line length, and will invoke the program more than once if necessary. One of the points of xargs is to break up invocations of a program into chunks of arguments that fit in one maximum length command line. xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is…

Well put

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#303

Earlier quoted context omitted.

That's a nice filter. (Of course, I'm a former mathematician as well.) Here's how I think of it: - the prior odds that you picked the double-headed coin are 1/999. - after seeing ten heads, the posterior odds that you picked the double-headed coin are (2^10)/999 - let's approximate this as 1. (Bayes' theorem usually gets expressed in terms of probabilities, but it's so much simpler in terms of odds.) - so it's roughl…

Why is it 1/999? Shouldn't it be 1/1000 since there are 1000 total coins?

Odds, not probability. Probability p means odds of p:(1-p) or, if you prefer writing it as a fraction, p/(1-p).

(Note 1. The odds of a thing are the ratio Pr(thing) : Pr(not thing). You can generalize this to any mutually exclusive and exhaustive set of things: the odds are the ratio of the probabilities. The fact that there may therefore be more than 2 such things is the reason why I prefer not to turn odds into fractions as above.)

(Note 2. Bayes' theorem is, as others have mentioned, much nicer when you work with odds rather than probabilities for your prior and posterior probabilities. If you're comfortable with logarithms, it's nicer still when you work with logarithms of odds. Now you're just adding the vector of log-likelihoods to the prior odds vector to get the posterior odds vector. Which is how I think of the question above, at least if I'm allowed to be sloppy and imprecise. You start with almost exactly 10 bits of prior prejudice for "fair" over "two-headed", then you get exactly 10 bits of evidence for "two-headed" over "fair", at which point those cancel out almost exactly so you should assign almost equal probabilities to those two possibilities.)

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#304

Earlier quoted context omitted.

An example that should show this approach is wrong: Suppose that the jar contains 500 double-head coins and 500 double-tail coins. You pull a coin from the jar, flip it 10 times, and get 10 heads. What is the probability it will come up heads next time?

That seems like a completely different problem to me, since all randomness is out of the system the moment you see the first flip.

OK, so now imagine that there are 1000000 double-headed coins, 1000000 double-tailed coins, and one fair coin. Now (1) there's still (potentially) randomness present, so it's not "completely different" from the original problem, but (2) the ignore-the-data approach gives an obviously wrong answer whereas using the data gives a believable answer.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#305
post #250

Earlier quoted context omitted.

I'd give half marks for this, because it optimizes (meaninglessly) for processes, at the risk of ending up with "rm: Too many arguments" in a directory tree containing a sufficiently large number of MP3 files.

xargs knows the maximum command line length, and will invoke the program more than once if necessary. One of the points of xargs is to break up invocations of a program into chunks of arguments that fit in one maximum length command line. xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is…

Well, how about that! It could be that I formed my opinion regarding xargs before it got that smart, or it could be the old Red Hat boxes on which I mostly learned my craft didn't bother compiling in that capability. Either way, I'm glad to know about it now, and thank you very kindly for pointing it out to me!

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#306

Earlier quoted context omitted.

I'd give half marks for this, because it optimizes (meaninglessly) for processes, at the risk of ending up with "rm: Too many arguments" in a directory tree containing a sufficiently large number of MP3 files.

zero marks for not understanding how xargs works

And a resounding "no hire" for privileging snark over substance.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#307

Earlier quoted context omitted.

The probability of which coin you have affects the probability of the next toss coming up heads, so having this knowledge is implicit in determining the solution.

That probability was determined the moment you picked the coin out of the jar. It makes no difference what you do to it after the pick. Hold it in your hand for a day, flip it 10 times, sit on it, whatever - the end result is that p(heads) for that particular coin has not changed . p(heads) will be either 0.5 for a real coin or 1.0 for the rigged one. The probability then comes down to what coin you picked at the sta…

I believe someone already presented this analogy to you, but I'm curious what your response is. Imagine the jar has only two coins, one always heads and one always tails. Choose a coin randomly, then flip it ten times. If you get ten heads, what is the probability that the next flip is heads?

According to the methodology you are advocating, the probability would be 50%, because you are only considering the initial probability of selecting a coin from the jar. But using the methodology I suggested in another comment, you would list out every possible outcome and conclude that there is a 100% chance of getting another heads.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#308
post #246
post #242

Earlier quoted context omitted.

I think you're incorrect because your conceptual model of what constitutes "probability" is incorrect for this type of problem. Try thinking about it in a more brute force way: imagine literally all possible outcomes of performing this experiment. In other words, create a list like this (each coin in the jar is numbered from 000 to 999 with 999 being the only biased coin, and coin flips are represented by 0 being hea…

Where is the unfair coin in your list? Without that you just get 50% heads. This method can definitely work to get the correct answer, but you have to account for all possibilities and weigh them by their probability.

Sorry, I edited coin #999 to be the biased coin.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#309
post #222

A nation's newest war ship is slowly disappearing. The ship's hull is made of Aluminium while its cannon bores are made of Stainless Steel. What is happening, why, and how do you stop it? Grad school chemistry/physics candicacy exam question, sure to generate colorful answers!

'Galvanic corrosion' and applying a non-metalic layer between the cannon/deck would be my first thought. Now I'm curious as to some of the more 'colorful answers'.

Yes indeed: two different metals in electrical contact through an electrolyte solution (sea water). One way to stop this is to use a sacrificial anode (where the oxidation occurs) made of Magnesium, although this would probably be unpractical in salt water. A colorful answer would be to replace the water with a fluid like 3M's Fluorinert and replace the air with a nitrogen atmosphere. But that would also be unpractical.

Re: Ask HN: What's your speciality, and what's your "FizzBuzz" equivalent?

#310
post #303

Earlier quoted context omitted.

Why is it 1/999? Shouldn't it be 1/1000 since there are 1000 total coins?

Odds, not probability. Probability p means odds of p:(1-p) or, if you prefer writing it as a fraction, p/(1-p). (Note 1. The odds of a thing are the ratio Pr(thing) : Pr(not thing). You can generalize this to any mutually exclusive and exhaustive set of things: the odds are the ratio of the probabilities. The fact that there may therefore be more than 2 such things is the reason why I prefer not to turn odds into fra…

That makes sense. I've never dealt with odds as a fraction before.
Post reply on HN