Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using boolean logic to deal with dates

Using boolean logic to deal with dates

The unexpected application of Karnaugh maps in a Rails project

Irina Bednova

October 30, 2014
Tweet

Other Decks in Programming

Transcript

  1. The problem • Date could be in the mm/dd/yyyy format

    • Date could be in any format recognisable by Date.parse
  2. The problem • Date could be in the mm/dd/yyyy format

    • Date could be in any format recognisable by Date.parse • Except the dd/mm/yyyy format
  3. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 0 1 1 1 0 0 1 0 1 X 1 1 0 1 1 1
  4. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 1 0 1 1 1 0 0 1 0 1 X 1 1 0 1 1 1
  5. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 1 0 1 1 0 1 0 0 1 0 1 X 1 1 0 1 1 1
  6. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 1 1 1
  7. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 X 1 1 1
  8. month_day_year generic_parse day_month_year result 0 0 0 0 0 0

    1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 X 1 1 1 1
  9. 0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  10. 0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  11. 0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  12. 0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  13. month_day_year 0 X 0 1 1 X 1 X generic_parse

    * day_month_year month_day_year 0 00 01 11 10 1
  14. month_day_year ∨ ¬generic_parse ∧ day_month_year 0 X 0 1 1

    X 1 X generic_parse * day_month_year month_day_year 0 00 01 11 10 1
  15. month_day_year ∨ ¬generic_parse ∧ day_month_year ∨ generic_parse ∧ ¬day_month_year 0

    X 0 1 1 X 1 X generic_parse * day_month_year month_day_year 0 00 01 11 10 1
  16. ((month_day_year ? 1 : 0) + ((day_month_year ? 1 :

    0) ^ (generic_parse ? 1 : 0)) == 0) month_day_year || generic_parse