Click here to Skip to main content
11,496,146 members (658 online)
Click here to Skip to main content

C# vs. VB contest - Resolving Mac Mahon problem using .NET

, 14 Mar 2005 88.2K 305 11
Rather than discussing for ever wether C# is better than VB or vice-versa, let's see which programmers are best.
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.

Sample Image - macmahon2.png

Introduction

For the last two years, every couple of month or so an article appears claiming “C# is faster than VB.NET”. I agree C# is possibly very slightly faster, I won’t argue. Perhaps it is only fair. Perhaps it is to compensate the fact that C# programmers are probably not as good a VB programmers. You understand that, it is time to revive a good old war like we had years ago between Atari and Amiga. If we can't decide which Language is best, let's see which programmers are best, whether it is VB programmers or C# programmers.

The Mac Mahon problem

The problem I want to challenge you is this one.

You have to complete a puzzle made of 24 pieces. The pieces are displayed in the picture at the beginning of this article.

  1. All the 24 pieces must be used.
  2. Each piece can be rotated to any orientation.
  3. Each segment color must match the color of the adjoining segment.
  4. The puzzle border must be of the same color (red in this case).

This problem can be reproduced on cardboard to play as a solitaire.

A valid solution

This is one solution of the problem.

As you can see

  • It uses all 24 pieces.
  • The border is all red.
  • Each piece shares a color with each of its neighbours.

The Challenge

The challenge is to make a program which looks for solution for this puzzle. The program has to count how many solutions the puzzle has, and then do it as fast a possible. The existing code is already searching, but not very fast. I let my computer run 24 hours and it did not complete…

VB.NET results

Date Description Result
14/03/2005

First release
by Pascal GANAYE

10,000 results in more than 24 hours. Did not complete
15/03/2005 Added a few optimizations 106624 solutions in 90 minutes

C# results

Date Description Result
14/03/2005

No submission yet

-
17/03/2005 Marc Clifton started a C#. 77,306 solutions in about 60 minutes

Other languages

I would love to see another language here. If you have a try, please post something in the forum below.

Point of Interest

As you can see, each piece is divided in 4 triangles and filled with 3 colours. Mathematically this is a nice problem, because this it is not 24 arbitrary chosen pieces but every single combination. There are 3*3*3*3 = 81 possibilities. But If you remove the duplicates you end up with only 24 different pieces.

Submission rules

  • I will post one submission in each submitted language. You can also use this page forum at the bottom.
  • The program can use any sort of optimisation as long as it stays managed .NET and native language (can’t use MSIL).
  • All optimisation must be described. Please no hard coded solution.

I suggest a notation structure for the solutions. If you name the piece A0,B0,C0,...X0.

Sample screenshot A0 Sample screenshot B0 Sample screenshot C0 Sample screenshot D0 Sample screenshot E0 Sample screenshot F0
Sample screenshot G0 Sample screenshot H0 Sample screenshot I0 Sample screenshot J0 Sample screenshot K0 Sample screenshot L0
Sample screenshot M0 Sample screenshot N0 Sample screenshot O0 Sample screenshot P0 Sample screenshot Q0 Sample screenshot R0
Sample screenshot S0 Sample screenshot T0 Sample screenshot U0 Sample screenshot V0 Sample screenshot W0 Sample screenshot X0

The rotated version of Sample screenshot B0 would be called:

Sample screenshot B1 (90 degrees anti-clockwise)

Sample screenshot B2 (180 degrees), and

Sample screenshot B3 (270 degrees).

Then a solution like this one

could be written like this:

B2 D0 I0 L0 J0 G0
A0 C2 V0 S0 T2 O3
K0 F0 X0 W0 U0 Q3
H2 E0 P2 R2 M2 N3

or even as a single line like this:

B2D0I0L0J0G0A0C2V0S0T2O3K0F0X0W0U0Q3H2E0P2R2M2N3

