Live data from Hacker News

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

news.ycombinator.com

241–250 of 363 posts

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

#241
post #198

Earlier quoted context omitted.

"If you flipped 10 heads in a row the probability of the coin you have being the double heads coin increases dramatically..." I disagree. The coin is the coin. It didn't magically transport itself or change state after flipping it 10, 100, or a billion times. Lets change the puzzle to the simplest state: you pull a coin from the 1000-coin jar and flip it just once. What's the probability of heads? This is why roulett…

The coin is the coin, but your information about the coin has changed. Probability is a fact about you, not a fact about the coin. Here is perhaps a more visceral example: On any given day, your car has a 10% chance of having blown a wheel the previous night. If it has blown a wheel, every bump will feel jarring. If it hasn't blown a wheel, any given bump will feel jarring with 10% probability. You drive over a hundr…

So, I think that tge question is ambiguous, and a little more direction could clear it up. If you want to know the probability, taking into account the 10 heads results thus far, I would tell the interviewee, "I am going to do this process repeatedly (picking a coin and flipping 10 times), and I'm going to keep track of what percentage do the all one side thing. What will that percentage be approximately?".

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

#242
post #169

Earlier quoted context omitted.

You didn't read it wrong, but you probably did fail the test ;-) There is no gotcha in the question, it's just a math problem that you either do or do not know how to solve. This isn't really about intelligence as much as it is about whether you have taken a course on probability. If you flipped 10 heads in a row the probability of the coin you have being the double heads coin increases dramatically, so you have to t…

"If you flipped 10 heads in a row the probability of the coin you have being the double heads coin increases dramatically..." I disagree. The coin is the coin. It didn't magically transport itself or change state after flipping it 10, 100, or a billion times. Lets change the puzzle to the simplest state: you pull a coin from the 1000-coin jar and flip it just once. What's the probability of heads? This is why roulett…

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 heads and 1 being tails):

    Picked fair coin #000, flipped 00000000000 (eleven flips)
    Picked fair coin #000, flipped 00000000001
    Picked fair coin #000, flipped 00000000010 ...
    Picked fair coin #000, flipped 11111111111
    ....
    Picked biased coin #999, flipped 11111111111
Now select all of the lines above where the first ten flips are heads. Of these outcomes, how many have an eleventh flip of heads and how many have an eleventh flip of tails? Unless my idea of probability is flawed, this should be the same answer that the mathematicians in this thread are providing, so something right around 75% heads.

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

#243
post #198

Earlier quoted context omitted.

The coin is the coin, but your information about the coin has changed. Probability is a fact about you, not a fact about the coin. Here is perhaps a more visceral example: On any given day, your car has a 10% chance of having blown a wheel the previous night. If it has blown a wheel, every bump will feel jarring. If it hasn't blown a wheel, any given bump will feel jarring with 10% probability. You drive over a hundr…

Probability is a fact about you, not a fact about the coin. Huh? It's a coin . You flip it. It has no knowledge of the past and no idea about the future. It lands and it's either heads 50% of the time and tails 50% of the time. It's all about the coin and nothing about what you've observed in the last N trials. That's the simple logic that the OP is trying to see if you understand.

It's really interesting to watch this thread. I'm not saying that you should simply trust what the other commenters are saying, but the user crntaylor is the one that originally posted the question, and his solution is that the likelihood of the next flip being heads is 75%

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

#244
post #198

Earlier quoted context omitted.

The coin is the coin, but your information about the coin has changed. Probability is a fact about you, not a fact about the coin. Here is perhaps a more visceral example: On any given day, your car has a 10% chance of having blown a wheel the previous night. If it has blown a wheel, every bump will feel jarring. If it hasn't blown a wheel, any given bump will feel jarring with 10% probability. You drive over a hundr…

Probability is a fact about you, not a fact about the coin. Huh? It's a coin . You flip it. It has no knowledge of the past and no idea about the future. It lands and it's either heads 50% of the time and tails 50% of the time. It's all about the coin and nothing about what you've observed in the last N trials. That's the simple logic that the OP is trying to see if you understand.

Likewise, a tire has no knowledge of the past or future. It will transfer a bump from the road to you following the laws of physics, depending on whether it is functioning properly, represented by a probability.

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

#245

I'm a software developer, but the code I work does a lot of DB access. I always ask a "two joins and an aggregate question." Given three tables: authors books sales ---------- ---------- ---------- id id id name author_id book_id title date price find the total sales by author in November 2013. The result set should have two columns: author's name and their total sales.

