Showing posts with label Logic. Show all posts
Showing posts with label Logic. Show all posts

Monday, March 7, 2011

Short-circuiting logic. Which one would you rather maintain?

Which one would you rather maintain?

Explicit logic?
(
    !string.IsNullOrEmpty(letter_pressed)
    && x.CompanyName.StartsWith(letter_pressed)
)
||
string.IsNullOrEmpty(letter_pressed)

Implicit logic?
string.IsNullOrEmpty(letter_pressed)
||
x.CompanyName.StartsWith(letter_pressed)

Does lesser code always trumps the longer code?

Friday, September 17, 2010

Logic Puzzle


Two days ago Michael was nine years old. Next year he will be 12 years old. What day of the year is his birthday?


Answer: December 31

The base date is January 1 2010. Two days ago(December 30 2009), Michael's age is 9

January 1 2010 = 10
December 31 2009 = 10
December 30 2009 = 9

Michael's age of December 31 2010 is 11
Next year, 2011 (December 31 2011), Michael's age is 12



Source: http://wiki.answers.com/Q/Two_days_ago_Michael_was_nine_years_old._Next_year_he_will_be_12_years_old._What_day_of_the_year_is_his_birthday