Solve puzzle with code

Here is a quite common programming interview puzzle – You have two buckets. A 3 gallon bucket and a 5 gallon bucket. Buckets are not marked or graduated. You are to fetch 4 gallon of water in a single trip to the river. How will you do it?
Obviousy, this question is asked by changing the capacities of the two buckets and the amount of water to be fetched.
Your mission, should you choose to accept it, is to write a program to solve this puzzle in a generic way. Your program should take 3 inputs – capacities of the two buckets and the amount of water to be fetched. After solving the puzzle, your program must write out the solution step-by-step. You can use any programming language, any platform, any programming technique to write the program. Use whatever you like – C#, VB, C, C++, Java, Ruby, Python, F#, Boo, Javascript or any other language of your choice. Use design patterns, TDD, BDD, MVVM, Linq or whatever. Make it blazing fast, exploit multiple cores, use artificial intelligence. Go nuts! If you want to write the whole program in T-sql, powershell script or a batch script, go ahead. Heck ! you can even do it with regular expressions, if that your thing!
Your mission, should you choose to accept it, is to write a program to solve this common programming interview puzzle in a generic way.
The puzzle goes like this – You have two buckets. A 3 gallon bucket and a 5 gallon bucket. Buckets are not marked or graduated. You are to fetch 4 gallons of water in a single trip to the river. How will you do it?
tommylees-flickr-buckets
Photo Credit : http://www.flickr.com/photos/71256895@N00/3688461774/sizes/l/in/photostream/

Your program should take 3 inputs – capacities of the two buckets and the amount of water to be fetched. After solving the puzzle, your program must write out the solution step-by-step. You can use any language, any platform and any technique to write the program. Use whatever you like – C#, VB, C, C++, Java, Ruby, Python, F#, Boo, Javascript, powershell script or any other language of your choice. Use design patterns, TDD, BDD, MVVM, Linq or whatever. Make it blazing fast, exploit multiple cores, use artificial intelligence. Go nuts! If you want to write the whole program in T-sql, go ahead. Heck ! you can even do it with regular expressions, if that your thing!

Windigo 1.1 Released

windigo-samsungWindigo is a windows phone app to access your diigo account on windows phone 7.

Create, edit and search diigo bookmarks. Slick, to-the-point interface. Browse and search public bookmarks of other diigo users. Tap on the bookmark for details, including tags. Tap on any tag to narrow your search. Trial version is available.

Windigo 1.1 is out on the windows phone marketplace now.  Highlights of this update :

– Last SearchScope used is now persistent
– Fixed search when a search term is picked from suggested words
– Problem report now includes system info
– Handle crash on navigating from main page
– Fixed feature tracking for analytics
  • Last SearchScope used is now persistent
  • Fixed search when a search term is picked from suggested words
  • Problem report now includes system info
  • Handle crash on navigating from main page
  • Fixed feature tracking for analytics

Call For Windigo Beta Testers

Windigo is a windows phone app. It lets you access your Diigo bookmarks on the go from your windows phone. You can browse, edit and create new bookmarks. Search your and other’s (public) bookmarks. Drill-down using tags. Share your bookmarks with your friends.

I have completed developing this app and I would like to get it in the hands of a few more people to get some additional feedback before I submit it in windows phone marketplace. If you have a windows phone and a windows live id, you can help with this. Your phone does not need to be a developer (unlocked) phone.

If you are interested, contact me.

Here is what I will do for you :

  • I will acknowledge your role in preparing Windigo for release.
  • Your name and a link to your website will appear in the credits page for Windigo.
  • I will return the favor.
  • ChildWindow Positioning

    Silverlight ChildWindow is centered over the parent control. I have extended ChildWindow to open it at a specific position.

    Positioned ChildWindow
    Positioned ChildWindow

    Here is a live demo : childwindow-positioning-demo

    And here is the code :

    public partial class ChildWindowEx : ChildWindow
    {
    
        Point _pt = new Point(0,0);
    
        public ChildWindowEx()
        {
            InitializeComponent();
        }
    
        public ChildWindowEx(Point pt) : this()
        {
            _pt = pt;            
        }
    
        protected override Size ArrangeOverride(Size finalSize)
        {            
            Grid grid = Utils.FindChild(this, "ContentRoot");
    
            if (grid != null)
            {               
                grid.Arrange(new Rect(_pt.X, _pt.Y, grid.DesiredSize.Width, grid.DesiredSize.Height));
                return finalSize;
            }
    
            return base.ArrangeOverride(finalSize);
        }
    }

    Visual Studio 2010 Solution : download

    Remove ListBoxItem Highlighting

    A Silverlight/Wpf ListBoxItem is highlighted when selected or when the mouse hovers over it.

    I need to display a list of items that are not highlighted when selected. This is a common scenario when displaying an inactive list for simply listing out some information.

    ListBoxItem’s default template can be easily inspected and modified using Expression Blend – Select a ListBoxItem in Objects and Timeline pane, Right click and select Edit template > Edit a Copy. Name you template and save it at the scope of your choice.

    This will create a copy of the template and allow you to modify it. Switch to the xaml view. Locate the VisualStates of MouseOver, Selected and Focused, and blank them out –

    de-highlighted-xaml

    The style is applied to the ListBoxItems using ItemContainerStyle –

    applying-style-to-listboxitems

    Here is the xaml style for the ListBoxItem –

    After the style is applied, the ListBoxItems are not highlighted when selected or focused. Here is a live demo of a ListBox that does not highlight when items are selected : remove-listboxitem-hlighting-demo

    Sideload Windows Phone

    1. Create your AppHub account here – http://create.msdn.com. Registration walk through is here.

    2. Unlock your phone – using PhoneReg.exe (usually) located here – “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\Phone Registration\PhoneReg.exe”

    wp-Start-WPDevTools

    wp-dev-phone-registration

    3. Sideload xap into your phone. Use XapDeploy.exe (usually) located here – “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\XAP Deployment\XapDeploy.exe”

    wp-app-deployment

    You can also deploy straight from Visual Studio to Windows Phone Device. Connect your phone to your computer.
    Make sure Visual Studio deployment target is “Windows Phone 7 Device” :

    wp-device-target

    From Toolbar, select Build, Deploy Solution.