Interview questions – Change for a dollar

By James at March 22, 2010 12:19
Filed Under: Inland Empire .NET UG, Life in General, Technology in General

So, in my quest to become gainfully employed, I am going through the interview process, mainly technical interviews with hands-on developers. Unfortunately, they seem to want people that 1) either *just* graduated from Computer Science school, or 2) can memorize obscure bits of code, and recite the Visual Studio help files verbatim.

At my last interview, I walked in – after a two-hour car ride, and trying to find a parking spot – to a “Hi, let’s write some code on the white board” situation. Ok, I say to myself, “let’s give this a try”. Their first question, “write code to calculate the optimum number of coins to return when giving change after a purchase.”

Hmm, I think. And I stumbled around for a bit, eventually ending up writing some pseudo-code that involved some long division. The Inland Empire .NET User’s Group’s next meeting was the following Tuesday, and I decided to ask them the same question – however they had the luxury of being in a friendly environment with soda and pizza in their fiery little bellies.

Below are the two answers that UG members sent to me, and it got me to thinking. What I would like to do is have you write your code in the comments, so I can see how many different ways there are to write this method.

From member Daniel Lopez, “Just for grins. If you have suggestion on how to make it better, let me know.”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GiveChange
{
      class Program
      {
            static void Main(string[] args)
            {
                  DoChange(8.92);
            }

            private static void DoChange(double Tendered)
            {
                  double _DecimalPart = Math.Round(1-( Tendered - Math.Floor(Tendered)),2);
                  do
                  {
                        if (_DecimalPart >= .25)
                        {
                              Change.Quarters += 1;
                              _DecimalPart -= .25;
                        }
                        else if (_DecimalPart >= .10)
                        {
                              Change.Dines += 1;
                              _DecimalPart -= .1;
                        }
                        else if (_DecimalPart >= .05)
                        {
                              Change.Nickles += 1;
                              _DecimalPart -= .05;
                        }
                        else 
                        {
                              Change.Pennies += (int)(_DecimalPart * 100);
                              _DecimalPart -= _DecimalPart;
                        }
                  }
                  while (_DecimalPart > 0);

                  StringBuilder sb = new StringBuilder();

                  sb.Append(string.Format( "Quarters: {0}", Change.Quarters));
                  sb.AppendLine();
                  sb.Append(string.Format("Dines: {0}", Change.Dines));
                  sb.AppendLine();
                  sb.Append(string.Format("Nickles: {0}", Change.Nickles));
                  sb.AppendLine();
                  sb.Append(string.Format("Pennies: {0}", Change.Pennies));

                  Console.WriteLine(sb.ToString());
                  Console.ReadLine();            
            }      
      }

      public  static  class Change
      {
            public static int Quarters { get; set; }
            public static int Dines { get; set; }
            public static int Nickles { get; set; }
            public static int Pennies { get; set; }
      }
}

And from member Henry Vander Leest, "Hi James, Was thinking about the comments you made at the meeting about the interview you had the the question about the code to make change. Well, here's my solution... I don't believe I could have written this in 5 minutes under stressful circumstances. Live Long and prosper."

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ChangeMaker1
{
    class Program
    {
        static void Main(string[] args)
        {
            //takes command line arg from 1 to 99 to make change for a dollar
            int quarters;
            int dimes;
            int nickels;
            int pennies;
            int tendered = 100;
            int cost = Convert.ToInt32(args[0]);
 
            int change = tendered - cost;
            quarters = change / 25;
            change -= quarters * 25;
 
            dimes = change / 10;
            change -= 10 * dimes;
 
            nickels = change / 5;
            change -= nickels * 5;
 
            pennies = change;
 
            Console.WriteLine("Quarters {0}, Dimes {1}, Nickels {2},  Pennies {3}, 
This is the change for item costing {4} cents",
quarters, dimes, nickels, pennies, cost ); } } }

I tested both, and they work like a champ. Now I just need to memorize these for my next round of interviews. So tell me, how would you do this “simple” exercise.

Time to work…

James

.NET Rocks is on the Road Again!

By James at March 18, 2010 03:46
Filed Under: Inland Empire .NET UG, Life in General

Man am I excited! Richard Campbell and Carl Franklin from .NET Rocks are going on the road again, and are making special plans to come out and visit the Inland Empire .NET User’s Group!

I’ve been working with – well he’s been doing all the work – Jim Barry at ESRI in Redlands to host the event there, and he has really come through for us. We will be having the event in the new Auditorium, which means the Inland Empire leg of the road trip will make all the other venues look like rickety old shelters.

(Update. I got so excited, I forgot the date)

