Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)
New Posts  All Forums:Forum Nav:

Programming Challenge (Out-of-Date) - Page 14  

Poll Results: Are you interested in participating in and/or helping organise and post these programming challenges?

 
  • 100% (2)
    I want to participate.
  • 0% (0)
    I want to contribute by helping posting and organise these challenges.
  • 0% (0)
    I'll only take part if other people are willing to participate.
  • 0% (0)
    I can help and participate - I love programming!
  • 0% (0)
    I do not wish to participate or help.
2 Total Votes  
post #131 of 306
Quote:
Originally Posted by dangerousHobo View Post
Palindrome Crawler in C++
does not handle duplicates, but might fix that later
See C++ can be simple and clean too (and fast)

Code:
#include <iostream>
#include <fstream>
#include <string>

bool compare(const int i, const int k, const std::string s) {
    if (i == k)
        return true;
    if (i + 1 == k)
        return (s[i] == s[k]);
    return (compare(i+1, k-1, s) && s[i] == s[k]);
}

int main(const int argc, const char **argv) {
    std::ifstream inFile;
    inFile.open(argv[1], std::ios::in);
    if (!inFile) exit(1);
    
    std::string s;
    while (!inFile.eof()) {
        inFile >> s;
        std::cout << "EVAL: " << s << std::endl;
        for (int i = 0; i < s.size() - 2; i++) {
            for (int k = i + 2; k < s.size(); k++) {
                if (compare(i, k, s))
                    std::cout << s.substr(i,k+1-i) <<  std::endl;
            }
        }
    }
    inFile.close();

}
That is some nice code I like it.
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #132 of 306
python

Code:
#!/usr/bin/env python
import sys

def main(argv):
    f = open(argv[1], "r")
    for line in f.readlines()[1:]:
        print line[:-1]
        palindromes = set()
        for start in range(0, len(line) - 2): 
            for end in range(start+3, len(line)):
                substring = line[start:end]
                if (substring == substring[::-1]) and (substring not in palindromes):
                    print substring
                    palindromes.add(substring)
        print ''    

if __name__ == "__main__":
    main(sys.argv)

Edited by rabidgnome229 - 7/26/10 at 8:13pm
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
post #133 of 306
Quote:
Originally Posted by rabidgnome229 View Post
python

Code:
#!/usr/bin/env python
import sys

def main(argv):
    f = open(argv[1], "r")
    for line in f.readlines()[1:]:
        print line[:-1]
        palindromes = set()
        for start in range(0, len(line) - 2): 
            for end in range(start+3, len(line)):
                substring = line[start:end]
                if (substring == (substring)[::-1]) and (substring not in palindromes):
                    print substring
                    palindromes.add(substring)
        print ''    

if __name__ == "__main__":
    main(sys.argv)
I like this one too looks so much cleaner then mine and doesn't waste doing the less then 3 like mine does.
Edited by Midpipps - 7/26/10 at 4:50pm
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #134 of 306
now it can handle duplicates, thanks to the STL

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <set>

using namespace std;

bool compare(const int i, const int k, const string& s) {
    if (i == k)
        return true;
    if (i + 1 == k)
        return (s[i] == s[k]);
    return (compare(i+1, k-1, s) && s[i] == s[k]);
}

int main(const int argc, const char **argv) {
    ifstream inFile;
    inFile.open(argv[1], ios::in);
    if (!inFile) exit(1);

    set<string> st;
    pair<set<string>::iterator, bool> ret;
    string s;
    while (!inFile.eof()) {
        inFile >> s;
        cout << "EVAL: " << s << endl;
        for (int i = 0; i < s.size() - 2; i++) {
            for (int k = i + 2; k < s.size(); k++)
                if (compare(i, k, s)) {
                    ret = st.insert(s.substr(i, k+1-i));
                    if (ret.second == true)
                        cout << s.substr(i,k+1-i) << endl;
                }
        }
        st.clear();
    }
    inFile.close();
    return 0;
}
I like the python rabid.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
post #135 of 306
Was looking through all the ones I had and none jumped out as fun for this week so I decided to change it up a little and make one up.

Gonna give xtascox suggestion from this thread to see if we can maybe pull in a few more people.

gonna split into levels so that it can be as hard or easy as you would like.

So here it is.

TIC-TAC-TOE

Make a game of TIC-TAC-TOE

level 1: simple 2 player game
  • can be based in console window if you would like to just make it text based
  • does not have to have a win condition if you do not want to program one.

level 2: 2 player game
  • graphical user interface
  • has a win condition

level 3: player vs computer
  • has to have an system in place for the human player to play against
  • has to have a win condition built into the game part.

