Click here to Skip to main content
15,911,715 members

Comments by Member 14994754 (Top 4 by date)

Member 14994754 8-Jan-21 10:31am View    
i stuck and got error in my coding. I dont know how to solve in logic math.
Member 14994754 8-Jan-21 10:06am View    
#if !defined(EINSTEIN_H__INCLUDED_)
#define EINSTEIN_H__INCLUDED_

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>

//=============================================================================
//
// Definitions...
//
//=============================================================================
#ifdef __TURBOC__
//-----------------------------------------
// Definitions for Borland C++ Compiler
//-----------------------------------------
#include <bios.h>

#define GetKbKey() ( bioskey( 0 ) )
#define GetKbReady() ( bioskey( 1 ) != 0 )
#define keyESCAPE 0x011B
#define keyj 0x246A
#define keyJ 0x244A
#define keyn 0x316E
#define keyN 0x314E
#else
//-----------------------------------------
// Definitions for Microsoft C++ Compiler
//-----------------------------------------
#define GetKbKey() ( _getch() )
#define GetKbReady() ( _kbhit() != 0 )
#define keyESCAPE 0x001B
#define keyy 'y'
#define keyY 'Y'
#define keyn 'n'
#define keyN 'N'
#endif

#define COPYRIGHT "Einstein's Riddle solved in C++ (c)09.12.2003 by Manfred Becker"
#define MIN 0 // Min. number of persons and other things
#define MAX 4 // Max. number of persons and other things
#define MAX_ITEMS 120 // fact(5)=120 possibilities
#define BACKUPFILE "backup.txt"
#define SOLUTIONFILE "solution.txt"

#ifndef FALSE
enum BOOLEAN {FALSE, TRUE};
#endif

#define WITHOUT_BREAK_ON_ERROR FALSE
#define WITH_BREAK_ON_ERROR TRUE

//Garden Owners (Paul , Hank ,Sam, Zick, Luke ),
//Fruit Varieties (Apple, Pear, Nut, Cherry),
//Vegetable varieties (Carrot, Parsley, Gourd, Onion)
//Flower Varieties (Aster, Rose, Tulip, Lily).
// All the values are in in alphabetical order ...

enum OWNER { OWNER_UNKNOWN, LUKE, HANK, PAUL, SAM, ZICK };
enum FRUIT { FRUIT_UNKNOWN, APPLE, CHERRY, NUT, PEAR };
enum VEGETABLE { VEGETABLE_UNKNOWN, CARROT, GOURD, PARSLEY, ONION };
enum FLOWER { FLOWER_UNKNOWN, ASTER, LILY, ROSE, TULIP };
enum GARDENNUMBER { GARDENNUMBER_UNKNOWN, NR1, NR2, NR3, NR4, NR5 };

// Global variables
char sOwner[MAX+2][20] = { " ? ", " luke ", " hank ", " paul ", " sam ", " zick " };
char sFruit[MAX+2][20] = { " ? ", " apple ", " cherry ", " nut ", "pear"};
char sVegetable[MAX+2][20] = { " ? ", " carrot ", " gourd ", " parsley ", " onion "};
char sFlower[MAX+2][20] = { " ? ", " aster ", "lily", " rose ", "tulip" };

// Global hints
char sHint[21][80] =
{
" 1. They grow 12 different varieties.",
" 2. Everybody grows exactly 4 different varieties",
" 3. Each variety is at least in one garden.",
" 4. Only one variety is in 4 gardens.",
" 5. Only in one garden are all 3 kinds of crops.",
" 6. Only in one garden are all 4 varieties of one kind of crops.",
" 7. Pear is only in the two border gardens.",
" 8. Paul's garden is in the middle with no lily.",
" 9. Aster grower doesn't grow vegetables",
"10. Rose growers don't grow parsley.",
"11. Nuts grower has also gourd and parsley.",
"12. In the first garden are apples and cherries.",
"13. Only in two gardens are cherries.",
"14. Sam has onions and cherries.",
"15. Luke grows exactly two kinds of fruit."
"16. Tulip is only in two gardens.",
"17. Apple is in a single garden.",
"18. Only in one garden next to Zick's is parsley.",
"19. Sam's garden is not on the border.",
"20. Hank grows neither vegetables nor asters.",
"21. Paul has exactly three kinds of vegetable."
};

