Flipping a Coin

coin toss

I read The Adventures of Accordion Guy in the 21st Century regularly.  It’s not a book or anything, it’s just the blog of a really cool guy.

Anyway, in one of his recent blog entries, he talked about Flipping a Coin as a means to make a decision. I had never thought of the coin flip as a viable way of making a decision — and indeed this method is in line with that tradition by making the decision before the coin lands.

 

 

Getting out of the weeds

weeds

I’ve been struggling to ship a few of my ideas.  It turns out that I’m not alone; plenty of developers go through this problem.  The good ones get over it, and quickly. I’ve been analzying my behavior, what I spend my personal coding time on (at work I have no trouble shipping), and I’ve come to realize that I spend a lot of time in the weeds.

For software, being in the weeds means dealing with details that don’t matter to shipping. My newest example is fighting with JQuery AutoComplete functionality in my ASP.NET MVC application. Even though everything is correct, it simply won’t autocomplete.  I’ve spent the last three coding sessions futzing with it, only to not get anything done. 

I spent 6 hours trying to get autocomplete to work when I could have spent five minutes on a dropdownlist and been done with it.

All during that time, I was just thinking about how to get it to work, or what could have gone wrong (maybe my routes weren’t defined correctly? Maybe I don’t have the path correct for JQuery?) instead of just implementing the simplest feature and going about my business.  The entire rest of the application took about 2 hours to spec and write, so to spend 6 hours on a tiny polish feature is asinine.

So here’s what I’m going to do: Post my code here, see if there are any takers to figuring out where I went wrong, and move on.  I’ve got a deadline to meet, and I won’t meet it by staying in the weeds.

 

Castle Ravenloft: Fun for the Whole Family

I always wanted to get into Dungeons and Dragons. I never got the chance, and I never grew up around a group of people that played Dungeons and Dragons.  Even today I’d love to play D&D, but don’t have a group of friends that play it, and I’m a little nervous about playing with strangers (especially since I have no idea what’s going on). 

I think Wizards of the Coast heard my plight, because last September they came out with Castle Ravenloft, a Dungeons and Dragons boardgame.  

We're officially screwed. on Twitpic It may be a boardgame, but Monopoly it is not.  Ravenloft lets you and four of your closest friends brave the corridors of castle ravenloft in 13 separate adventures, each unique and harder than the last.  The mechanics of D & D are there, but greatly simplified. Gone are character creation, the dungeon master, and the plethora of dice that frequents D&D, and in their place are characters with various pick-and-choose powers, each player controlling monsters they spawn, and a single d20.

Its greatest strength is that it allows 5 newcomers to Dungeons and Dragons experience the essence of D&D without the (sometimes boring) overhead that goes with it.  It’s D&D for people that don’t have the 4+ hours for a campaign.  Its greatest weakness is that it is unfinished in some areas, and has the possibility of ambiguity when confronted with some adventures.  

I was able to sit down two people that didn’t even know what D&D was and a little over an hour later, they were begging to play another adventure.  During Thanksgiving break, I introduced it to my family, and they loved it, from my 17 year old brother to my mother.  

I lied. We're now screwed. on TwitpicI’m not alone in my assessment. Gabriel from Penny Arcade writes about his first experience with Castle Ravenloft:

Now you can take a table of people who have never rolled a D20 and have them playing an authentic feeling D&D adventure in the time it would take you to teach them Pandemic. There is no dungeon master required and no complex multi paged character sheets to try and learn. You decide who you want to be and then you are tossed in a dungeon and it’s time to start adventuring. The game does an incredible job of condensing the D&D experience into something you can just pick up and play.

If you’re looking for a co-operative boardgame for your next family visit, look no further than Castle Ravenloft.  

An exercise in TDD.

