Wednesday, July 24, 2019

Sudoku Checker

Sudoku Checker

Problem Statement

Given  a vector<vector<int>> of size 9*9. Check whether it is a valid Sudoku or not.  

Problem Solving 

  • I thought of starting with Iterators, writing Iterators for row iterator a column iterator and square iterator. 
  • This got me involved in a lot of Object Oriented Problem and how to implement == nicely. 
  • That got me stuck on the double dispatch problem and further after few frustrated days, I found a book, Effective C++. 
  • Now after having read that book and coming to chapter 2. I thought I had one solution and I restructured the Object modeling and yes it did work.
  • This whole thing took a lot of time. around 2 weeks now. 
  • Then I peeked in the book and answer in the book seemed very short and concise.
  • Hah.. I think I created a complex solution to a simpler problem. 
  • The solution in the book is very clean, basically instead of iterators and their complex hierarchy and initialization on objects this solution has a function that takes in a row_start , row_end, col_start, col_end and the original matrix. 
  • Instantly I can see how easy it would be, the signature of the function would reveal it's algorithm. 
  • But okay. I think this was a good learning. 
  • The solution would be iterate all rows cols and sub matrices and check if anyone has duplicates. 
  • checking for duplicates can be done via a set or bit vector. 

 Learning

  • Multiple learning here. 
  • First I think I should fork my problem solving skill from OO modelling skills. 
  • So I have picked up a new book Programming Pearls. 
  • All other learning were related to c++ and it's OO nature. 
  • This took a lot of time and broke the rhythm. 
  • I still do not know when is the time to give up and look in the book. 

No comments:

Post a Comment