Some place in space

My interview with Microsoft

March 14th, 2008 glenn

I interviewed with Microsoft via my college. It was my first interview for software development. I read up on how Microsoft conducts interviews, what they want to know, etc. So I knew there would be a technical question. I would be surprised if any interview for a developer job didn’t have one.Here is a problem I have though. When someone asks you to solve a technical problem during an interview, do they want to know:

  • 1) How you solve problems?
  • 2) How well you know the language you say you know?
  • 3) Can you even code at all?

I believed that this was the order of priority. Now I wonder if it is the other way around.

The problem I was given was this:
Write a function that takes an array of integers, removes all duplicates from the array and compacts it.

Assuming the interviewer wanted to see option number 1 from above, I started out writing pseudo code. That is a good way to solve a problem isn’t it? You reason it out first before you jump into coding. I should have taken the clue he gave me when he said it was ‘an easy problem’.

In C#, this is an easy problem:

CompactArray
{
     public void compact(ref int[] array)
    {

          numbers = numbers.Distinct().ToArray();

     }
}

Too simple?

At least C++ is a little more interesting.

<font style=“position: absolute;overflow: hidden;height: 0;width: 0″></font>
void arrayCleaner(int * numbers, int * size)
{

     list<int> num;</int>

     for(int i = 0; i &lt; *size -1; i++)
     {
          num.push_front(numbers[i]);
     }

     memset(numbers,0,*size);

     num.unique();

     *size = num.size();

     for(int i = 0; i &lt; *size -1; i++)
     {
          numbers[i] = num.back();
          num.pop_back();
     }

}

My favorite one though, is good old C. This is what I actually designed in psuedo code.

void cleanArray(int * numbers, int * size)
{
     int * values = malloc(*size);
     int * x;
     int i = 0;
     int j = 0;
     int z = 0;
     int duplicate = 0;

     memset(values,0,*size);

     for(i=0; i &lt; *size/sizeof(int);i++)
     {
          x = &amp;numbers[i];
          for(j=0;j &lt; *size/sizeof(int);j++)
          {
               if (*x == values[j])
               {
                    duplicate = 1;
               }
          }

          if (!duplicate)
          {
               values[z++]= *x;
          }
          duplicate = 0;
     }

     for(i=0;i &lt; z;i++)
     {
          numbers[i] = values[i];
     }

     *size = z * sizeof(int);

     free(values);

}

To me this is the best example of coding and problem solving.

Read More

CPP Double Quotes and Single Quotes

February 28th, 2008 glenn

I’m writing this down here because I always seem to forget it.
In cpp, single quotes represents a char.

char c = ‘x’;

Double quotes represents a string.

string str = “Hi”;

Note that the string has 3 bytes because it has 3 chars, ‘H’, ‘i, ‘\0′.
Why does this matter? Well if you did something like:

TCHAR c = “x”;

The compiler will give you:
error C2440: ‘initializing’ : cannot convert from ‘const char [2]‘ to ‘TCHAR’

TCHAR c = “x” might seem to make sense if you aren’t thinking about it, so watch out.

Read More

Software for home Fabbers, part 1

February 20th, 2008 glenn

My senior project at OSU was to create the software for a home fabber project. The software would read a file in STL (stereolithography) format and convert it into a format that the fab machine could understand. Everything was up to me as far as how it was written, and I was the only CS student working on the software.

It was a real learn-as-I-go experience. I could have written something in linux using C with a command line interface, but I wanted to be able to show people something that anyone could understand. I decided to create a GUI that could display the shape loaded and allow the user to manipulate it. Problem was I didn’t know how to create a GUI. Visual Studio makes it real easy to create Windows GUI’s, so I used that.

I had never really used Visual Studio before. Most of what I had done was in ANSI C or C++ using command line compilers like gcc and text editors. It turns out that it was easier to create Windows forms using .Net. This means managed code. This means I could not automatically paste regular C++ code into my GUI project. I could have learned MFC, but I did not have the time. I figured out how to make the C++ code I knew how to create mesh with the managed .Net code. It wasn’t pretty.

Next, I had to figure out how to display 3D shapes. The obvious choices were OpenGL and DirectX. I had heard tons about how easy OpenGL was, how great the resources and community was and horror stories about how hard DirectX was. The DirectX was appealing actually, I like I challenge and I know it can do great things, but I was still limited by time. I just OpenGL as the faster (as far as code writing) of the two. With the help of CodeProject, I figured out how to place an OpenGL control on a windows form.

All of the previous was the easy part. I now had to figure out how to manipulate the 3D file into something the fabber could understand. An STL file describes a mesh. A mesh is a description of a surface. I needed to send info about interior volumes to the fab machine. This was tough because I had to be able to describe the problem in accurate terms before I could even begin to search for and formulate a solution.

