Wednesday 6 January 2016

Its a lazy Holiday morning

Particularly I dont know what these Polish people are celebrating, anyway, here is the code for factorisation and checking for a prime number. for the primorial... i got lazy, and stuck probably... but I know y'all geniouses and you can finish it..hehe

dont forget to type exit to quit.

 
#include <iostream>
int fact(int);
bool is_prime(int);
int primorial(int);

using namespace std;

int main()
{
    string choice;
    int a;
    while(choice!="exit"){
    cout << "Choose a code to test" << endl;
    cout << "CODE\t|\tDescription" << endl;
    cout << "fact\t|\tCalculates Factorial" << endl;
    cout << "prime\t|\tChecks if your number is prime or not" << endl;
    cout << "primo\t|\tDescription" << endl;
    cout << "exit\t|\tQuits the program" << endl;
    cin  >>  choice;

        if(choice=="fact"){
        cout << "Enter a number to factorize\n";
        cin  >> a;
        cout << "\nThe factorial is " << fact(a) << endl;}

        if(choice=="prime"){
        cout << "Enter a number\n";
        cin  >> a;
        if(is_prime(a))
            cout <<a<< " is a prime number.\n\n";
        else
            cout <<a<< " is not a prime number.\n\n";}

        if(choice=="primo"){
        cout << "Enter a number to primorialize\n";
        cin  >> a;
        cout << "The primorial is " << primorial(a)<<endl<<endl;}

    }

    return 0;
}


int fact(int x)
{
    if(x==1)
        return x;
    else
        return x*fact(x-1);
}


bool is_prime(int x)
{
    if(x==1)
    return true;
    if(x==2)
    return true;
    for(int y=2; y<x ; y++){
        if(x%y==0)
        return false;
        else
        return true;}
}

int primorial(int x)
{
 ////////smart people.. i need help!!!
}

Tuesday 5 January 2016

IT Work Environment

.
.
.
.
.
In creating a Html, the server needs the file index.html for accessing the file. This file should be in the folder ../public/..
The group permissions for public is x for www.data for execution

Creating the simplest form of a homepage using one line...lol almost nothing in it..
- create the folder "public_html"
- set the permission to be executed
- create a "index.html" in that folder and open it with a text editor
- write the following html code...

<HTML>
<BODY>
Hellow world
</BODY>
</HTML>

nb: html might
- give the file permission 744
- to access this homepage...in your web browser..navigate to your server, and to your username
- in our case... it xor.uni.lodz.pl/~username

To style your text
<HTML>
<HEAD>
<META CHARSET="UTF-8">
</HEAD>
<BODY>
Hellow world
</BODY>
</HTML>

notice the position of the "tag HEAD"
It should be included after before the body. UTF-8 is used for localized characters, in this case, its the best for Polish chars.

Creating an Interactive Table

In the Body write the following html code

<TABLE WIDTH="960" BORDER="1" ALIGN="CENTER">
<TR> <TD ALIGN="CENTER" COLSPAN="2"> Header text </TD> </TR>
<TR> <TD WIDTH="200" HEIGHT="300" VALIGN="TOP"> </TD>
<TD VALIGN="CENTER"> </TD> </TR>
<TR> <TD COLSPAN="2"> </TD> </TR>
</TABLE>

TD- creates a new cell
WIDTH="960"- can also be writen as a percent e.g WIDTH="80%" according to the screen size

--end of lesson--

Tuesday 15 December 2015

Voting Poll Script

as from the example in the lecture


Not much to say...as usual. My blogging-mojo has died off, or should I say...Never born..hehe. anyway. this script is for the voting poll example. Notice, (in the script) there is a #include <iomanip> .As it says, it manipulates the input and output stream. Its work is see on the setprecision(x) code. Clearly from the script, it makes the output to 3 s.f. neat trick.

For those who missed Intro to Comp Sci

I'd like to give a heads in for the questions that may come in the test on 5 Jan. {may might be definite..lol}.

--How many parts does a Turing Machine has--
4. Which are control unit, read/write head, tape which is divided into cells and the machine's alphabet.

--What sequences of steps can a Turing Machine do--
Observing a cell, writing a symbol, moving the read/write head and changing its states.

--Examples of States--
Start,Halt,add,overflow,carry,return etc...

like i said...jus a heads up.

#SwayQuote
Smooth wind, produce weak bamboo. Expect solid diamond 10miles deep.

return 0; 

Tuesday 8 December 2015

Some C++ scripts

If it wasn't for my current mood, i would have pasted the whole code and explained how its understood in this blog.

download scripts here
Countdown by Function recurrance  
Fib Calculator
Filling an array with a function

Some days, are jus hay day. lol.

Ben.

Sunday 22 November 2015

Magic 60



Spilling some secrets aint a big deal... unless they are a part of some government etc.. Well this is the oldest trick in the book. Well if you were directed here, then here is the layout.





