Monday 25 February 2013

Scraping a Pass

I received the results from one of my modules from last semester. I've already had my results from two other modules and I was looking at a possible first if everything else went well, realistically though I was probably looking to get a solid 2:1.

Then I got this grade back. Wow, it really ruined my day, I did a little better than expected on the assignment but bombed the test. Thankfully my assignment marks put me over the pass mark but just barely. I'm not happy at all with this grade.

Part of me wants to rage at the system. This was a level 6 module and a hard one at that. I'm currently taking the level 5 module that's supposed to build up to this one. This is the result of years of scheduling and re-scheduling the modules until this was the only fit, it's a major fault of the school, and one that they're rectifying next year, but I can't really blame the school. These things happen with teachers and awards coming and going over the years. However having taken these modules out of order I feel has undermined me, and everyone else on the award. I spent a lot of time trying to figure out the basics of the subject while being taught about the much, much more advanced applications and techniques. It was very frustrating.

All in all though I had plenty of help. I plagued my tutors during this module and I was just happy to have a working application to submit for my assignment in the end.

My study technique failed me tremendously for the exam. The module covered a lot of very complicated subjects over a a fairly short period of time. I didn't understand a lot of the basic stuff so I focused on those for my general study and then looked to the past exam papers for my more focused revision. I revised for two days solid and was fairly confident when I sat down to take the exam. However, the tutors went for a complete re-write on the exam this year and virtually nothing that had been on any of the past papers appeared on this exam. So I basically sat the exam almost completely unprepared.

Worst case scenario this bumps my degree down to a third class, which is horrifying. If I get solid firsts this semester I can maybe scrape a 2:1 which would be fine. So far I'm doing extremely well in two modules and not as well in the other two so I'll just have to wait and see how it goes but I'm optimistic but this is going to be hanging over my head for for the next two months, especially come exam time.

Monday 18 February 2013

Kata 3 - Magic Numbers

This kata comes from the website of one of my old lecturers. It was an interesting problems to tackle and there are a lot of different ways to approach it.

159 * 48 = 7632 contains each of the numbers 1-9. The program finds and displays all the other simple multiplications that also contain each of the numbers 1-9.

I started by creating an algorithm that generated a string containing all the numbers I wanted. This was exceptionally tricky to do. So my algorithm just starts counting from 123456789. Each number is checked that it contains only one of each number. Because I'm using only 9 digit numbers there isn't any need to validate any further than that. If the number is valid it's passed through to another checker that systematically changes the number into a simple multiplication equation. If the equation is valid I win.

The application takes a ridiculously long time to run. After completion I thought of a way to potentially half the run time but I didn't implement it because I've been obsessing about this for far too long.

This was done largely using TDD but I actually wrote the test in Obj C and then transferred the program to C# because of a memory problem I was having in XCode.


 static void Main(string[] args)  
     {  
       string equationString;  
       List<string> createdStrings = new List<string>();  
       //create an array of strings ///159 * 48 = 7632  
       for (int i = 123456789; i <= 987654321; i++){  
         equationString = i.ToString();  
         //validate strings with the checker  
         if (equationCharacterChecker(equationString)){  
           if (equationChecker(equationString)){  
             createdStrings.Add(equationString);  
           }  
         }  
       }  
     }  
     public static bool equationCharacterChecker(string equation) {  
       SortedSet<string> setOfEquationCharacters = new SortedSet<string>();  
       setOfEquationCharacters.Add("1"); setOfEquationCharacters.Add("2"); setOfEquationCharacters.Add("3");  
       setOfEquationCharacters.Add("4"); setOfEquationCharacters.Add("5"); setOfEquationCharacters.Add("6");  
       setOfEquationCharacters.Add("7"); setOfEquationCharacters.Add("8"); setOfEquationCharacters.Add("9");  
       string character;  
       for (int i = 0; i < equation.Count(); i++)  
       {  
         character = equation[i].ToString();  
         if (setOfEquationCharacters.Contains(character)){  
           setOfEquationCharacters.Remove(character);  
         } else {  
           return false;  
         }  
       }  
       return true;  
     }  
     //159 * 48 = 7632  
     public static bool equationChecker(string equation) {  
       int length = equation.Length;  
       for (int m = 1; m < equation.Length-2; m++){  
         for (int e = m+1; e < equation.Length-1; e++){  
           int multiplicand = Convert.ToInt32(equation.Substring(0, m));  
           int multiplier = Convert.ToInt32(equation.Substring(m, e-m));  
           int product = Convert.ToInt32(equation.Substring(e));  
           if (multiplicand * multiplier == product) {  
             Console.Write(multiplicand + " * " + multiplier + " = " + product + "\n");  
             return true;  
           }  
         }  
       }  
       return false;  
     }  

