Decimal 2 Binary

By DimitriC at February 21, 2012 11:23
Filed Under: Programming, tips & tricks

From time to time I get a fun question. One of them was this: Please provide a list with powers of 2 accompanied by their binary representation, for let’s say up to 50.

 

First version:

 

   1:  int temp=1;
   2:   
   3:  for(int i = 1; i<=50; i++)
   4:  {
   5:      Console.WriteLine(i+": Dec: "+temp+" - Bin: "+Convert.ToString(temp,2));
   6:      temp = temp*2;
   7:  }

 

This gives the following result:

 

image

 

Here we bump into the maximum of information that can be held by an integer. So for going up to 50, it suffices to change the type of the decimal number to long:

 

   1:  long temp=1;
   2:   
   3:  for(int i = 1; i<=50; i++)
   4:  {
   5:      Console.WriteLine(i+": Dec: "+temp+" - Bin: "+Convert.ToString(temp,2));
   6:      temp = temp*2;
   7:  }

image

So, I could answer the question. But the same problem occurs when you come to the limit of the long-data type (which is at 64).

 

Double, float or decimal are not supported by the Convert.ToString(…) implementation where you can define the toBase-parameter.

The New Pricing Model for SQL Azure Explained!

By DimitriC at February 17, 2012 10:08
Filed Under: Cloud, Microsoft, General, SQL Azure

Cihan Biyikoglu (SQL Azure) explains on his blog the new pricing model for SQL Azure and provides us with some useful links such as a price calculator, more pricing details,…

 

The article: The New Pricing Model for SQL Azure Explained!

What is "binding" and what makes it late?

By DimitriC at February 14, 2012 08:39
Filed Under: Programming, Training

Another interesting post on Eric Lipper’s blog. In this post, he explains his understanding of the concept of “late binding” (with a couple of small samples).

 

Read the full article here.

Oracle .NET Developer Newsletter

By DimitriC at February 02, 2012 14:05
Filed Under: Oracle, WCF, LINQ, Entity Framework

Found one of these in my mailbox today. And found some interesting stuff!

 

Live Webcast: Entity Framework, LINQ, and WCF Data Services for Oracle Database

 

On Thur., Feb. 9, at 9 a.m. PT, Oracle will host a live webcast on using Microsoft Entity Framework, LINQ, and WCF Data Services with Oracle Database. Led by an Oracle product manager, this session features step-by-step demonstrations that build an Entity Data Model (EDM) from an Oracle schema, query that EDM using LINQ, perform DML on the EDM, and generate an Oracle schema using Model First.

Register here

Log4net for .NET 4.0 & .NET 3.5/4.0 client

By DimitriC at January 19, 2012 08:26
Filed Under: General, log4net, tools & Utilities, Programming

Release 1.2.11 of log4net has these changes (source):

 

General:

 

log4net 1.2.11 is not only a bug fix release, it also adds support for Microsoft® .NET 4.0 as well as the client profiles of .NET 3.5 and .NET 4.0. … The binary distributions no longer contain assemblies built for the Compact Framework 1.0 or the Shared Source CLI - you can build those yourself using the source distribution.

NOTE: The signature of ILoggerFactory.CreateLogger has changed!

 

Some of the bug fixes:

- Visual Studio 2010 .NET 4.0 Application does not copy log4net lib to bin directory

- RemoteFileAppender Tests fail on Windows 7

- log4net doesn't log when running a .Net 4.0 Windows application built in Release mode

- EventLogAppender's ActivateOptions throws SecurityException on Vista/Win2k3 and later when not run as administrator

 

Some of the improvements:

 

- support .NET 2.0 connectionStrings configuration section

- IPAddressConverter improvement for .NET 2 or .NET 3

- Add Cc and Bcc support to SmtpAppender

 

Some new features:

 

- add the ability to roll files based on universal time (UTC).

- Support ASP.Net related PatternConverters to allow items from the HttpContext.Current.Session, Cache, Request, etc. to be captured.

- Build for Compact Framework 2.0

- Added ExceptionEvaluator

- Add TimeEvaluator

- New property ReplyTo address for the SmtpAppender required

- Buildable with VS 2008 and .NET FW 3.5

  • - Support .NET 4.0 including Client Profile

 

 

Previous articles:

 