public class Program
    {
        static void Main(string[] args)
        {
            int sn = 123456782;
            int[] Digits;
            int AddedResult = 0;
            string s = sn.ToString();
            string sa = s.Substring(s.Length - 1, 1);

            int checkDigit = Convert.ToInt32(sn.ToString().Substring(s.Length - 1, 1)); //get the last digit.

            if (IsValidLength(sn))
            {

                sn = RemoveLastDigit(sn);
                Digits = ExtractEvenDigits(sn);
                Digits = DoubleDigits(Digits);
                AddedResult = AddedEvenDigits(Digits);
                AddedResult += AddOddDigits(sn);
                if (IsValidSN(AddedResult, checkDigit))
                {
                    Console.WriteLine("The number is valid");
                }
                else
                {
                    Console.WriteLine("The Number is not valid");
                }
            }
            else
            {
                Console.WriteLine("NotValidLength");
            }

            Char c = '2';
            Console.WriteLine("Character is {0}: ", Convert.ToInt32(c)); // returns 50
            string st = c.ToString();
            Console.WriteLine("string is {0}: ", Convert.ToInt32(st)); //returns 2;

            Console.Read();
            
        }

        public static bool IsValidSN(int AddedResult, int checkDigit)
        {
            return ((AddedResult % 10 == 0 && checkDigit == 0) || IsValidDifference(AddedResult, checkDigit));
            
        }

        public static bool IsValidDifference(int AddedResult, int checkDigit)
        {
            int nextHighestTens = AddedResult;
            while (nextHighestTens % 10 != 0)
            {
                nextHighestTens++;
            }
            return ((nextHighestTens - AddedResult) == checkDigit);
        }

        public static int AddOddDigits(int sn)
        {
            string s = sn.ToString();
            int i = 1;
            int addedResult = 0;
            foreach (char c in s)
            {
                if (i % 2 != 0)
                {
                    addedResult += Convert.ToInt32(c.ToString());
                }
                i++;
            }

            return addedResult;
        }

        public static int AddedEvenDigits(int[] Digits)
        {
            int addedEvenDigits = 0;
            string s = "";
            for (int i = 0; i < Digits.Length; i++) //extract each digit. For example 12 is extracted as 1 and 2
            {
                s += Digits[i].ToString();
            }
            for (int i = 0; i < s.Length; i++) //now add all extracted digits
            {
                addedEvenDigits += Convert.ToInt32(s[i].ToString());
            }
            return addedEvenDigits;
        }

        public static int[] DoubleDigits(int[] Digits)
        {
            int[] doubledDigits = new int[Digits.Count()];
            for (int i = 0; i < Digits.Length; i++)
            {
                doubledDigits[i] = Digits[i] * 2;
            }
            return doubledDigits;
        }

        public static int[] ExtractEvenDigits(int sn)
        {
            int[] EvenDigits = new int[4];
            string s = sn.ToString(); //12345678

            int j = 0;
            for (int i = 1; i < s.Length; i += 2)
            {
                EvenDigits[j] = Convert.ToInt32(s[i].ToString());
                j++;
            }
            
            return EvenDigits;
        }

        public static int RemoveLastDigit(int sn)
        {
            string s = sn.ToString();
            return Convert.ToInt32(s.Substring(0, s.Count() - 1));
        }
        public static bool IsValidLength(int sn)
        {
            return (sn > 9999999 && sn < 1000000000);
        }
    }

The Tests

    [TestFixture]
    public class SINTests
    {
        private int SinNumber = 123456782;

        [Test]
        public void TestValidNumber()
        {
            Assert.IsTrue(Program.IsValidLength(SinNumber));
        }
        
        [Test]
        public void TestRemoveLastDigit()
        {
            Assert.AreEqual(12345678, Program.RemoveLastDigit(SinNumber));
        }

        [Test]
        public void TestExtractEvenDigit()
        {
            int sn = 12345678;
            int[] array = new int[] { 2,4,6,8 };
            Assert.AreEqual(array, Program.ExtractEvenDigits(sn));
        }

        [Test]
        public void TestAddOddDigits()
        {
            int sn = 12345678;
            int result = 1 + 3 + 5 + 7;
            Assert.AreEqual(result, Program.AddOddDigits(sn));
        }
        [Test]
        public void TestDoubleEvenDigits()
        {
            int sn = 12345678;
            int[] original = new int[] { 2, 4, 6, 8 };
            int[] array = new int[] { 4, 8, 12, 16 };
            Assert.AreEqual(array, Program.DoubleDigits(original));
        }
        [Test]
        public void TestOddDigits()
        {
            int sn = 12345678;
            Assert.AreEqual(16, Program.AddOddDigits(sn));
        }

    }

Struggling to Ship: Prologue

About 21 days ago, I received The ShipIt Journal by Seth Godin, I had hoped this little journal would scare me into action. You see, I have a problem. I don’t ship.  Oh, I’ve released projects before; one a failure (over-time, and ended up being replaced a month later), and the jury is still out on the other; but I haven’t shipped any of my last three projects (Edit It, Stack Stats, A Blog Engine). They’re all in various stages of completion, from sketches on a piece of paper to actual prototypes written.  But they don’t exist yet. No one’s using them.  

In the eyes of myself and my peers, I’ve done nothing.  It’s a sobering thought that keeps me up at night.  In a profession where we’re measured by what we’ve released, the programmer that doesn’t ship is a charlatan.

The excuses are plenty and you’ve probably heard them all before.  Extra work, ballroom dancing, preparing for a wedding, you know, the usual. I have a precious few hours each night to spend, and it’s really easy for something to get in the way.

Or so my lizard brain keeps saying.

Perhaps deep down inside, I’m scared of my software sucking.  I want to make great software, but I know that once it’s out there, I’m vulnerable.  

The first step to conquering a fear is to face it.  This is me facing it.  Until these three projects finally ship, expect me to write about the process of trying to ship, the process of creating. If I fail, it will be public. If I succeed, it will be public. I have no idea what’s going to happen, only that I don’t have a lot of time to screw around. 

I want to make great software, but first I’ve actually got to make software.