Quiz: can you count how many combinations …

Here’s a combinatorics quiz: If you have 2 ordered lists (lengths N, M), how many ways can they be interleaved into a single list while still preserving the partial ordering from the original lists? So if the lists were:List 1: A,BList 2: X,YThe following would be valid: A,B,X,Y A,X,Y,B X,Y,A,B A,X,B,Y But ‘ yxab’ would…

RTS Battle simulation with IronPython

I used Python to simulate Age of Empires archer battles.  I wanted to be able to answer questions like: If 12 archers attack 10 archers, what will the margin of victory be? If two armies of the same size attack each other, how do different strategies affect the outcome? This also led to some practical…

"This statement is false"

Saying phrases like “This statement is false” does mean you’ve found some fatal flaw in logic itself and it does not make you sound smart. It makes you sound like somebody who doesn’t know the difference between syntax and semantics. The real issue…In order for a statement to have meaning, it must be well defined….

Trivia about the [Conditional] attribute

The System.Diagnostics.Conditional attribute has been on blog-todo list for a while, and I’m finally getting around to it.  For the quiz-loving folks, here you go: Quiz: First, some lingo: I’ll say a Conditional Function is a function with a Conditional attribute on it. The conditional function is active (within the scope of a symbol) if…

Quiz: What runs before Main()?

Quiz: What managed code runs before managed Main() in your program startup path?     Answers: I note “managed code”, because obviously the CLR startup code gets executed, as does other native startup code. 1) The common answer is static constructors referenced from Main(). 2) The less common answer would be managed code in the…

Answer to Number puzzle

Here are answers + commentary to the number puzzle I posted yesterday, which was, fill in the digits:    ABC  +DEF   GHI   OR prove it’s impossible.   I originally moderated the answers but have now gone back and published them all. My conclusion is that the folks who read this blog are way smarter than I am. So…

Number puzzle

Here’s a little number puzzle quiz. Fill in the digits:    ABC  +DEF   GHI Where each letter represents a unique digit between 1 and 9, such that all digits are used exactly once. OR (and this is where it gets interesting…) prove that it’s impossible to fill in such digits. (And, “it’s too hard” is not a…

"Why are you picking off the olives?"

Somebody asked me this at lunch. I had gotten a pizza with olives, and was picking off the olives. I figured that would make a cute good interview question. So consider it a pop-quiz: why would somebody order a pizza with olives and then pick off the olives?     Spoiler:     The simple…

Viewing types with Reflection-Only

It’s natural for a tool to use Reflection-Only loading to load an assembly and view the types in it.  For example, I used this in my pdb2xml tool. However, I missed an important detail that I wanted to warn you about after getting it wrong myself. Consider the following snippet which will print all the…

Pop quiz: Who wins in finally vs. return?:

Question 1) What’s the return value from this C# function: static int Test() { int val = 1; try { return val; } finally { val = 2; } } Question 2)  What about this (using a static instead of  local) static int s_val; static int Test() { s_val = 1; try { return s_val;…