Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random C++ code

Name: Anonymous 2009-01-26 14:02

LocationList& Graph::bfSearchForShortestPath(const Location &s, const Location &d, LocationList &route){
    deque<Node> t;
    Node v;
    Node v_next;
    int i;
    nodes[s].visited=true;
    nodes[s].pred=Location(0,0);
    t.push_back(nodes[s]);
    while(!t.empty() && nodes[t[0].loc].loc!=nodes[d].loc){
        v=t[0];
        v_next=nodes[v.adjList[0]];
        i=1;
        while(i<v.adjList.size() && v_next.visited){
            v_next=nodes[v.adjList[i]]; i++;
        }
        if (!v_next.visited){
            nodes[v_next.loc].visited=true;
            nodes[v_next.loc].pred=v.loc;
            t.push_back(v_next);
        } else {
            t.pop_front();
        }
    }
    if (t.empty()) throw UnexpectedStateException("No Route");
    route.clear();
    v=nodes[d];
    while(v.loc!=s){
        route.push_front(v.loc);
        v=nodes[v.pred];
    }
    route.push_front(s);
    return route;
}


Because I know everybody here loves C++ so much, have some random code.

Name: Anonymous 2009-01-26 14:03

NO EXCEPTIONS

Name: Anonymous 2009-01-26 14:22

How the hell do I do random numbers in haskell? In C, LISP it's all so simple, no stupid generators, just a range. What the heck haskell.

Name: Anonymous 2009-01-26 14:27

Name: Anonymous 2009-01-27 14:50

cout << "Hello World" << endl;

EXPERT PROGRAMMER

Name: Anonymous 2009-01-27 17:18

>>3
it's pretty simple in haskell, too:
GHCi, version 6.8.3: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :m + Random
Prelude Random> putStrLn . show =<< randomRIO ((1,12) :: (Int,Int))
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Loading package random-1.0.0.0 ... linking ... done.
5


__   __ __  __  ____   ___      _________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
||   || Version: September 2006 _________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Type :? for help
Hugs> :l Random
Random> putStrLn . show =<< randomRIO ((1,12) :: (Int,Int))
10

Name: Anonymous 2009-01-27 17:22

>>6
putStrLn . show
It's called print.

Name: Anonymous 2009-01-27 18:04

Prelude> do print =<< "Hello World" =<< endl; end

Name: Anonymous 2009-01-27 20:53

That's pretty impressive for random code. How long it took before the first compilable program came out?

Name: Anonymous 2009-01-27 22:14

>>8
What the FUCK is that/!?!

Name: Anonymous 2009-01-27 22:18

>>8
EXPERT HASKELL++ PROGRAMMER

Name: Anonymous 2009-01-28 9:06

>>9
Not too long, after all it was mostly a conversion from pseudocode to C++. A stupid mistake - using v_next instead of nodes[v_next.loc] took some time to figure out, but it compiled fine with that error too.
nodes being a map<Location,Node> and v_next just being a Node that made sense, but obviously the visited-attribute wouldn't be saved. I know, a stupid mistake, but I don't consider myself an EXPERT yet.

Name: Anonymous 2009-01-28 9:11

>>12
I don't think you understood >>9.

Name: Anonymous 2009-01-28 10:27

>>13
Now that you mention it...
FUCK!

Name: Anonymous 2009-03-06 7:59

The one in forums   experience writing HUGE   Programs that you   insert into your   code Lastly hunt   down some good   books to learn   it anyway because   I know that   there is a   bullshit sub cons?

Name: ​​​​​​​​​​ 2010-10-23 21:20

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List