Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3695970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:40:55+00:00 2026-05-19T04:40:55+00:00

This question is messy, i dont need a working solution, i need some psuedo

  • 0

This question is messy, i dont need a working solution, i need some psuedo code.

How would i solve this maze? This is a homework question. I have to get from point green to red. At every fork i need to ‘spawn a thread’ and go that direction. I need to figure out how to get to red but i am unsure how to avoid paths i already have taken (finishing with any path is ok, i am just not allowed to go in circles).

Heres an example of my problem, i start by moving down and i see a fork so one goes right and one goes down (or this thread can take it, it doesnt matter). Now lets ignore the rest of the forks and say the one going right hits the wall, goes down, hits the wall and goes left, then goes up. The other thread goes down, hits the wall then goes all the way right. The bottom path has been taken twice, by starting at different sides.

How do i mark this path has been taken? Do i need a lock? Is this the only way? Is there a lockless solution?

Implementation wise i was thinking i could have the maze something like this. I dont like the solution because there is a LOT of locking (assuming i lock before each read and write of the haveTraverse member). I dont need to use the MazeSegment class below, i just wrote it up as an example. I am allowed to construct the maze however i want. I was thinking maybe the solution requires no connecting paths and thats hassling me. Maybe i could split the map up instead of using the format below (which is easy to read and understand). But if i knew how to split it up i would know how to walk it thus the problem.

How do i walk this maze efficiently?

The only hint i receive was dont try to conserve memory by reusing it, make copies. However that was related to a problem with ordering a list and i dont think the hint was a hint for this.

class MazeSegment
{
    enum Direction { up, down, left, right}
    List<Pair<Direction, MazeSegment*>> ConnectingPaths;
    int line_length;
    bool haveTraverse;
}

MazeSegment root;

class MazeSegment
{
    enum Direction { up, down, left, right}
    List<Pair<Direction, MazeSegment*>> ConnectingPaths;
    bool haveTraverse;
}

void WalkPath(MazeSegment segment)
{
    if(segment.haveTraverse) return;
    segment.haveTraverse = true;
    foreach(var v in segment)
    {
        if(v.haveTraverse == false)
            spawn_thread(v);
    }
}

WalkPath(root);

alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:40:56+00:00Added an answer on May 19, 2026 at 4:40 am

    You can do this using the usual “read, calculate new value, compare-and-swap, repeat until CAS succeeds” method commonly found in lock-free programming.

    All grid-squares in your maze start should hold a pointer representing the direction to move to reach the exit. Initially they all are “unknown”.

    Walk the maze starting at the exit. On each square reached, use compare and swap to replace “unknown” with the direction to the square this thread previously processed. If CAS fails, you’ve got a loop, prune that branch. If CAS succeeds, continue forward. When you assign a direction to the entrance, you now can follow the path to the exit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question would probably apply equally as well to other languages with C-like multi-line
This question was very helpful, however I have a list control in my report,
Note: This is a follow up to this question . I have a legacy
This question is kind of an add-on to this question In C#, a switch
This question and answer shows how to send a file as a byte array
This question comes on the heels of the question asked here . The email
This question is a follow up to my previous question about getting the HTML
(This question is over 6 years old and probably no longer has any relevance.)
This question is about removing sequences from an array, not duplicates in the strict
This question is the other side of the question asking, How do I calculate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.