0

An assignment is given to prepare a prolog code for the following scenario.

Five bikes with colors Red, Blue, Black, White and Grey are in queue. At least one in front of Red and at least one behind the Blue. At least one in front of Black and at least one behind it. White should be ahead the Blue in the queue. Grey and Blue aren't adjacent to the black.

Here the orientation of these bikes also to be considered. I designed a C++ code and It gives 64 Possible alignments of bikes for the above scenario. However, I'm in a hurry to convert this code as Prolog code.

This is that C++ code I did.

    #include<stdio.h>
    #include<conio.h>
    int main(){
    int i,j,k,l,m,fi,fj,fk,fl,fm; 
    /*
    i (is Red), j (is Blue), k (is Black), l (is White) & m (is Grey) are the bikes and their orientations are fi, fj, fk, fl & fm. fi gives '1' if the bike 'i' is oriented to front. Otherwise it is '0'. Similarly fj,fk,fl & fm. 
    */

    int possibilities=0;
    for(i=0; i<5;i++){
    for(fi=0; fi<2; fi++){
    for(j=0; j<4;j++){
    for(fj=0; fj<2; fj++){
    for(k=1; k<4;k++){
    for(fk=0; fk<2; fk++){
    for(l=0; l<5;l++){
    for(fl=0; fl<2; fl++){
    for(m=0; m<5;m++){
    for(fm=0; fm<2; fm++){
    if((i==j)||(i==k)||(i==l)||(i==m)||(j==k)||(j<=l)||(j==m)||(k==l)||(k==m)||(l==m)||(m==k-1)||(m==k+1)||(j==k-1)||(j==k+1))
    break;
    else{
    possibilities++;
    printf("Red in %d & Front is %d, Blue in %d & Front is %d, Black in %d Front is %d, White in %d & Front is %d, Grey in %d & Front is %d\n",i,fi,j,fj,k,fk,l,fl,m,fm);
    }
    }}}}}}}}}}
    if(possibilities==0){
    printf("No Solutions Found..!");
    }
    printf("There are %d possibilities",possibilities);
    return 0;
    }

Could anyone give a prolog code to display the positions of these bikes..? Thanks in advance

2
Contributors
1
Reply
11
Views
1 Year
Discussion Span
Last Post by rubberman
0

Where is your prolog code? This is C/C++. Prolog is very different. I assume you are speaking of the prolog computer language?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.