- Logging: Log4Net Part I

- Logging: Log4Net Part II

- Logging: Log4Net Part III

- Logging: What/When to log?

- Logging: Log4Net Custom AdoNetAdapter and RollingFileAppender with XML

 

Links:

 

- Log4net web site

- Download Log4net

Microsoft at 2012 International Consumer Electronics Show (CES)

By DimitriC at January 17, 2012 10:08
Filed Under: General, Microsoft

See Steve Ballmer’s pre-event keynote, photos and more from this year's Consumer Electronics Show in Las Vegas.

 

All links to presentations, video’s, articles, blogs, photos can be found at the official Microsoft News Center page for CES

BOOK: Putt's Law and the Successful Technocrat: How to Win in the Information Age

By DimitriC at January 10, 2012 09:13
Filed Under: Books, General, Training

Putt's Law and the Successful Technocrat: How to Win in the Information Age

 

As many of you, I too have this huge pile of books somewhere in the house correctly named by Homer J. Simpson as “the to-read-pile”. One of the books that’s been on there quite a while is “Putt's Law and the Successful Technocrat: How to Win in the Information Age” by Archibald Putt (a pseudonym).

 

The books handles the topic on how to be successful in a hierarchy of companies (or departments) whose core business is technology. Sometimes, you read a Dilbert-cartoon and laugh going “it’s funny cause it’s true”. I’ve had that with this book all the time. I’ve read its 170 pages in two days and had to agree for many times with the author’s description of the reality we live in. When it seems that management takes weird decisions, absurd conclusions,… this books explains why they have. I absolutely recommend this book for everyone who is in the technology-business.

 

Interested in the book?

 

United States (in $) / United Kingdom & Europe (in £)

Visual Studio 11 Developer Preview

Found the MSDN newsletter in my mailbox this morning. First topic that caught my eye: Visual Studio 11 Dev Preview! Another one? Indeed!!! So here is some more information on the new kid on the block.

 

What's New in Visual Studio 11 Developer Preview

Visual Studio 11 Developer Preview Training Kit

 

.NET Framework 4.5 Developer Preview

Read geographical information from the Windows Regional and Language Settings

By DimitriC at December 13, 2011 08:19
Filed Under: Programming, tips & tricks

Recently I got a question of how in .NET it was possible to read from the Windows Regional and Language Settings. Rather than messing around with the Windows registry, the best way to get this information is to use the RegionInfo-object in the System.Globalization namespace.

 

The code:

 

First of all, don’t forget to add the correct using statement:

   1:  using System.Globalization;

After that it’s just declaring the RegionInfo object and reading the settings you’d like (for the example, i’m reading all the settings):

 

   1:  RegionInfo local = RegionInfo.CurrentRegion;
   2:   
   3:  Console.WriteLine("CurrentEnglishName: "+local.CurrencyEnglishName);
   4:  Console.WriteLine("CurrencyNativeName: " + local.CurrencyNativeName);
   5:  Console.WriteLine("CurrencySymbol: " + local.CurrencySymbol);
   6:  Console.WriteLine("DisplayName: " + local.DisplayName);
   7:  Console.WriteLine("EnglishName: " + local.EnglishName);
   8:  Console.WriteLine("GeoId: " + local.GeoId);
   9:  Console.WriteLine("IsMetric: " + local.IsMetric);
  10:  Console.WriteLine("ISOCurrencySymbol: " + local.ISOCurrencySymbol);
  11:  Console.WriteLine("Name: " + local.Name);
  12:  Console.WriteLine("NativeName: " + local.NativeName);
  13:  Console.WriteLine("ThreeLetterISORegionName: " + local.ThreeLetterISORegionName);
  14:  Console.WriteLine("ThreeLetterWindowsRegionName: " + local.ThreeLetterWindowsRegionName);
  15:  Console.WriteLine("TwoLetterISORegionName: " + local.TwoLetterISORegionName);
  16:  Console.WriteLine("ToString: " + local.ToString());

 

image

 

NOTE: Notice that the ToString() method is also implemented for this class. So calling RegionInfo.CurrentRegion.ToString() will give you the TwoLetterISORegionName.

Visual Studio SLN-file tools

By DimitriC at December 12, 2011 11:19
Filed Under: Programming, tools & Utilities, Visual Studio