My solution:

    SELECT authors.name, SUM(sales.price) FROM authors
      INNER JOIN books ON authors.id = books.author_id
      INNER JOIN sales ON books.id = sales.book_id
      WHERE sales.date >= Nov 2013 AND sales.date 
Although a coworker pointed out that inner joins would drop authors who haven't written books, and books that have no sales. If you want to include all of those, then use LEFT OUTER JOIN instead of INNER JOINs.

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

#246
post #242

Earlier quoted context omitted.

"If you flipped 10 heads in a row the probability of the coin you have being the double heads coin increases dramatically..." I disagree. The coin is the coin. It didn't magically transport itself or change state after flipping it 10, 100, or a billion times. Lets change the puzzle to the simplest state: you pull a coin from the 1000-coin jar and flip it just once. What's the probability of heads? This is why roulett…

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.

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

#247
post #198

Earlier quoted context omitted.

The coin is the coin, but your information about the coin has changed. Probability is a fact about you, not a fact about the coin. Here is perhaps a more visceral example: On any given day, your car has a 10% chance of having blown a wheel the previous night. If it has blown a wheel, every bump will feel jarring. If it hasn't blown a wheel, any given bump will feel jarring with 10% probability. You drive over a hundr…

So, I think that tge question is ambiguous, and a little more direction could clear it up. If you want to know the probability, taking into account the 10 heads results thus far, I would tell the interviewee, "I am going to do this process repeatedly (picking a coin and flipping 10 times), and I'm going to keep track of what percentage do the all one side thing. What will that percentage be approximately?".

That's not ambiguous if the applicant has taken a basic college statistics course, which is what the question is intended to determine. The term "probability" has more precise definitions in mathematics than in everyday language.

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

#248
post #187

Earlier quoted context omitted.

The probability of heads is 0.999*0.5 + 0.001*1 = 0.5005 The important thing is that as you observe heads from the coin, you learn something about the coin. As you observe more heads it is less likely to be a fair coin and more likely to be the coin with double heads. This doesn't change anything about the coin, but it changes something about what you know about the coin. See here for the correct answer: https://news…

Since the question simply asked what p(heads) was on the next flip, it seems our answers match. Thanks!

Not at all. The answer is about 0.75, and stated in the answer jules linked to.

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

#249
Hi - vfx/games programmer here - I've never been given FizzBuzz - although similar problems generally appear on any programming test I've seen (reverse a string, find loop in linked list etc.) the better ones I've seen a couple of times now are:

"How do you reflect a vector about a normal? Name some uses."

"What is the dot product? Name some uses."

These aren't just filters but an experienced real-time rendering or physics programmer is going to have quite a lot to say about the practical implementations of either in particular situations and what hardware features are available to help you with them...

if there is a good theoretical understanding then they can talk a lot about what the dot product is, its relationship to matrix multiplication and tensor inner products in general. they can explain multiple approaches to the problem of reflecting the vector and derive their solutions from first principles instead of just repeating remembered knowledge.

there are lots of little domain specific bits of knowledge as well e.g. the reflection question can lead to discussion of the Blinn half angle approximation - why it works and why its no longer a particularly valid optimisation on today's hardware - the dot product question can lead to discussion of how to efficiently handle solving a quadratic equation on the GPU

really i expect a decent (games/vfx) programmer to run out of time whilst elaborating on answers to either of these questions (although not to the detriment of the rest of the test of course...).

the best filter is a strong demo though imo. never met a bad programmer who has a decent demo... none of the average, lazy or bad programmers i've worked with have one that i couldn't have crapped out in the evening before an interview.

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

#250

Earlier quoted context omitted.

find path -iname "*.mp3" -print0 | xargs -0 rm -fv

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 /bin/echo) one or more times with any initial-
  arguments followed by items read from standard input.

  --max-chars=max-chars
  -s max-chars
         Use at most max-chars characters per command line, including the
         command  and  initial-arguments and the terminating nulls at the
         ends of the argument strings.  The largest allowed value is sys‐
         tem-dependent,  and  is  calculated as the argument length limit
         for exec, less the size of your environment, less 2048 bytes  of
         headroom.   If this value is more than 128KiB, 128Kib is used as
         the default value; otherwise, the default value is the  maximum.
         1KiB is 1024 bytes.
Post reply on HN