In my post on how to care, I committed to start blogging more regularly, rather than sporadically. I began last week by spending an hour on my commute each day doing writing and research for the post I published Saturday. On Sunday I took a break from the entire internet. I plan to continue with that schedule. This coming week I’ll be eliminating some time-wasting websites from my life and replacing them with reviewing and acting on my next actions lists, including one for improving my blog. However, because I don’t want my blog to be primarily about blogging, or about my own personal growth, I’m not going to be publicly committing and reporting on my commitments here in the future. For those who care, they can see my current efforts on my public Daytum page.
Archive for the 'Uncategorized' Category
In my last post I mentioned that I was doing some practice with the binary search algorithm. I wanted to approach it with a slightly different mindset and see what kind of an algorithm that led to. So I decided to think of it as a walk. I would go “visit” locations in the array and see if I should turn right or left at each one. Doing this in C meant that I could do some crazy stuff with arrays – nothing I would do in shipping code, but fun to play with nevertheless. Here is what I came up with:
1 char ChopWalk(int value, int *array, int size, int *poffset) 2 { 3 int walkto = size / 2; 4 int direction = 0; 5 char found = 0; 6 7 if (walkto == size) 8 return 0; 9 10 if (value == array[walkto]) 11 { 12 found = 1; 13 direction = 0; 14 } 15 else 16 { 17 if (value > array[walkto]) 18 direction = +1; 19 else if (value < array[walkto]) 20 direction = -1; 21 found = ChopWalk(value, &array[walkto + direction], direction * (size / 2), poffset); 22 } 23 24 *poffset += walkto + direction; 25 26 return found; 27 } 28 29 int Chop(int value, int *array, int size) 30 { 31 int result = 0; 32 if (ChopWalk(value, array, size, &result)) 33 return result; 34 else 35 return -1; 36 }
So for the last couple of weeks I’ve been practicing the binary search algorithm, as laid out by Dave Thomas here. I’ve done both iterative and recursive variations in C++ and then in C. I love the value of katas for learning new languages and features. I know both C++ and C, but doing this simple problem in both programs allowed me to work on learning new areas in each. First, in C++ I took the time to use the standard template library (stl), because I’m not very familiar with it. I just used vectors in my tests, but it helped me to become familiar with the stl documentation and the concepts of iterators as used in the stl.
Next, I did the same variations in C. This was fun because C is so basic, and it’s been a long time since I coded in straight C. You don’t worry about concepts like objects or functional programming (though they may help you think about the problem). It gets you really close to the underlying physical model of computation. You’re forced to think more about how the memory is laid out, and how the algorithm takes advantage of that, whereas with C++ and the stl the whole problem and the solution are more abstract, just slightly more removed from hardware.
In addition to the languages themselves, it’s also a chance to practice my use of tools. I used the work to hone my skills in vim, to understand our build system at work more fully, and to consider testing frameworks.
One of my biggest frustrations with the Windows Mobile task application is that it synchronizes your completed tasks. After a while, this greatly outnumbers your active tasks, making the task app really slow. So I periodically move my completed tasks to a separate task folder (I like to have them around for searching). Alternatively, you could just delete them once a week or so. The following Outlook macro code can be used to move all the completed tasks in your tasks folder to the first tasks subfolder.
Dim fld As Folder Dim fldComplete As Folder Set fld = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks) Set fldComplete = fld.Folders.Item(1) For x = fld.Items.Count To 1 Step -1 Dim objTask As TaskItem Set objTask = fld.Items(x) If (objTask.Complete) Then objTask.Move fldComplete End If Next x