And basically how it works..eish.. its best if you watch this video.
Magic 60 - BennySway

 You would see that i programmed the code for this game..
critics say if its done by a computer then its merely just a calculation, but its more impressive when done by a human being, with eyes closed lol. Anyway here is the code if thou needst art...hehe..(th).
======================
 #include<iostream>

using namespace std;

int main()
{
    int n,calc=0,magic=0;
    bool giveup=false;
    char choice,start,theEnd;


    cout<<"Magic 60"<<endl;
    cout<<"Think of a number from 1 to 60.\n";
    cout<<"Shall we proceed?y/n: ";
    cin>>start;

    if(start=='y'){
                cout<<"\n\nType '0' and press enter to quit anytime\n\n\n";
                cout<<"\t\tBox 1.\n";
                            n=-1;
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++){
                        n+=2;
                        //if(n>=60)
                        //break;
                        cout<<n<<"\t";}
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=1;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                            }}
                cout<<endl;
  //initializing the next box2.
    if(giveup!=true){
                cout<<"\t\tBox 2.\n";
                            n=1;        //reseting n
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++)
                        {
                        n+=1;
                        magic+=1;
                        if(magic<=2)cout<<n<<"\t";
                        if(magic==3){
                            n+=2;
                            cout<<n<<"\t";
                            magic=1;}

                        }
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=2;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                    }}

  //initializing the next box3.
    if(giveup!=true){
                cout<<"\t\tBox 3.\n";
                            n=3;        //resetting n
                            magic=0;    //resetting magic
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++)
                        {
                        n+=1;
                        magic+=1;
                        if(n>60){cout<<"23";break;}
                        if(magic<=4)cout<<n<<"\t";
                        if(magic==5){
                            n+=4;
                            cout<<n<<"\t";
                            magic=1;}

                        }
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=4;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                    }}

 //initializing the next box4.
    if(giveup!=true){
                cout<<"\t\tBox 4.\n";
                            n=7;        //resetting n
                            magic=0;    //resetting magic
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++)
                        {
                        n+=1;
                        magic+=1;
                        if(n>60){cout<<"23";break;}
                        if(magic<=8)cout<<n<<"\t";
                        if(magic==9){
                            n+=8;
                            cout<<n<<"\t";
                            magic=1;}

                        }
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=8;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                    }

 //initializing the next box5.
    if(giveup!=true){
                cout<<"\t\tBox 5.\n";
                            n=15;        //resetting n
                            magic=0;    //resetting magic
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++)
                        {
                        n+=1;
                        magic+=1;
                        if(n>60){cout<<"23";break;}
                        if(magic<=16)cout<<n<<"\t";
                        if(magic==17){
                            n+=16;
                            cout<<n<<"\t";
                            magic=1;}

                        }
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=16;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                    }}

 //initializing the next box6.
    if(giveup!=true){
                cout<<"\t\tBox 6.\n";
                            n=31;        //resetting n
                            magic=0;    //resetting magic
                for(int row=1;row<=5;row++){
                    for(int col=1;col<=6;col++)
                        {
                        n+=1;
                        magic+=1;
                        if(n>60){cout<<"23";break;}
                        if(magic<=32)cout<<n<<"\t";
                        if(magic==33){
                            n+=32;
                            cout<<n<<"\t";
                            magic=1;}

                        }
                        cout<<endl;}
                cout<<"\nDid you see youre number?y/n:";
                cin>>choice;
                        if(choice=='y')
                            calc+=32;
                        else if(choice=='n')
                            calc+=0;
                        else{
                                giveup=true;
                                cout<<"Dont believe in magic? Try next time.";
                    }}

//Evaluation
    cout<<"I now know the number youre thinking of...\n\nContinue?y/n:";
    cin>>theEnd;
    if(calc>60)
        cout<<"The number you thought of is indeed greater than 60, we didnt agree on that.\nThanks for playing anyway.";
    if(theEnd=='y'&&calc<=60)
    cout<<"You thought of the number "<<calc;
    if(theEnd=='n')
     cout<<"Dont believe in magic? Try next time.";
            }else
        cout<<"Dont believe in magic? Try next time.";
        //if(choice!='y'||choice!='n'||choice!='0')
          //  cout<<"\n\nThis program malfunctioned because it couldn't understand your input.\nClearly all it needed was a y/n...\nIs it that hard?\n\n";
    return 0;
}

=========================================



All truth cant and shall not stay hidden...unless you pay money for it to stay like that. lol.

Friday 13 November 2015

The Sway Start


There's a beginning for everything, even BennySway blogs here and there. Well I have to leave a trace for those who like my footsteps, not because of the way they look, but the direction they chose in this ever-twisting life. The Sway Start.

I hope its not to late, because there already a lot of people blogging, looks like I'm still weak at the game. Well all games have level, and its better late than never.

https://www.youtube.com/watch?v=dSvPZHRBAKE
I really hope its not too late.