Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
A boolean value interview question (pixelstech.net)
2 points by sonic0002 on April 30, 2012 | hide | past | favorite | 3 comments


The solutions

   return  a ^  b ? c : a
   return  a == b ? a : c
Are expressing exactly the same idea- When A and B are identical, they will xor to 0, and otherwise something nonzero. Thus, xor can be thought of in general as a "!=" operator, provided booleans work like you'd expect in C.


Thank you for your remind. We have corrected the error. Yes, you are right, these two solutions have the same logic.


    (defn at_least_2 [a b c]
          (>= (count (filter true? [a b c])) 2))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: