logic

Jasmine expect logic (expect A OR B)

强颜欢笑 提交于 2019-11-30 04:16:55
I need to set the test to succeed if one of the two expectations is met: expect(mySpy.mostRecentCall.args[0]).toEqual(jasmine.any(Number)); expect(mySpy.mostRecentCall.args[0]).toEqual(false); I expected it to look like this: expect(mySpy.mostRecentCall.args[0]).toEqual(jasmine.any(Number)).or.toEqual(false); Is there anything I missed in the docs or do I have to write my own matcher? raina77ow Note: This solution contains syntax for versions prior to Jasmine v2.0. For more information on custom matchers now, see: https://jasmine.github.io/2.0/custom_matcher.html Matchers.js works with a

How to do cases with an inductive type in Coq

ε祈祈猫儿з 提交于 2019-11-30 03:08:06
问题 I wan to use the destruct tactic to prove a statement by cases. I have read a couple of examples online and I'm confused. Could someone explain it better? Here is a small example (there are other ways to solve it but try using destruct ): Inductive three := zero | one | two. Lemma has2b2: forall a:three, a<>zero /\ a<>one -> a=two. Now some examples online suggest doing the following: intros. destruct a. In which case I get: 3 subgoals H : zero <> zero /\ zero <> one _________________________

Distinguishing extra element from two arrays?

馋奶兔 提交于 2019-11-30 02:45:56
One of my friend was asked this question in an interview - You have given two integer arrays each of size 10. Both contains 9 equal elements (say 1 to 9) Only one element is different. How will you find the different element? What are different approaches you can take? One simple but lengthy approach would be - sort both arrays,go on comparing each element,on false comparison, you'll get your result. So what are different approaches for this? Specify logic as its expected in an interview. Not expecting a particular code in a specific language. Pseudo code will suffice. (Please submit one

Swift good coding practice: If statement with optional type Bool

*爱你&永不变心* 提交于 2019-11-30 02:35:00
问题 So I've been developing an app in Swift, and today I spent nearly an hour debugging a problem that turned out to be completely unexpected. It all resulted from the code below. if (hero.isAI) { //isAI is a Bool } The problem was that this if statement ALWAYS returned true. So I thought that maybe I was setting isAI to true somewhere but in the end I realized that I declared isAI as an optional type as shown below. var isAI: Bool! when it should have been var isAI: Bool This resulted in the if

How to parse a string of boolean logic in PHP

◇◆丶佛笑我妖孽 提交于 2019-11-30 02:22:14
I'm building a PHP class with a private member function that returns a string value such as: 'true && true || false' to a public member function. (This string is the result of some regex matching and property lookups.) What I'd like to do is have PHP parse the returned logic and have the aforementioned public function return whether the boolean result of the parsed logic is true or false. I tried eval(), but I get no output at all. I tried typecasting the boolean returns...but there's no way to typecast operators...hehe Any ideas? (Let me know if you need more information.) Just stumbled upon

Subtraction operation using only increment, loop, assign, zero

徘徊边缘 提交于 2019-11-30 02:16:40
I am trying to build up subtraction, addition, division, multiplication and other operations using only following ones: incr(x) - Once this function is called it will assign x + 1 to x assign(x, y) - This function will assign the value of y to x (x = y) zero(x) - This function will assign 0 to x (x = 0) loop X { } - operations written within brackets will be executed X times Using following rules it is straight forward to implement addition (add) like this: ADD (x, y) { loop X { y = incr (y) } return y } However, I'm struggling to implement subtraction . I think that all the other needed

Elegant way of reading a child property of an object

懵懂的女人 提交于 2019-11-29 22:17:14
Say you are trying to read this property var town = Staff.HomeAddress.Postcode.Town; Somewhere along the chain a null could exist. What would be the best way of reading Town? I have been experimenting with a couple of extension methods... public static T2 IfNotNull<T1, T2>(this T1 t, Func<T1, T2> fn) where T1 : class { return t != null ? fn(t) : default(T2); } var town = staff.HomeAddress.IfNotNull(x => x.Postcode.IfNotNull(y=> y.Town)); or public static T2 TryGet<T1, T2>(this T1 t, Func<T1, T2> fn) where T1 : class { if (t != null) { try { return fn(t); } catch{ } } return default(T2); } var

Find if every even bit is set to 0 using bitwise operators

痞子三分冷 提交于 2019-11-29 20:05:55
问题 I have a 32 bit int I can only access it 8 bits at a time. I need to find out if every even bit is set to 0 and return 0 if its true and 1 otherwise. So far I am going to split my int using shifts into 4, 8 bit variables. int a, b, c, d Now I am going to not them so now I will test if the bit is set to 1 instead of 0. To test if its set to 1 I will and them by 01010101. Now I dont know how to tell if every even bit is set to 1. I cannot use if/for/while loops or any conditional statements and

Higher-order unification

烂漫一生 提交于 2019-11-29 19:51:40
I'm working on a higher-order theorem prover, of which unification seems to be the most difficult subproblem. If Huet's algorithm is still considered state-of-the-art, does anyone have any links to explanations of it that are written to be understood by a programmer rather than a mathematician? Or even any examples of where it works and the usual first-order algorithm doesn't? Charles Stewart State of the art — yes, so far as I know all algorithms more or less take the same shape as Huet's (I follow theory of logic programming, although my expertise is tangential) provided you need full higher

Why if (n & -n) == n then n is a power of 2?

好久不见. 提交于 2019-11-29 18:43:41
Line 294 of java.util.Random source says if ((n & -n) == n) // i.e., n is a power of 2 // rest of the code Why is this? The description is not entirely accurate because (0 & -0) == 0 but 0 is not a power of two. A better way to say it is ((n & -n) == n) when n is a power of two, or the negative of a power of two, or zero. If n is a power of two, then n in binary is a single 1 followed by zeros. -n in two's complement is the inverse + 1 so the bits lines up thus n 0000100...000 -n 1111100...000 n & -n 0000100...000 To see why this work, consider two's complement as inverse + 1, -n == ~n + 1 n