Live data from Hacker News

Which answer in this list is the correct answer to this question? (2017)

math.stackexchange.com

51–60 of 137 posts

Re: Which answer in this list is the correct answer to this question? (2017)

#51

Similar one I enjoyed in the Naive Bayes article from yesterday https://blog.floydhub.com/naive-bayes-for-machine-learning/ Multiple Choice: If you choose an answer to this question at random, what is the chance you will be correct? A) 25% B) 50% C) 60% D) 25%

What's the correct answer?

Re: Which answer in this list is the correct answer to this question? (2017)

#52
post #43

Here is a single python statement that solves the problem: print([ q for q in itertools.product((True, False), repeat=6) if q == ( all(q[1:]), # 1. All of the below. not any(q[2:]), # 2. None of the below. all(q[:2]), # 3. All of the above. any(q[:3]), # 4. One of the above. not any(q[:4]), # 5. None of the above. not any(q[:5]), # 6. None of the above. ) ]) https://gist.github.com/lovasoa/f2b4ed93e755bf4172583d28f20…

Slight variation:

    import itertools

    def below(n):
        return slice(n+1, None)

    def above(n):
        return slice(None, n)

    print([
        q for q in itertools.product((True, False), repeat=6)
        if q == tuple(
            f(i) for i, f in enumerate([
                lambda n: all(q[below(n)]),  # 1. All of the below.
                lambda n: not any(q[below(n)]),  # 2. None of the below.
                lambda n: all(q[above(n)]),  # 3. All of the above.
                lambda n: any(q[above(n)]),  # 4. One of the above.
                lambda n: not any(q[above(n)]),  # 5. None of the above.
                lambda n: not any(q[above(n)]),  # 6. None of the above.
            ])
        )
    ])

Re: Which answer in this list is the correct answer to this question? (2017)

#54
post #43

Here is a single python statement that solves the problem: print([ q for q in itertools.product((True, False), repeat=6) if q == ( all(q[1:]), # 1. All of the below. not any(q[2:]), # 2. None of the below. all(q[:2]), # 3. All of the above. any(q[:3]), # 4. One of the above. not any(q[:4]), # 5. None of the above. not any(q[:5]), # 6. None of the above. ) ]) https://gist.github.com/lovasoa/f2b4ed93e755bf4172583d28f20…

Run it online here: https://onlinegdb.com/rkZhWVniH

Thanks for posting this, because I'm a Python n00b and I had no idea what this line was doing:

itertools.product((True, False), repeat=6)

The site made it easy for me to spend 30 seconds figuring it out. My interpretation is that that line generates what I'll call a truth table (not sure if that's what it formally is) then brute force searches for rows that satisfy all of the listed constraints.

I'd also hazard that the fact that there's only one answer is engineered into the question and not a natural product of this search.

Re: Which answer in this list is the correct answer to this question? (2017)

#56
post #51

Similar one I enjoyed in the Naive Bayes article from yesterday https://blog.floydhub.com/naive-bayes-for-machine-learning/ Multiple Choice: If you choose an answer to this question at random, what is the chance you will be correct? A) 25% B) 50% C) 60% D) 25%

What's the correct answer?

0%

Re: Which answer in this list is the correct answer to this question? (2017)

#57
post #43

Here is a single python statement that solves the problem: print([ q for q in itertools.product((True, False), repeat=6) if q == ( all(q[1:]), # 1. All of the below. not any(q[2:]), # 2. None of the below. all(q[:2]), # 3. All of the above. any(q[:3]), # 4. One of the above. not any(q[:4]), # 5. None of the above. not any(q[:5]), # 6. None of the above. ) ]) https://gist.github.com/lovasoa/f2b4ed93e755bf4172583d28f20…

A less clever solution, using the wonderful z3

  import z3
  answers = [z3.Bool(f"answer{i}") for i in range(1,7)]
  implications = [
      z3.And(answers[1:]),         # All of the below
      z3.Not(z3.Or(answers[2:])),  # None of the below
      z3.And(answers[:2]),         # All of the above
      z3.Or(answers[:3]),          # Any of the above
      z3.Not(z3.Or(answers[:4])),  # None of the above
      z3.Not(z3.Or(answers[:5]))]  # None of the above
  constraints = [z3.Implies(ans, impl) for ans,impl in zip(answers, implications)]
  z3.solve(constraints)

Re: Which answer in this list is the correct answer to this question? (2017)

#58
x is unknown, T=True, F=False, ttt = x or x or x, otherwise all connected with "and"

By definition:

  #1: xTTTTT
  #2: xxFFFF
  #3: TTxxxx
  #4: tttxxx
  #5: FFFFxx
  #6: FFFFFx
Begin evaluation from 6.

Let's assume 6 is T so we have xxxxxT. In that case 5 need to be F. But if 5 is F, then any from [1,2,3,4] need to be T. But if any from [1,2,3,4] is T then 6 cannot be T. Thus 6 cannot be T, so it is F if correct answer exists.

Now we have: xxxxxF

Next, we try to set 5 to T: xxxxTF. 1 cannot be T, 2 cannot be T, since their last elements are different (TT!=TF, FF!=TF), 3 cannot be T because it requires 1 and 2 be both T , 4 cannot be T because (1 or 2 or 3) are F.

So we have: FFFFTF

Thus only 5 is True.

Re: Which answer in this list is the correct answer to this question? (2017)

#60
post #23
post #8

Earlier quoted context omitted.

Using the clpb library [0]: solution([A1,A2,A3,A4,A5,A6]) :- sat(A1 =:= A2*A3*A4*A5*A6), sat(A2 =:= ~(A3+A4+A5+A6)), sat(A3 =:= A1*A2), sat(A4 =:= A1+A2+A3), sat(A5 =:= ~(A1+A2+A3+A4)), sat(A6 =:= ~(A1+A2+A3+A4+A5)). [0] https://www.metalevel.at/prolog/puzzles

Alternatively using z3 [0]: (declare-const a1 Bool) (declare-const a2 Bool) (declare-const a3 Bool) (declare-const a4 Bool) (declare-const a5 Bool) (declare-const a6 Bool) (assert (= a1 (and a2 (and a3 (and a4 (and a5 a6)))))) (assert (= a2 (not (or a3 (or a4 (or a5 a6)))))) (assert (= a3 (and a1 a2))) (assert (= a4 (or a1 (or a2 a3)))) (assert (= a5 (not (or a1 (or a2 (or a3 a4)))))) (assert (= a6 (not (or a1 (or a2…

I posted a solution using the python z3 library, which might be easier to use for people used to python, here: https://news.ycombinator.com/item?id=21545143
Post reply on HN