My initial plan was to decompose the shape into small cubes. The printer could understand this. If the software says that there is a cube at X,Y it spits out some goo at X,Y (Ok really it was X,r but more on this later). I had no idea how to do this. The STL describes a mesh in terms of triangles. I limited my problem to converting a single triangle into a triangle composed of cubes. Once this was done to the whole mesh, the interior could be filled with cubes. I had no idea how to do this either. I further limited the problem to being able to detect if a line intersected a triangle. From here I could construct the cubes. Now I was making progress. There was lots of good info about how to do this on the Internet.

I then realized that this was basically a collision detection problem. I had done this in 2D back in the good old days on my Commoder64 (yes I’m an older student), but collision in 2D was not the same as collision in 3D. Collision in 3D relies on bounding boxes. In many video games, the collision detection is really between the bounding boxes of 2 or more shapes. This was not good enough, I needed to accurately describe the whole shape, not the bounding box.

What I could do though, is use the bounding box of the mesh as a good way to define a point that is definitely outside of the shape. I could then pick a point at random and by comparing it to the point on the bounding box test whether that point was on the inside of my mesh or on the outside. Turns out that there is a nifty algorithm that can do this, and it works for 2D and 3D shapes as long as they are solid. They could even be concave. It’s not proven to be 100% accurate, but it works well enough for my purposes. I started writing the software for this but soon found a nice software library written in C that does this and provided a nice data structure for the meshes.

So here is what I did: I created a small box shape, to represent the smallest thing the printer could create. I then moved the shape in a sequential pattern and at each placement I test each corner of the box for it location inside or outside the mesh. If 6 of 8 corners were inside, the box itself was considered to be inside the mesh and the fabber would print in that location. All of this would be displayed on my GUI as it happened.

And the project was a success.

There you have a wordy but by no means complete description of my project. There was a lot more I could have done and wanted to, but my goal was to have working software to go with the working fabber the engineers creates (they were really sharp guys). There probably should have been at least 1 more CS student working on this, but this was a new type of cross discipline project and was somewhat experimental.

Some of the things I would like to change:

  • Write the whole thing in one language
  • Make it more modular
  • Have a requirements document
  • Re-write the pre-written code
  • Unit testing

So here begins the Rototyper Software v2.o project!

It will be:

  • Written in C#
  • Written with DirectX
  • Modular
  • Created from scratch
  • Unit tested
  • Fully documented
  • Usable with a variety of home fabbers

In the long term, I plan on creating a version usable on Linux machines as well.

I’ve already gotten a good start on the project. This blog will track my progress of the project. I hope to be able to give my completed software back to the OSU engineering project for future student project use. It was an awesome project and I hope they continue it.

Read More

College and time management skills

October 22nd, 2006 glenn

Time management has got to be one of my weakest skills. It’s not something that they teach in college, or at least not something that I have been taught in college, but there is the opporunity to learn it here. It is possible to get by without ever learning it, but you will never get very far.

I find it to be more true as time goes on that I do not get done the simple things I want to do, even though I know that I have plenty of time. For one example, this website, my personal “blog” (hate that word). I have dozens of articles written in my head, a few projects that I have been working on, etc. Yet notice the gap between entries. Pretty boring, because I am leading a pretty boring life and it is not because I have to. It’s because I am currently unable to make use of my time, and it is starting to cut into my personal activities.

There is time I spend being productive, and time I spend on ‘me time’. Recently I have become aware that I spend most of my time on ‘not doing a damn thing’ time, and it’s disgusting. How will I deal with this?

(more…)

Read More

Routine Vs Ritual

July 5th, 2006 glenn

It’s difficult to get into good habits sometimes. The conventional belief is that it takes 21 days of doing something to make it a habit. That 21 days can be a lot harder than it sounds. I think my personal best is 14 days.

It helps to think of some activity as a ritual. Humans seemed mentally geared for ritual. Everyone has some silly little habit, some odd compulsion that they do without thinking. This is the difference between routine and ritual. A routine is planned, requires thought. A ritual requires no thought, you just do it.

Computer programs are designed to be efficient and use as little of the processor as possible. Daily habits should be the same way with regards to your brain. If you have to put a lot of thought into something you do every day, you may be doing something wrong.

That sounds scary. I mean, most people drive cars every day, but how much thought do you really put into it? It’s rather automatic. I would be more worried about someone who has to really concentrate on driving every day. Really, anything that you do over and over again becomes automatic. You get better at it.

So why not skip to this point of the process? Take something that you want to be in the habit of doing everyday and make a ritual of it. Don’t waste time thinking about it, just do it.

Yes, I am aware that is nike’s logo. I’m not endorsing them.

Read More