This will probably help to compare our results.

You can see mine here.

Last notes

I hope you realize, I don't take this language war very seriously. I just love the Mac-Mahon problem. How can we live without knowing for sure how many solutions there are?

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Pascal Ganaye
Software Developer (Senior)
United Kingdom United Kingdom
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

Comments and Discussions

 
GeneralYour link is incorrect Pin
Mustafa Ismail Mustafa22-Nov-07 13:13
memberMustafa Ismail Mustafa22-Nov-07 13:13 
GeneralRe: Your link is incorrect Pin
Pascal Ganaye7-Jan-08 1:35
memberPascal Ganaye7-Jan-08 1:35 
General5784 Pin
ColinDavies17-Apr-05 1:21
memberColinDavies17-Apr-05 1:21 
GeneralRe: 5784 Pin
pascal ganaye20-Apr-05 15:53
memberpascal ganaye20-Apr-05 15:53 
GeneralI am a bit embarassed... Pin
pascal ganaye9-Apr-05 14:12
memberpascal ganaye9-Apr-05 14:12 
GeneralIf this is what I think it is... Pin
Daniel Turini7-Apr-05 1:53
memberDaniel Turini7-Apr-05 1:53 
GeneralResults Pin
pascal ganaye6-Apr-05 11:08
memberpascal ganaye6-Apr-05 11:08 
GeneralRe: Results Pin
Giancarlo Aguilera7-Apr-05 15:06
memberGiancarlo Aguilera7-Apr-05 15:06 
GeneralC++ solution Pin
Jon5-Apr-05 1:34
memberJon5-Apr-05 1:34 
GeneralRe: C++ solution Pin
SeveredCross5-Apr-05 17:44
memberSeveredCross5-Apr-05 17:44 
GeneralRe: C++ solution Pin
Jon5-Apr-05 23:36
memberJon5-Apr-05 23:36 
GeneralRe: C++ solution Pin
pascal ganaye6-Apr-05 11:12
memberpascal ganaye6-Apr-05 11:12 
GeneralRe: C++ solution Pin
Marc Clifton9-Apr-05 8:16
protectorMarc Clifton9-Apr-05 8:16 
GeneralSolved in 67 seconds Pin
Marc Clifton31-Mar-05 4:53
protectorMarc Clifton31-Mar-05 4:53 
GeneralRe: Solved in 67 seconds Pin
pascal ganaye31-Mar-05 10:40
memberpascal ganaye31-Mar-05 10:40 
GeneralRe: Solved in 67 seconds Pin
Marc Clifton31-Mar-05 11:56
protectorMarc Clifton31-Mar-05 11:56 
GeneralRe: Solved in 67 seconds Pin
pascal ganaye1-Apr-05 10:09
memberpascal ganaye1-Apr-05 10:09 
GeneralC# Algorithm Pin
SeveredCross21-Mar-05 12:05
memberSeveredCross21-Mar-05 12:05 
GeneralRe: C# Algorithm Pin
pascal ganaye21-Mar-05 13:53
memberpascal ganaye21-Mar-05 13:53 
GeneralOptimizations Pin
pascal ganaye19-Mar-05 4:48
memberpascal ganaye19-Mar-05 4:48 
Generalhttp://www.ganaye.com/macmahon/ Pin
pascal ganaye16-Mar-05 14:08
memberpascal ganaye16-Mar-05 14:08 
General5.2 million and counting Pin
Marc Clifton16-Mar-05 1:36
protectorMarc Clifton16-Mar-05 1:36 
GeneralRe: 5.2 million and counting Pin
pascal ganaye16-Mar-05 12:21
memberpascal ganaye16-Mar-05 12:21 
GeneralRe: 5.2 million and counting Pin
Marc Clifton16-Mar-05 16:01
protectorMarc Clifton16-Mar-05 16:01 
GeneralThe number of results battle. Pin
pascal ganaye16-Mar-05 12:52
memberpascal ganaye16-Mar-05 12:52 
GeneralRe: The number of results battle. Pin
Marc Clifton17-Mar-05 13:15
protectorMarc Clifton17-Mar-05 13:15 
GeneralRe: The number of results battle. Pin
pascal ganaye19-Mar-05 1:20
memberpascal ganaye19-Mar-05 1:20 
GeneralRe: The number of results battle. Pin
Marc Clifton19-Mar-05 2:03
protectorMarc Clifton19-Mar-05 2:03 
GeneralRe: The number of results battle. Pin
pascal ganaye19-Mar-05 6:17
memberpascal ganaye19-Mar-05 6:17 
GeneralIt will not prove anything Pin
Oleg Shilo15-Mar-05 17:41
memberOleg Shilo15-Mar-05 17:41 
GeneralRe: It will not prove anything Pin
pascal ganaye17-Mar-05 4:26
memberpascal ganaye17-Mar-05 4:26 
GeneralRe: It will not prove anything Pin
Oleg Shilo17-Mar-05 13:09
memberOleg Shilo17-Mar-05 13:09 
General77,306 Pin
Marc Clifton15-Mar-05 15:20
protectorMarc Clifton15-Mar-05 15:20 
GeneralMore on MacMahon Pin
Peter Hancock14-Mar-05 17:44
memberPeter Hancock14-Mar-05 17:44 
GeneralRe: More on MacMahon Pin
pascal ganaye14-Mar-05 22:48
memberpascal ganaye14-Mar-05 22:48 
QuestionSeriously - are you mental ? Pin
Christian Graus14-Mar-05 15:07
memberChristian Graus14-Mar-05 15:07 
AnswerRe: Seriously - are you mental ? Pin
pascal ganaye14-Mar-05 15:15
memberpascal ganaye14-Mar-05 15:15 
GeneralRe: Seriously - are you mental ? Pin
Christian Graus14-Mar-05 17:20
memberChristian Graus14-Mar-05 17:20 
GeneralRe: Seriously - are you mental ? Pin
mav.northwind14-Mar-05 22:15
membermav.northwind14-Mar-05 22:15 
GeneralRe: Seriously - are you mental ? Pin
pascal ganaye15-Mar-05 3:23
memberpascal ganaye15-Mar-05 3:23 
GeneralRe: Seriously - are you mental ? Pin
mav.northwind15-Mar-05 3:41
membermav.northwind15-Mar-05 3:41 
GeneralRe: Seriously - are you mental ? Pin
Christian Graus15-Mar-05 15:30
memberChristian Graus15-Mar-05 15:30 
GeneralRe: Seriously - are you mental ? Pin
Unruled Boy16-Mar-05 16:48
memberUnruled Boy16-Mar-05 16:48 
GeneralRe: Seriously - are you mental ? Pin
Christian Graus17-Mar-05 12:20
memberChristian Graus17-Mar-05 12:20 
GeneralRe: Seriously - are you mental ? Pin
pascal ganaye17-Mar-05 4:33
memberpascal ganaye17-Mar-05 4:33 
AnswerRe: Seriously - are you mental ? Pin
dnh31-Mar-05 12:44
memberdnh31-Mar-05 12:44 
GeneralThis won't test which language is faster Pin
Marc Clifton14-Mar-05 14:44
protectorMarc Clifton14-Mar-05 14:44 
GeneralRe: This won't test which language is faster Pin
pascal ganaye14-Mar-05 15:14
memberpascal ganaye14-Mar-05 15:14 
GeneralRe: This won't test which language is faster Pin
SeveredCross14-Mar-05 17:18
memberSeveredCross14-Mar-05 17:18 
GeneralRe: This won't test which language is faster Pin
Christian Graus14-Mar-05 18:05
memberChristian Graus14-Mar-05 18:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 14 Mar 2005
Article Copyright 2005 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid