C/C++ Coding challenges

Enigma_1

Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    hello friends this is my answer to dat problem..
    i used an integer array for the conversion process.
    :)

    //(c)dURA :)
    #include<iostream>
    using namespace std;

    int main()
    {
    int now,x,j;
    begin:

    const int size=20;
    int no[size]={0};

    cout<<"Please enter the integer value : ";
    cin>>x;

    now=x;
    int i=0;
    for(i=0;;i++)
    {
    if (now==0) break;
    no=now%16;
    now=now/16;
    if (now<16 and now>0)
    {i=i+1;no=now;break;}
    }

    cout<<"\nhexadecimal representation of "<<x<<" is 0x";

    for(j=i;j>=0;j--)
    {
    if (no[j]>9)
    {
    switch (no[j]){
    case 10 : cout<<"A";break;
    case 11 : cout<<"B";break;
    case 12 : cout<<"C";break;
    case 13 : cout<<"D";break;
    case 14 : cout<<"E";break;
    case 15 : cout<<"F";break;
    default : cout<<"Z";break;
    }
    }
    else cout<<no[j];
    }

    cout<<"\n\t\t____\n\n";
    goto begin;
    }


    ela kiri machan. :yes::yes::yes::yes:
     

    cyber22118

    Member
    Jan 30, 2010
    3,569
    99
    0
    Not Far From U
    i love to post some thing here but my A/L exam is next week.. so I cant spend so much time with my com.. :( :( .. ill post some really good algos like face recog and shit after my exam.. Enigma_1 , u should put some avatar for your profile.. u are doing a good work.. a lot of people started this kind of threads but they didn't last more than 2 days.. grt wrk..
     

    Enigma_1

    Junior member
  • Feb 5, 2008
    70
    3
    8
    Colombo
    i love to post some thing here but my A/L exam is next week.. so I cant spend so much time with my com.. :( :( .. ill post some really good algos like face recog and shit after my exam.. Enigma_1 , u should put some avatar for your profile.. u are doing a good work.. a lot of people started this kind of threads but they didn't last more than 2 days.. grt wrk..

    thx for the encouragement machan. Yeah I will add an avatar to my profile. Wishing you all the best for your exam. :D:D:D
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Lets do a new challenge shall we? This is just a thought; a random one!
    Use your skills of programming to determine the path to take to get from point A to point B in a given maze of 0s and 1s. 1s mark walls and 0s mark paths that you can go through.

    points A, B are given in (x,y) format.
    The maze and points A,B will be(usually) given in a text file in the following format.
    Code:
    Ax,Ay,Bx,By
    110111
    100101
    100001
    100100
    110111
    in this case Ax=2, Ay=4, Bx=5, By=3 (these values should be in the text file, it is shown as letters for easy readability)

    The maze will be rectangular in shape and will vary in size.

    About the maze.
    The maze is designed in a way that the correct path is achieved by only using horizontal, vertical travel and 90 degree turning(much easier!)

    Your algorithm should get the right way and it should be outputted to the screen as messages like this(like when you answer a direction question)

    Go Straight n blocks
    Turn Left
    Turn Right

    The path as a list of positions[(x,y)] is also accepted :D

    HINT:



    I'm thinking of an recursive method as of now, but hey there can be better ones!

    NOTE: I didn't code this yet, I won't code it today may be -- I'd only think of it today :P anyways try this! These are the practical implementations of algorithms you'd need these in the future.

    ANOTHER NOTE: Those who what to wonder about can make some modifications and make this algorithm a 'maze solver'--it wont need a B position, it'd be able to get out of the maze where ever it starts from :P(if a path exists)
     
    Last edited:

    DURApix

    Well-known member
  • Aug 1, 2010
    1,259
    192
    63
    /dev/null
    Lets do a new challenge shall we? This is just a thought; a random one!
    Use your skills of programming to determine the path to take to get from point A to point B in a given maze of 0s and 1s. 1s mark walls and 0s mark paths that you can go through.

    points A, B are given in (x,y) format.
    The maze and points A,B will be(usually) given in a text file in the following format.
    Code:
    Ax,Ay,Bx,By
    110111
    100101
    100001
    100100
    110111
    in this case Ax=2, Ay=4, Bx=5, By=3 (these values should be in the text file, it is shown as letters for easy readability)

    The maze will be rectangular in shape and will vary in size.

    About the maze.
    The maze is designed in a way that the correct path is achieved by only using horizontal, vertical travel and 90 degree turning(much easier!)

    Your algorithm should get the right way and it should be outputted to the screen as messages like this(like when you answer a direction question)

    Go Straight n blocks
    Turn Left
    Turn Right

    The path as a list of positions[(x,y)] is also accepted :D

    HINT:



    I'm thinking of an recursive method as of now, but hey there can be better ones!

    NOTE: I didn't code this yet, I won't code it today may be -- I'd only think of it today :P anyways try this! These are the practical implementations of algorithms you'd need these in the future.

    machan I didnt got the idea Correctly??
    2.gif

    pls can u give an example??
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    machan I didnt got the idea Correctly??
    2.gif

    pls can u give an example??

    ok heres one, this is the text file that u input to the program.

    0,0,6,3

    0111111
    0000011
    0100011
    0111000
    0000101

    and this is the output

    Go straight 1 block(s)
    Turn Left
    Go straight 4 block(s)
    Turn Right
    Go straight 2 block(s)
    Turn Left
    Go straight 2 block(s)

    thats all :D
    NOTE: the red 0 is at (0,0)
     

    cyber22118

    Member
    Jan 30, 2010
    3,569
    99
    0
    Not Far From U
    Lets do a new challenge shall we? This is just a thought; a random one!
    Use your skills of programming to determine the path to take to get from point A to point B in a given maze of 0s and 1s. 1s mark walls and 0s mark paths that you can go through.

    points A, B are given in (x,y) format.
    The maze and points A,B will be(usually) given in a text file in the following format.
    Code:
    Ax,Ay,Bx,By
    110111
    100101
    100001
    100100
    110111
    in this case Ax=2, Ay=4, Bx=5, By=3 (these values should be in the text file, it is shown as letters for easy readability)

    The maze will be rectangular in shape and will vary in size.

    About the maze.
    The maze is designed in a way that the correct path is achieved by only using horizontal, vertical travel and 90 degree turning(much easier!)

    Your algorithm should get the right way and it should be outputted to the screen as messages like this(like when you answer a direction question)

    Go Straight n blocks
    Turn Left
    Turn Right

    The path as a list of positions[(x,y)] is also accepted :D

    HINT:



    I'm thinking of an recursive method as of now, but hey there can be better ones!

    NOTE: I didn't code this yet, I won't code it today may be -- I'd only think of it today :P anyways try this! These are the practical implementations of algorithms you'd need these in the future.

    ANOTHER NOTE: Those who what to wonder about can make some modifications and make this algorithm a 'maze solver'--it wont need a B position, it'd be able to get out of the maze where ever it starts from :P(if a path exists)

    thats the simplest basic of satellite navigation... lets see who solves this..
     

    DURApix

    Well-known member
  • Aug 1, 2010
    1,259
    192
    63
    /dev/null
    ok heres one, this is the text file that u input to the program.

    0,0,6,3

    0111111
    0000011
    0100011
    0111000
    0000101

    and this is the output

    Go straight 1 block(s)
    Turn Left
    Go straight 4 block(s)
    Turn Right
    Go straight 2 block(s)
    Turn Left
    Go straight 2 block(s)

    thats all :D
    NOTE: the red 0 is at (0,0)

    machan meka tikak amaaru cake 1k wage :nerd:
    mama hitana widiyata machan
    meka karanna 2D array ekak use karanna wenawa neda?
    without OOP C++, meka karanna puluwanda??
    mokoda tauma apita OOP karala naha.:confused:
     

    croshanlg

    Member
    Jan 7, 2008
    2,665
    285
    0
    6° 54' N 79° 52' E
    Hey friends... it’s so nice to see the thread has gone so well. I was very interested about this thread when I first saw it. I was little busy last few days, but I’m free now & I’m looking forward to post more in this great thread. I give this very simple question as my first challenge to this thread. :yes:
    Ok. All you have to do is to build a national ID card validate & birth day extractor algorithm.
    1. Algorithm must validate a particular string is valid national ID number.
    2. If it is valid, then the algorithm must output the birthday of the person.

    INPUT ------------------------> Validate & extract b’day ---------------------> OUTPUT (b'day of ID card holder)
    (ID number)

    Guess this one will be a piece of cake for you. Anyway I’ll post the answer within next few days. Let’s see which one of us has the best algorithm. :yes:
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    The maze source: http://www.sendspace.com/file/y22h0b

    sample output
    + marks where it went before
    * marks where it is currently

    use
    Code:
    gcc -I. -o maze maze.c ll.c
    to compile using gcc

    Code:
    0 0 5 4 9 5
    *00000011
    011110000
    011000010
    111101110
    000000111
    
    +*0000011
    011110000
    011000010
    111101110
    000000111
    
    ++*000011
    011110000
    011000010
    111101110
    000000111
    
    +++*00011
    011110000
    011000010
    111101110
    000000111
    
    ++++*0011
    011110000
    011000010
    111101110
    000000111
    
    +++++*011
    011110000
    011000010
    111101110
    000000111
    
    ++++++*11
    011110000
    011000010
    111101110
    000000111
    
    +++++++11
    011110*00
    011000010
    111101110
    000000111
    
    +++++++11
    011110+*0
    011000010
    111101110
    000000111
    
    +++++++11
    011110++*
    011000010
    111101110
    000000111
    
    +++++++11
    011110+++
    01100001*
    111101110
    000000111
    
    +++++++11
    011110+++
    01100001+
    11110111*
    000000111
    
     r0
     r0
     r0
     r0
    +++++++11
    01111*+++
    01100001+
    11110111+
    000000111
    
    +++++++11
    01111++++
    01100*01+
    11110111+
    000000111
    
    +++++++11
    01111++++
    01100+*1+
    11110111+
    000000111
    
     r0
    +++++++11
    01111++++
    0110*++1+
    11110111+
    000000111
    
    +++++++11
    01111++++
    011*+++1+
    11110111+
    000000111
    
     r0
    +++++++11
    01111++++
    011++++1+
    1111*111+
    000000111
    
    +++++++11
    01111++++
    011++++1+
    1111+111+
    0000*0111
    Go 6 blocks right 
    Go 1 blocks down 
    Go 1 blocks left 
    Go 1 blocks down 
    Go 1 blocks left 
    Go 2 blocks down 
    Go 2 blocks right
     
    Last edited:

    DURApix

    Well-known member
  • Aug 1, 2010
    1,259
    192
    63
    /dev/null
    help needed

    Hey friends... it’s so nice to see the thread has gone so well. I was very interested about this thread when I first saw it. I was little busy last few days, but I’m free now & I’m looking forward to post more in this great thread. I give this very simple question as my first challenge to this thread. :yes:
    Ok. All you have to do is to build a national ID card validate & birth day extractor algorithm.
    1. Algorithm must validate a particular string is valid national ID number.
    2. If it is valid, then the algorithm must output the birthday of the person.

    INPUT ------------------------> Validate & extract b’day ---------------------> OUTPUT (b'day of ID card holder)
    (ID number)

    Guess this one will be a piece of cake for you. Anyway I’ll post the answer within next few days. Let’s see which one of us has the best algorithm. :yes:


    this is very interesting challenge for me. I like to program it using c. but the problem is i dont know how to get the relevant details from dat NIC no.:confused:
    pls anyone can post the algorithm to filter those things. I mean i dont want the coding.. ;) I only need the way to get those important details from da NIC.

    thanx
    dURA
     

    amilabanuka

    Well-known member
  • Sep 30, 2006
    7,291
    878
    113
    Thama math hoyanooo....
    this is very interesting challenge for me. I like to program it using c. but the problem is i dont know how to get the relevant details from dat NIC no.:confused:
    pls anyone can post the algorithm to filter those things. I mean i dont want the coding.. ;) I only need the way to get those important details from da NIC.

    thanx
    dURA

    first two digits: birth year

    next three digits: birth day n sex:
    if the value is greater than 500 it is female else male
    if > 500 then reduce 500 to take the birth day.
    for ex: 80509xxxxv
    a girl born in 1980 Janu 09:

    last four digits: registration code

    hope this help