//=============================================================================
//
// All about persons...
//
//=============================================================================
class CPerson
{
private:
// Membervariables of the class
OWNER m_eOwner;
FRUIT m_eFruit;
Member 14994754 8-Jan-21 10:06am View    
/*****************************************************************************\
Einstein's riddle solved in C++ (c)09.12.2003 by Manfred Becker
Compiler: MS-Visual C++ 1.52, 4.0, 5.0, 6.0, C++.net
Borland C++ 3.1, 4.5
/ \ / \ / \ / \ / \
/ \ / \ / \ / \ / \
/ 1 \ / 2 \ / 3 \ / 4 \ / 5 \
/ \ / \ / \ / \ / \
/ GARDEN \ / \ / \ / \ / \
/___________\ /___________\ /___________\ /___________\ /___________\
| | | | | | | | | |
| OWNER. | | | | | | | | |
| FRUIT | | | | | | | | |
| VEGETABLE | | | | | | | | |
| FLOWER | | | | | | | | |
|___________| |___________| |___________| |___________| |___________|

Einstein's riddle...
Five friends have their gardens next to one another, where they grow three kinds of crops:.
fruits (apple, pear, nut, cherry),
vegetables (carrot, parsley, gourd, onion)
flowers (aster, rose, tulip, lily)


The question is: Who has which garden and what is grown where?

The hints...

1. They grow 12 different varieties.
2. Everybody grows exactly 4 different varieties
3. Each variety is at least in one garden.
4. Only one variety is in 4 gardens.
5. Only in one garden are all 3 kinds of crops.
6. Only in one garden are all 4 varieties of one kind of crops.
7. Pear is only in the two border gardens.
8. Paul's garden is in the middle with no lily.
9. Aster grower doesn't grow vegetables.
10. Rose growers don't grow parsley.
11. Nuts grower has also gourd and parsley.
12. In the first garden are apples and cherries.
13. Only in two gardens are cherries.
14. Sam has onions and cherries.
15. Luke grows exactly two kinds of fruit.
16. Tulip is only in two gardens.
17. Apple is in a single garden.
18. Only in one garden next to Zick's is parsley.
19. Sam's garden is not on the border.
20. Hank grows neither vegetables nor asters.
21. Paul has exactly three kinds of vegetable.

The solution...
This program solve the riddle by testing all possibilities (sequences).
These are 120 x 120 x 120 x 120 x 120 = 24.883.200.000
My computer (PentiumIII,700MHz) solve in one Minute:

Compiler | Num.Sequences | Total time
---------+---------------+------------------------
TC++ 1.0 | 44.529.916 | 9 hr. 19 min.
BC++ 3.1 | 44.588.157 | 9 hr. 18 min.
BC++ 4.5 | 1.632.593 | 10 days 14 hr. 1 min.
MCSV15 | 704.187 | 24 days 12 hr. 56 min.
MSVC60 | 6.187.477 | 2 days 19 hr. 1 min.
MSVC.net | 6.151.717 | 2 days 19 hr. 24 min.

Einstein wrote this riddle last century.
He said that 98% of the world could not solve it.

Could you?

\*****************************************************************************/


#include "einstein.h"


//=============================================================================
//
// main-Routine
//
//=============================================================================

//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
//-----------------------------------------------------------------------------
{
CEinsteinsRiddle EinsteinsRaetsel( BACKUPFILE, SOLUTIONFILE );

return EinsteinsRaetsel.Solve(argc, argv);
}

//=============================================================================
//
// All about perso
Member 14994754 8-Jan-21 9:15am View    
i already try but i dont know how to settle in math logic.Kindly please help me.