All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Logic
The 8 cards (Posted on 2009-01-31) Difficulty: 2 of 5
You have 8 cards (pieces of paper) numbered from 1 to 8. The first 4 are all white, and the last 4 are all black. On each one is written:

#1: The next two cards are black.
#2: The next two cards are of different colors.
#3: The previous card has the same color as the next.
#4: There are the same number of black cards before and after this one.
#5: The previous card is of the same color as the next.
#6: The previous card is white.
#7: The next two cards are of the same color.
#8: The previous card is black.

Arrange the 8 cards in a row so that all the sentences result truthfully.

See The Solution Submitted by pcbouhid    
Rating: 4.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): Logical solution | Comment 4 of 10 |
(In reply to re: Logical solution by pcbouhid)

PCB,

Since you mention "the time of Cobol...", I'm assuming that was the old cobol, before COBOL II, when it still didn't have an END-IF, but just a period(.) to terminate all and any nested IFs. That, and the lack of substring capability were the worst things about that language for a sensible programmer.  It also allowed insensible programmers to use an ALTER xxx TO PROCEED TO xxx to make debugging impossible. And of course any programming allowing GOTO allows the insensible programmer to wreak havoc, but sometimes a GOTO is the best way to handle something, when used in moderation.

Quick Basic, the language I most often used, and its similar QBasic and Visual Basic (versions 6 and under) all have similar syntax and include the needed END IF, as well as substring handling (as MID$). There is a programming tutorial at http://pages.intnet.mu/jhbpage/Program/Qbasic/tutorial/index.htm, oriented to QBasic, a product very similar to QuickBasic. You can do a Google search for other QuickBasic tutorials.

The IDE (interactive development environment) for QB 4.5 is available for download at various sites: you can do a Google search for that also. A good one is probably http://www.qbcafe.net/qbc/english/download.shtml.

The key to programming these puzzles is to devise a representation of the system, as either numbers or strings, possibly in arrays, in such a way that extraneous solutions are pruned as soon as possible so the execution time does not take forever.  Also, from an execution time point of view QBasic is slower than QuickBasic and QuickBasic is slower than Visual Basic.

Many of the programs I write involve recursion, where either it's not known beforehand how many loops need to be nested, or the number of nests is so large that it's just easier to write one loop and make it recursive.

Some of my programs invoke a PERMUTE subroutine.  I usually don't include that code in the solutions, as one of the Algorithms category puzzles is to devise such an algorithm for permutations.

For special purposes, requiring extra precision math, or use of handy prime number functions, I use UBASIC. Those are the ones in my comments that have line numbers on each line of the program.

Other than that, just examine the programs I have submitted in comments.

  Posted by Charlie on 2009-02-01 14:26:52
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information