On Hosam Kamel’s blog there is an interesting post on a tool that helps you finding your way in an SLN-file (Visual Studio Solution file).

 

“Tools for SLN File” is a tool that makes it easier for developers to compare, merge or filter the Solution (.Sln) Files generated by Visual Studio. (source)

Benefits and Features

Using the SLNTools provides the following advantages:

  • - Make it easier to compare SLN files versus a 'generic' file comparer. For more information on the compare function see SLNTools Compare.
  • - Make it easier to merge SLN files versus a 'generic' file merger. For more information on the merge function see SLNTools Merge.
  • - Make it possible to create filters for a SLN file. The way it work is that when the filter file is opened, a temporary solution is created dynamically. The created solution file contain only the projects that are specified in the filter, and all the dependencies of those projects. This make it possible to have a mega-solution that contain all the projects needed to build the complete system but still have the possibility to work efficiently on a subset of the system. As you might know, Visual Studio is a lot faster when you have a solution with 10-20 projects instead of one with 200+ projects (opening the solution, building, etc). For more information on the filter function see SLNTools Filter.

 

For downloading the tools or viewing the full article, please visit the original blog post.

Read from the Windows Registry using C#

By DimitriC at December 08, 2011 09:49
Filed Under: Programming, Windows, tips & tricks

I’ve added an example in the MSDN Samples repository which explains how to read values from the Windows Registry.

 

Description:

 

The example is a simple Console-application that shows you how to select the correct RegistryHive, and afterwards navigate to the correct key and read the value. Keep in mind that reading from the Windows registry always returns an object of type 'object' so you'll need to cast this value to something that makes more sense. This means that you'll be expected to know what you're going to read (integer, binary, string,...). And last but not least, don't forget to add the Microsoft.Win32 using statement!

