Pages

Modified Eight Queen Problem

Problem
Suppose that you have a chess board and eight queens. The squares of the chess board being (1,1) to (8,8). Now you have to place the queens such that they could not attack eachother(no queen should be able to attack any other).

Solution
/*
 * File:   main.cpp
 * Author: power
 *
 * Created on January 19, 2012, 2:38 PM
 */

#include <cstdlib>
#include <iostream>
using namespace std;
class point{
public:
    point(){
        this->x=0;
        this->y=0;
    }
    point(int x,int y){
        this->x=x;
        this->y=y;
    }
    int x;
    int y;
    void setx(int a){
        this->x=a;
    }
    void sety(int a){
        this->y=a;
    }
    void display(){
        cout<<"("<<x<<","<<y<<")";
    }
}; 

point* p(char x,char y);
void solution(point *p,int size,point *store[],point *a[]);
bool nonattack(point *p, point *q,int size);
void display(point *p);
void solve(point*[]);
bool chkPredefined(point *c,point *pre[]);
int main(int argc, char** argv) {
    point *po[8]={p('1','8'),p('2','4'),p('3','C'),p('4','D'),p('5','E'),p('6','F'),p('7','G'),p('8','H')};
    solve(po);
    return 0;
}
bool chkPredefined(point *c,point *pre[]){
    point *q=c;
    for(int i=0;i<8;i++){
        if(pre[i]->x!=0){
            if(pre[i]->x!=q->x){
                //cout<<"Returning false1"<<endl;
                return false;
            }
        }
        if(pre[i]->y!=0){
            if(pre[i]->y!=q->y){
                //cout<<"returning false2"<<endl;
                return false;
            }
        }
        q+=1;
    }
    return true;
}
void solve(point *a[]){
    point p[8];
    point *store[8];
    //initialization
    for(int i=1;i<=8;i++){
        p[i-1].x=i;
    }
    solution(p,8,store,a);
    //return 0;
   
}
void solution(point *c,int size,point *store[],point *a[]){
    static int st=0;
    if(size==0){
        //display(c-8);exit(1);
        return;
    }else{
        int i=0;
        while(i++<8){
            c->y=i;
            //recdisplay(c,8);
            //display(c);return;
            //display(c);return;
            //cout<<c->y;
            //continue;
            solution((c+1),size-1,store,a);
            if(size==1)
                if(nonattack(c-7,(c-6),7)){
                    if(chkPredefined(c-7,a)){
                        cout<<st++<<" :";
                        display(c-7);
                    }else{
                        continue;
                    }
                }else{
                    continue;
                }
           
        }
    }
}
bool nonattack(point *c, point *others,int size){
    /*returns true if queens are in non attacking condition*/
   
    if(size==0){
        //cout<<size<<endl;
        //recdisplay(others-1,1);exit(1);//display last one
        return true;
    }else{
        int y=c->y;
        int y1=others->y;
        int x=c->x;
        int x1=others->x;
       
        if(y==y1){return false;}//attack
        if((y1-y)==(x1-x)){return false;}
        if((y1-y)==(x-x1)){return false;}
        if(nonattack(c,(others+1),size-1)&& nonattack(others,others+1,size-1)){
            return true;
        }else{
            return false;
        }
    }
}
void display(point *p){
    point *q;//=p;
    q=p;
    for(int i=0;i<8;i++){
        cout<<"("<<q->x<<","<<q->y<<")  ";
        q=q+1;
    }
    cout<<endl;
}
point*  p(char x,char y){
    //cout<<x<<y<<endl;
    int xt=0,yt=0;
    if(x>'0'&&x<='9'){
        xt=x-'0';
    }
    if(y>'0'&&y<='9'){
       yt=y-'0';
    }
    return new point(xt,yt);
}

Text to audio


 Introduction
 One day while sitting and reading a story on my laptop, it occurred to me that how awesome it would be if instead of reading all the text word by word, the computer would read it for me. Even it could generate a audio file (eg:- story.wav ) so that I could transfer it on my mobile and hear it whenever I am free without having to open my Laptop. I could use the same Audio as a dialog for my animation project.
Solution
Well, obviously, the next step was to google, search learn try then again search. There were several interesting solutions. One of them is the command called
espeak
To read a file type,( cd to the directory )
espeak <filename>
The general and simple syntax of the command is
espeak -v <voice_tone_name> -s <speed_per_minute> -f <text_file_name> -w <wave_file_name_desired>
Open a terminal, and type in the command to see/hear the magic.
For command documentation and options
espeak -h
 You can see the list of voices with
espeak --voices
This command has proved to be a great fun to me and hope you will enjoy using it too.

Assignment 3 | A sample firewall rules declaration example



#---------start of pf.conf------------------
intface="em0"
tcp_pass={ 80, 25, 22 }
udp_pass={ 110, 631 }
 table <good_guys> persist file  "/etc/good_guys"
 table <bad_guys> { 192.168.56.102/24 }

ASSIGNMENT 1 LAB 4




Tables provide a way for incresing the performance and flexibility of rules with lare number of sources and destinatio n addresses.
    Deceleration
        table <local> { 192.168.56.10/24,192.168.9.0/32 }
        table <good_guys> persist file "/etc/good_guys"
    Rules