Thursday, April 22, 2010 from 6:00 to 9:00-ish

Here’s a peek of what I’m talking about.

ESRI Auditorium

Go IE!

Here’s the “official” word from Richard and Carl…

.NET Rocks is on the Road Again!

Carl and Richard are loading up the RV and driving to your town again to show off the latest and greatest in Visual Studio 2010! And to make the night even more fun, we’re going to bring a rock star of the Visual Studio world to the event and interview them for a special .NET Rocks Road Trip show series. Along the way we’ll be giving away some great prizes, showing off some awesome technology and having a ton of laughs.

And one lucky person at the event will win “Ride Along with Carl and Richard” and get to board the RV and ride with the boys to the next town on the tour (don’t worry, we’ll get you home again!)

So come out to the most fun you can have in a geeky evening – and find out what’s new and cool in Visual Studio 2010!

Thanks Jim for all your help!

Keep an eye on http://www.iedotnetug.org/sf/dotnetrocksroadshow/ to RSVP for the event

Time to get planning.

Inland Empire .NET User's Group 2008 Microsoft Launch

By James at March 12, 2008 09:02
Filed Under: Inland Empire .NET UG

We had our 2008 Microsoft Launch event last Tuesday. When word came down from Microsoft that they were going to have Community Launch Events, I immediately asked for the details. I was told we could have at most, three presenters. In the last year, several members of the user group have really stepped forward to help me with things, and I thought it would be nice to reward them by giving them access to this great experience. So, I wrote a letter back, describing what these people have done, and could they be involved. The answer was "yes". I also mentioned our meeting schedules and our Launch would be a week before Community Launches were supposed to start. Again, they said it wouldn't be a problem. So it was game on. I invited the members I had thought of and away they went.

Well, the "official" training started to trickle out, and there wasn't much there, so these six people, went ahead and created their own content. Launch day came and was I impressed! Here is what the lineup was:

  • George Ande – ASP.NET Ajax with .NET 3.5
  • Sean Dorsett – Visual Studio 2008 Tips and Tricks
  • Volkan Uzun – New features of C# 3.0
  • Steve O’Brien – LINQ
  • Matt Penner – GIS and Spatial Analysis in SQL 2008
  • Cigdem Uzun – Silverlight 2.0

What totally amazed me was how with minimal official training content there was, they each came up with six dead on, concise, to the point, and top notch presentations. Each presentation went about 25-30 minutes, and the amount of questions which were generated, just blew me away. The amount of energy in the room was great. Two recruiters, Armando Lopez from Robert Half Technology, and Brant Jones from San Bernardino County talked about local jobs.

Attendance was great, with standing room only and I'm grateful to Robert Dottl at Riverside Medical Clinic for giving us the bigger room.

Here are the stats:

  • RSVPs: 36 
  • Attendance: 34 - a new IEDOTNETUG Record
  • Non RSVP Attendees: 8
  • First Time Attendees: 11
  • Total Raffle Ticket Sales: 364
  • Number of software licenses (VSTS 2008, SQL 2008, WS 2008, telerik, CodeSmith, ReSharper, Infragistics) won: 38
  • Number of books (O’Reilly, Wrox, Pearson) won: 22
  • Number of job offers mentioned after break: 4
  • Pizza slices left over: 1

Oh, and that's not a typo. This was not Visual Studio Standard Edition given away at the public launches, this is Visual Studio Team Suite!

Pictures of the launch are on Flickr, http://www.flickr.com/photos/iedotnetug

Wow, I'm still on a high

About the author

James James is a five time and current Microsoft MVP in Client App Development, a Telerik Insider, a past Director on the INETA North America Board, a husband and dad, and has been developing software since the early days of Laser Discs and HyperCard stacks. As the Founder and President of the Inland Empire .NET User's Group, he has fondly watched it grow from a twice-a-month, early Saturday morning group of five in 2003, to a robust and rambunctious gathering of all types and sizes of .NET developers.

James loves to dig deep into the latest cutting edge technologies - sometimes with spectacular disasters - and spread the word about the latest and greatest bits, getting people excited about developing web sites and applications on the .NET platform, and using the best tools for the job. He tries to blog as often as he can, but usually gets distracted by EF, LINQ, MVC, ASP, SQL, XML, and most other types of acronyms. To keep calm James plays a mean Djembe and tries to practice his violin. You can follow him on twitter at @latringo.

And as usual, the comments, suggestions, writings and rants are my own, and really shouldn't reflect the opinions of my employer. That is, unless it really does.

James Twitter Feed

Recent Comments

Comment RSS

Month List