System.Blog.Martens.Ben

The Tech Blog of Ben Martens

Browse by Tags

Tagged Content List
  • Blog Post: Brain Teaser #3 Answer

    If you haven't read the question yet, you can read it here . The answer for this lies in the C# specification. Specifically, read section 8.13. There are two different ways you can use a using statement and in this case we are interested in the second way. The key words from the spec are "in this...
  • Blog Post: Brain Teaser #3

    This brain teaser also comes courtesy of Simeon Cran. What will the following code output? When you think you know, copy the code into Foo.cs and run “csc Foo.cs” and then run “Foo.exe”. Did it output what you expected? The brain teaser is to come up with the correct explanation...
  • Blog Post: Brain Teaser #2 Answer

    Have read the question yet? Read it here . The problem is pretty simple if you have 00111 (where all the bits after the first 1 are also 1’s.) You shift right, run the NOT operator, and then AND that result with the original. For example: ORIGINAL = 00111 SHIFT RIGHT = 00011 NOT = 11100 ...
  • Blog Post: Brain Teaser #2

    This brain teaser comes courtesy of a co-worker named Simeon Cran. Using C# and no branches, and no method calls , no allocations, and no unsafe code , write a method that takes a ulong and clears all the bits in it except the highest bit that was set. Use as few operations as possible. e.g.: 0 ->...
  • Blog Post: Brain Teaser Answer

    There was a lot of extra information in that brain teaser . All you really needed was these two sentences: Clearly 41 runs * 1210 feet = 49610 feet. The watch incorrectly said that I had skied 20,100 but had the correct number of runs. So if I had looked after one run, the watch would have said 1210...
  • Blog Post: Brain Teaser

    During a recent Hope on the Slopes 24-hour ACS skiing fundraiser, I used my watch to track vertical feet throughout the day. The watch isn't perfectly calibrated, but it's reasonably accurate. The watch counts a run any time you make a vertical change of at least 100 feet (so when you ride up the lift...
Page 1 of 1 (6 items)