The available RegistryHives you can read from (and their corresponding names in the Registry Editor (Start => Run => regedit.exe):

  • - ClassesRoot (in RegEdit: HKEY_CLASSES_ROOT)
  • - CurrentConfig (in RegEdit:HKEY_CURRENT_CONFIG)
  • - CurrentUser (in RegEdit:HKEY_CURRENT_USER)
  • - DynData (Windows' own hive with dynamic data. Some configuration information in Windows must be stored in RAM because it requires fast modification and retrieval that cannot wait for the registry to send it to the hard disk. You can find all this data in the HKEY_DYN_DATA registry key. The information in this key is newly created every time Windows starts. Not visible in RegEdit)
  • - LocalMachine (in RegEdit:HKEY_LOCAL_MACHINE)
  • - PerformanceData (Is used to access performance counters but is not visible in Regedit)
  • - Users (in RegEdit:HKEY_USERS)

You can find the example here.

Service Pack Collection for Visual Studio 2010, SQL Server 2008 and Microsoft Office 2007

By DimitriC at December 05, 2011 11:05
Filed Under: General, Microsoft, Visual Studio, tools & Utilities, SQL, Update, Office

Microsoft Security Intelligence Report Vol. 11

By DimitriC at October 26, 2011 07:49
Filed Under: Security, Microsoft

Recently, Microsoft released the new SIR (Security Intelligence Report). This 168-page document provides an overview of all the threats that are out there:

 

With a collection of data from Internet services and over 600 million computers worldwide, the Security Intelligence Report (SIR) exposes the threat landscape of exploits, vulnerabilities, and malware. Awareness of threats is a preventive step to help you protect your organization, software, and people.

If you’re only interested in the thread-trends in your region, you can go to the Regional Threat Assessment site and select your region.

 

- The SIR web site
- SIR Volume 11 (PDF)

Security Development Lifecycle resources

There are a bunch of new SDL resources available on the Microsoft Security Development Lifecycle page. For every step in the software development process (Requirements, Design, Implementation, Verification, Release) there are tools and/or training videos available. For a video giving an overview of the SDL tools, click here.

 

Source

 

Requirements

Templates:

- SDL Process Template for Visual Studio Team System 2008

- MSF-Agile + SDL Process Template for Visual Studio Team System 2010

- MSF-Agile + SDL Process Template for Visual Studio Team System 2008

 

Videos:

 

 

Design

 

SDL Threat Modeling Tool

 

For more information on the treat modeling tool, click here.

 

Implementation

 

FxCop 

 

FxCop analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements. For more information, click here. Watch the video here.

 

Anti-Cross Site Scripting Library

 

This is specifically designed to help mitigate the potential of Cross-Site Scripting (XSS) attacks in web-based applications. Watch the video here.

 

Microsoft Code Analysis Tool .NET

 

CAT.NET is a binary code analysis tool that helps identify common variants of certain prevailing vulnerabilities that can give rise to common attack vectors such as Cross-Site Scripting (XSS), SQL Injection, and XPath Injection. Watch the video here.

 

 

Verification

BinScope Binary Analyzer

 

BinScope Binary Analyzer is a verification tool that analyzes binaries to ensure that they have been built in compliance with the SDL requirements and recommendations. Watch the video here.

 

SDL MiniFuzz File Fuzzer

 

MiniFuzz is a basic testing tool designed to help detect code flaws that may expose security vulnerabilities in file-handling code. Watch the video here.

 

AppVerifier

 

Application Verifier is a runtime verification tool for native code that assists in finding subtle programming errors that can be difficult to identify with normal application testing. For more information, click here.

 

SDL Regex Fuzzer

 

SDL Regex Fuzzer is a verification tool to help test regular expressions for potential denial of service vulnerabilities. Watch the video here.

 

Attack Surface Analyzer Beta

 

Attack Surface Analyzer is a tool that highlights the changes in system state, runtime parameters and securable objects on the Windows operating system.

 

 

Release

The release resources are the same templates and videos as the ones in the Requirements section.

Windows 8: Re-inventing the Start-button

By DimitriC at October 06, 2011 08:56
Filed Under: General, Microsoft, Windows 8, UI & UX

On the Windows 8-team blog there are many posts on how the team worked on this product. They don’t explain how they did it, but they also explain why. One of the topics here is the redesign of the start-menu. Steven Sinofsky talks about the history and evolution of the Start menu and how user feedback has been an important source of information in the development of this part of Windows.

 

- Evolving the start menu

- Designing the start screen

WCF and certificate-based authentication

By DimitriC at October 06, 2011 08:30
Filed Under: Architecture, Programming, Security, tips & tricks, WCF

If you want your WCF service to use certificate-based (X.509) certification to authenticate the users accessing your service, you’ll need to provide the right configuration on both the client and the server side. The keyword here is configuration. When I first started searching for a solution I knew it had to be done in the configuration file, but, as usual, I kind of underestimated the amount of configuring that had to be done.

 

Especially when you’re looking at the generated configuration file provided by Visual Studio, it’s easy to get lost in all the possible security settings. I once attended a course given by Juval Löwy (IDesign) on WCF where he applauded the fact that the WCF-team had made everything configurable and at the same time warned us for the complexity that came with it.

 

The solution: There is a easy-to-follow example where you can learn how certificate-based authentication for WCF can be done at Mitch Denny’s blog - Using Certificate-based Authentication and Protection with Windows Communication Foundation (WCF)

 

He starts out by creating a simple WCF service (with 1 HelloWorld-method) and afterwards adding the authentication configuration.

Visual Studio LightSwitch

By DimitriC at August 31, 2011 17:07
Filed Under: Documentation, Microsoft, Programming, Visual Studio, Training, tools & Utilities

The first post I did about this was the announcement of it's beta release. The final version has been available for a while now, so here we go :)

 

What is Visual Studio LightSwitch?

Microsoft Visual Studio LightSwitch is a simplified self-service development tool that enables you to build business applications quickly and easily for the desktop and cloud. What can your business do with LightSwitch? Watch this brief introduction to find out.

 

Links & resources:

Visual Studio LightSwitch page
MSDN LightSwitch Development Center
Visual Studio LightSwitch Technical White Paper Series

 

LightSwitch videos:

 

Overview with Jason Zander
Build Custom Business Apps. Coding Optional.

Introductory videos

Creating Your First Business Application
Data, Queries and Code in LightSwitch 2011
Controlling Access to Your Business Application
Publishing Your LightSwitch Application

Advanced videos

Understanding the LightSwitch Architecture
Deploying Your Application to the Cloud
Advanced LightSwitch Customization
Advanced LightSwitch Extensions

Extension videos

DevExpress LightSwitch Extensions
Infragistics LightSwitch Extensions
RSSBus LightSwitch Extensions

Visual Studio 2010: Team explorer issue

Recently I’ve been working on a project with a friend of mine. One of the things we were playing with was Team Foundation Server 2010. So we set it up and I connected to it using Visual Studio 2010 Ultimate. Collaborating was not an issue. Sharing documents, using source control,… everything worked fine. Now I wanted to work on some of my ideas. I wanted to start a new project in Visual Studio, but the only option that was available to me was the “Start new team project” issue:

 

image

 

When clicking here, I got the following error (which is ok since my rights on that TFS server have been revoked):

 

image

The weird thing here is that I have a fully working version of Visual Studio 2010 Ultimate installed, but I only get the Team Explorer functionality. You can verify this by checking the installed components of Visual Studio in the “About”-window (Help –> About Microsoft Visual Studio).

 

To get back to the “normal” mode in Visual Studio (meaning: being able to create new projects and working with VS2010 normally) you need to reset your preferences by doing Tools > Import/Export settings > Import. Here you can choose to reset everything or to import a certain configuration. I chose to import a predefined configuration without backing up my current configuration (wasn’t much use to me anyhow):

 

image

 

I selected the Visual C# Development Settings and pressed “Next”. There I chose to reset all settings and clicked the “Finish” button:

 

image

 

Now that my configuration settings have been restored, I have the regular view in my Visual Studio and I can create projects again!

 

image

Add national holidays to Outlook calendar automatically

By DimitriC at May 17, 2011 19:14
Filed Under: Office, Documentation, tips & tricks

 

In Microsoft Outlook you can automatically add your country’s national holidays.

In the “Tools” menu, select “Options”

 

clip_image002

 

In the “Preferences” tab on the Options-screen there is a “Calendar”-section. Click on “Calendar Options”

 

clip_image004

 

In the “Calendar options”-section of the Calendar Options (I swear, I’m not making this up) press the “Add Holidays…”-button.

 

clip_image006

 

Now a list appears with all the countries for which national holidays are known in Outlook. Select the countries of which you want the holiday information imported in Outlook and click “OK”.

Microsoft All-in-one code framework

Something I found that might come in handy:

 

The Microsoft All-In-One Code Framework is a free, centralized code sample library driven by developers' needs. Our goal is to provide typical code samples for all Microsoft development technologies, and reduce developers' efforts in solving typical programming tasks.

 

Codeplex page

Download (from Codeplex)

Request a code sample

 

For a full list of downloads (sorted by technology), please check the Codeplex download page. There are samples available for C++, ASP.NET, Silverlight, Azure, Office, Windows, WPF, Windows Security, and many more…

Team Foundation Server 2010 Resources

Here are some resources that might be useful when working with (or learning) Team Foundation Server 2010.

 

Team Foundation Installation Guide for Visual Studio 2010

Description:
Team Foundation Installation Guide 2010 includes instruction for installing Team Foundation Server, Team Foundation Server Proxy and Team Foundation Build Services.

Note: After you download the installation guide, you cannot view its contents unless you right-click the .chm file, click Properties, and then click Unblock.

 

Download

 

Administration Guide for Microsoft Visual Studio 2010 Team Foundation Server

Description: Effective administration of Team Foundation Server is important to the success of your team projects. You can use this downloadable version of the administration content available on MSDN for local review of critical administration concepts, procedures, and walkthroughs.

Download

 

Visual Studio 2010 Team Foundation Server Monitoring Management Pack

Description: The Team Foundation Server 2010 Monitoring Management Pack provides both proactive and reactive monitoring of Microsoft Team Foundation Server 2010. It monitors TFS components such as application tier server instances, team project collections, build servers, and proxy servers.

Download

 

Team Foundation Server Integration Tools (March 2011 Release)

Description: The TFS Integration Tools is a project developed by the Team Foundation Server (TFS) product group and the Visual Studio ALM Rangers to integrate Team Foundation Server with third party systems for migration and synchronization of data.  Although the tools can be used for many purposes, planning, thorough testing and honest evaluation of extra resources and cost that will be required should precede any decision to use the Integration Tools.  The Integration Tools are not intended to replace a server upgrade as a path to TFS2010 and this scenario should be avoided if possible.

The March 2011 release includes the following features:

  • Out of the box adapter to Team Foundation Server 2010
  • Out of the box adapter to Team Foundation Server 2008
  • Out of the box adapter to Rational ClearCase
  • Out of the box adapter to Rational ClearQuest
  • Out of the box adapter for File system based version control migrations
  • Updated documentation, guidance and case studies (readiness package)
  • Updated User Interface to configure and run integrations
  • Synchronization monitoring tools and reports

Download

 

Visual Studio 2010 Team Foundation Branching guide

Description: The purpose of this project is to build some insightful and practical guidance around branching and merging with Visual Studio Team Foundation Server 2010. The new release focuses on Hands on Labs and includes lots of lessons learnt from the community Q&A.

Download

 

Visual Studio 2010 Team Foundation Server Requirements Management

Description: This Ranger solution addresses the People, Process, and Technology guidance for Requirements Engineering (RE) using Team Foundation Server. The goal of this guidance is to provide formalized Microsoft field experience in the form of recommended procedures and processes, Visual Studio Team System and Team Foundation Server configurations, and skill development references for the Requirements Engineering discipline of your application lifecycle.

Download

 

Microsoft Visual Studio Team Explorer Everywhere 2010

Description: Eclipse plug-in and cross-platform command-line client for Visual Studio 2010 Team Foundation Server.

Download

 

Team Foundation Server Power Tools (March 2011)

Description: A plug-in to Visual Studio, Alerts Explorer provides a graphical user interface that supports flexible subscription of alerts based on check-in, work item change, or build completion.

Download

[WP7] Nodo update for Windows Phone

By StijnC at April 01, 2011 09:12
Filed Under: Windows Phone 7

The March update of Windows Phone 7 being released to the public sure got me exited, finally we’ll have copy/paste at our disposal.

 

Currently my carrier is still in a testing stage of the NoDo update, but using a little trick does the job and grants access to the update.

As of this writing, my phone is updating:

image

 

Steps are available on Paul’s website via Neowin

 

Enjoy!

Book: Algorithms of the intelligent web

By DimitriC at March 31, 2011 18:40
Filed Under: Books, Architecture, Programming, Training

clip_image001

 

A very interesting read, written by Haralambos Marmanis, Dmitry Babenko, on how the web provides us with a rich user experience with the help of algorithms. Topics such as ranking and recommendation systems are explained very well and are illustrated with examples. Also, API's from well known sites such as Google, eBay and Facebook are discussed.

 

The book on amazon.

The Job Interview: Technical questions (Pt. V)

By DimitriC at March 28, 2011 19:16
Filed Under: General, Training, tips & tricks

Here’s one that you might run into when being screened for a technical position: the brain teaser. The point here, usually, is not to see if you can solve a riddle. But more to see how your mind works when an unusual problem arises (see it as creative problem solving). I’ll go over some of the types of questions you may encounter and I’ll also give some references for who like this kind of stuff Smile.

 

The Fermi-question

The answers to these kind of questions are based on estimates and a logical thought-process that accompanies these estimates to derive a valid answer. Often you won’t find the correct answer, but the idea is to get very close. Some of the popular Fermi-questions are: “How many piano tuners are there in the world?” or “How many gas stations are there in the United States of America?”. A bad way to answer these questions is to just give a number and be done with it.

 

On wikipedia you can find a good example of this: “How many piano tuners are there in Chicago?

Next to wikipedia, here is another great resource on the subject: Science Olympics. Here you will also find many examples of Fermi-problems. Some neat ones:

 

- How many golf balls will fit in a suitcase?
- How many hairs are there on a human head?
- If your life earnings were doled out to you by the hour, how much is your time worth per hour?
- People crowd into London until all available open space within the city limits is covered with standing people. How many people would there be?

 

More information about Fermi problems in general can be found on Wikipedia.

 

Creative-thinking question

These are actually just weird questions. Again, keep in mind that the purpose of these questions is to see how you approach a problem that is new to you. For instance: “How are m&m’s made?”, “Without looking at specifications, what is the weight of a Boing 747?” “Why are soda cans produced in that shape?” “Why are manhole covers round?”

 

Some of these questions can be about things that you know. If you know how m&m’s are made, just answer. If you just now looked at you soda can and asked yourself “Why is it made like that?”, you might want to do some thinking. The answer can be simple: They are made like that cause that way they stack easy. The answer can also be scientific: The curves in the can make sure that the build up pressure inside the can doesn’t make the can go boom. If it would be a metal cylinder with the same thickness of steel everywhere, the can probably can’t stand the build up of pressure inside the can.

 

Mathematical questions

 

These questions often have a certain way of looking at a problem to find the solution. Typically, with these questions, when someone gives you the answer you go “aaaahhhhh…of course”. A very famous one here is the riddle that John McClane (played by Bruce Willis) and Zeus Carver (Samuel L Jackson) had to solve in Die Hard: With a Vengeance: You have a jug that can contain 5 liters (let’s call it J5) and a jug that can contain 3 liters (J3). Now, you need to get exactly 4 liters  in the 5-liter-jug. Solution (let’s use water, just like in the movie Smile ):

 

- fill J3 with water

- poor J3 into J5

- fill J3 again with water

- fill J5 to the top (now you added 2 liters, so you have 1 liter in J3)

- empty J5

- fill J5 with the 1 liter from J3

- fill J3

- poor J3 into J5

 

And now J5 contains 4 liters of water.

 

Another one: You have 8 billiard balls. They all have exactly the same weight, except for one. You have a weighing scale like this:

 

 

You need to find the billiard ball that has a different weight with the least amount of weighings.

 

Answer: You can find the billiard ball in two weighings.

 

Put three billiard balls on each side of the scale. If the scale balances to a side, you know in which batch of three the crooked ball is. Now you put one ball of this batch on each side of the scale. If it balances to a side you know which ball is crooked, if it doesn’t, the crooked ball is the remaining one. If in the measurement of 3 versus 3 the scale stays in balance, you just need to measure the remaining two.

 

This can also be done with 9 billiard balls, here when the scale balances to one side in the first weighing, the crooked ball is in the last batch of three. And you still have to just weigh two of them to find the crooked billiard ball.

 

 

 

As you can see, there are many examples of these kinds of questions. You can spend a lot of time surfing the web searching for these questions.

 

There are also several books that cover this subject. Often these books also cover other subjects I talked about in these series (algorithms, programming questions,…)

 

- How would you move Mount Fuji?(William Poundstone)

- Programming Interviews Exposed (John Mongan, Noah Suojanen, Eric Giguère)

- Puzzles for programmers and pros (Dennis Shasha)

- Cracking the coding interview (Gayle Laakmann)

 

…and probably many more Smile

The Job Interview: Technical questions (Pt. IV)

By DimitriC at March 21, 2011 19:56
Filed Under: Programming, Training

An often requested piece of code is a sort algorithm. Of course, there are many sorting algorithms as you can see with our good friend wikipedia. A popularly one is the Bubble sort. In it’s essence it’s not a difficult algorithm once you know how it works. But in interviews it’s usually the case that you haven’t had to implement it for a long time or maybe you’ve just graduated and have never heard of it (but then you shouldn’t have graduated or the people responsible for your curriculum need a good talking to!) A good alternative for the bubble sort is the Insertion sort.

 

A short description:

 

“…a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. “ – Source: Wikipedia

The algorithm:

   1: void BubbleSort(int[] intArray)
   2: {
   3:     int tmp;
   4:     for (int i = intArray.Length - 1; i >= 0; i--)
   5:     {
   6:         for (int j = 1; j <= i; j++)
   7:         {
   8:             if (intArray[j - 1] > intArray[j])
   9:             {
  10:                 tmp = intArray[j - 1];
  11:                 intArray[j - 1] = intArray[j];
  12:                 intArray[j] = tmp;
  13:             }
  14:         }
  15:     }
  16: }

 

 

An example of using the method above:

 

   1: void Main(string[] args)
   2: {
   3:     int[] intArray = new int[] { 2, 8, 4, 9, 5, 1 };
   4:     PrintArray(intArray);
   5:     BubbleSort(intArray);
   6:     Console.WriteLine();
   7:     PrintArray(intArray);
   8:  
   9:     Console.ReadKey();
  10: }
  11:  
  12: public static void PrintArray(int[] intarray)
  13: {
  14:     foreach (int number in intarray)
  15:     {
  16:         Console.WriteLine(number);
  17:     }
  18: }

 

…gives the following output:

 

image