Monday 11 February 2013

Kata2 Binary Search

I did my second Kata this morning. I thought I'd tackle the binary search problem in following with http://codekata.pragprog.com
The idea here is that you have some huge, but sorted, list and you need to find a single element within that list as efficiently as possible. As lists grow in size just traversing through the list element by element can take a really long time for higher numbers.

The binary search solution basically means you start in the middle continually divide the list in half until you find your element. For huge lists it's excellent because it doesn't matter where the desired element is in the list, it will always find it quickly, one drawback though it will more often than not, take several searches to locate the element. So you need to weigh the efficiency lost against the efficiency gained. 

I'm quite proud of my attempt. I've tested it with a list of 50,000,000 integers and it never takes more than 26 searches to find any element. It'll support an array of any size and it should support any data type, but I'll need to test that at a later time. This is a recursive approach as it was the approach that comes most naturally to me. I'm going to have a look at an iterative at a later time.

This was developed using TDD, kind of. I had to test this from a few different directions at once, namely efficiency and accuracy. I couldn't work out a good way of testing for them both at the same time so I'm leaving what test code I did end up with out of this post.

 -(NSNumber*)binarySearch:(NSArray*)array forInt:(NSNumber*)anInt {  
   int numberOfSearches = 1;  
   int min = 0;  
   int max = array.count;  
   int searchingFor = [anInt integerValue];  
   int indexOfGuess = [array indexOfObject:[array objectAtIndex:(max + min) / 2]];  
   int guess = [[array objectAtIndex:indexOfGuess] integerValue];  
   NSLog(@"%d searches", numberOfSearches);  
   while (searchingFor != guess){  
     if (max - min <= 2){  
       return [NSNumber numberWithInt:-1];  
     }  
     if (searchingFor < guess){  
       max = indexOfGuess;  
     }  
     if (searchingFor > guess){  
       min = indexOfGuess;  
     }  
     guess = [[array objectAtIndex:(max + min) / 2] integerValue];  
     indexOfGuess = [array indexOfObject:[array objectAtIndex:(max + min) / 2]];  
     numberOfSearches++;  
     NSLog(@"%d searches", numberOfSearches);  
   }  
   return [NSNumber numberWithInt:indexOfGuess];  
 }  

Monday 4 February 2013

Bruising the Ego

I've learned quite about managing your ego when it comes to development. Every programmer has an ego, don't listen to what they might tell you otherwise. We all consider ourselves the poets of the computing world, thinking up beautifully elegant solutions to impossible problems.

I have a huge ego, I freely admit this. I don't handle criticism well and I'm a sore loser. I constantly aim to blow peoples minds with my genius and when that doesn't happen I fall into pits of self loathing and depression. It's a constant struggle for me.

Two of my apps have received bad reviews recently. I've got another app that I'd written for a client that seems to have given up on me all together, bought my app and immediately reporting a bug and requesting all sorts of changes. I fixed the bug right away and then spent a month re-writing the app. Now they won't respond to my emails, nor have they updated the app. My natural pessimism tells me that they've written me off all together, but I just don't know.

Being that two people have chosen to be vocal about their dislike of my apps, demographically I know that there are a percentage of others out there that feel the same way and have just chosen not to speak up. I spent a lot of time and energy on those apps and I'm very proud of them and their success so far. These were my ideas, my creations, my products and I want everyone to love them.

Now in my defence neither of these two users appear to have read the description of the apps before purchasing, which is their mistake. And the things they're complaining about are actually restrictions put in place by Apple, nothing to do with me. But these are still my app reviews. There is also information within the apps and on the app store that would allow a displeased customer to get in touch with me of there's a problem. But they haven't tried to reach me. I take some solace in knowing, from experience, that there are customers out there that just want to complain about anything that they can. You can't please everyone right, so why don't all those that like my apps post good reviews and make me feel better about it. I'm sat here looking at dissatisfied customers and poor reviews and I'm powerless to do anything about it.

I suppose that I could look at it as there's being an opposing percentage of those that are very happy with my app. There is one good review as well, so that's something.