Side programming challenge: If I get enough responses I will work on a program to pit computer against computer will make it in C++ or whatever language most people want to use. your program would have to be in a class that I could include and call.
  • How it would work:
    1. instantiation = will be passed in a char of whether you are X or O
    2. data passed to class when getting next move= 3X3 array of chars
    3. returned value = where you would like your piece to go have not figured out exactly what I would do here was thinking maybe a string position 1 = left to right and position 2 = top to bottom
      Example: a return of 02 would be left most bottom cell. etc. 00 left most top cell 20 right most top cell.
just a thought will not worry about it unless I get some replies though.

Head here and weigh in on whether the last few programs have been too easy or not

Next challenge post 8/4/2010

The versus Challenge has a 2 week go so next versus will be: 8/11/2010
Edited by Midpipps - 7/29/10 at 8:15am
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #136 of 306
This one looks fun. Maybe I'll have a co-worker of mine that happens to have a Ph.D. in A.I. give me some tips on the computer controlled aspect
post #137 of 306
How about for the side challenge someone or I will throw together a simple tic-tac-toe server?

Here's my idea:

Code:
>RESTful web services as a listener 

-Wait for two clients to want to start a game
-Assign each a unique id
-Wait for move commands from each client
  --Reject any additional moves sent during a turn
  --When both clients moves have been sent, record each move respectfully
     and then return the following response to the clients:
                ---OpponentMoveGridLocation
                ---MoveSuccessful or MoveFailed
                ---EndGameConditionReached
MoveFailed could most likely be caused by the opponent moving into the spot you wanted.


Ideally you can use any language you are comfortable with as long as you can do HTTP GETs and POSTs with it.


Who knows, we may end up expanding this and allowing for larger grids and multiple concurrent games.
post #138 of 306
Quote:
Originally Posted by xtascox View Post
This one looks fun. Maybe I'll have a co-worker of mine that happens to have a Ph.D. in A.I. give me some tips on the computer controlled aspect
You don't need AI. Just a simple backtracking algorithm etc.
    
CPUMotherboardGraphicsRAM
i7 930 #3951A687 @ 4.1 GIGGLEHERTZ GIGABYTE GA-EX58-UD3R EVGA GTX 470 mushkin 3GB DDR3 1600 7-8-7-20 
Hard DriveOptical DriveOSMonitor
3x Caviar Black 640GB, 2TB, HM160HI, 7200.7 etc. old 52x CD-R I found x64 Windows 7 Ultimate RTM HP w2207h 22" LCD 
KeyboardPowerCaseMouse
Rocketfish Bluetooth Seasonic X-750 Antec Nine Hundred M$ Bluetooth Mouse 5000 
  hide details  
    
CPUMotherboardGraphicsRAM
i7 930 #3951A687 @ 4.1 GIGGLEHERTZ GIGABYTE GA-EX58-UD3R EVGA GTX 470 mushkin 3GB DDR3 1600 7-8-7-20 
Hard DriveOptical DriveOSMonitor
3x Caviar Black 640GB, 2TB, HM160HI, 7200.7 etc. old 52x CD-R I found x64 Windows 7 Ultimate RTM HP w2207h 22" LCD 
KeyboardPowerCaseMouse
Rocketfish Bluetooth Seasonic X-750 Antec Nine Hundred M$ Bluetooth Mouse 5000 
  hide details  
post #139 of 306
Quote:
Originally Posted by chatch15117 View Post
You don't need AI. Just a simple backtracking algorithm etc.
Yes I know, I was over exaggerating
post #140 of 306
Quote:
Originally Posted by chatch15117 View Post
You don't need AI. Just a simple backtracking algorithm etc.
Backtracking will present you with every option, are you planning to rank each outcome?
Things could get interesting if you hashed using a node like structure, adding probability to a given outcome based upon the summation of different outcomes possible after making a given move
Minimax theroem anyone?http://en.wikipedia.org/wiki/Minimax...inimax_theorem
Totally doable...
Setup the webserver and I am in...It will likely be Java however, my C++ is not up to scratch >.<
For sale
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-920 Asus P6T Deluxe Asus GTX460 TOP 768mb G Skill ECO 1600 CAS7 1.35V 
Hard DriveOptical DriveOSMonitor
2x Vertex 60 GB raid[0] Asus DVDRW W7,Ubuntu 2 xAsus VH236H 
KeyboardPowerCaseMouse Pad
Razer Ultra X3 1000W HAF 932 My Desk 
  hide details  
For sale
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-920 Asus P6T Deluxe Asus GTX460 TOP 768mb G Skill ECO 1600 CAS7 1.35V 
Hard DriveOptical DriveOSMonitor
2x Vertex 60 GB raid[0] Asus DVDRW W7,Ubuntu 2 xAsus VH236H 
KeyboardPowerCaseMouse Pad
Razer Ultra X3 1000W HAF 932 My Desk 
  hide details  
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
This thread is locked  
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)