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 8775517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:49:08+00:00 2026-06-13T18:49:08+00:00

I’m trying to resolve this for fun but I’m having a little bit of

  • 0

I’m trying to resolve this for fun but I’m having a little bit of trouble on the implementation, the problem goes like this:

Having n stacks of blocks containing m blocks each, design a program in c that controlls a robotic arm that moves the blocks form an inicial configuration to a final one using the minimum amount of movements posible, your arm can only move one block at a time and can only take the block at the top of the stack, your solution should use either pointers or recursive methods

In other words the blocks should go from this(suposing there are 3 stacks and 3 blocks):

| || || |
|3|| || |
|2||1|| |

to this:

| ||1|| |
| ||2|| |
| ||3|| |

using the shortest amount of movements printing each move

I was thinking that maybe I could use a tree of some sorts to solve it (n-ary tree maybe?) since that is the perfect use of pointers and recursive methods but so far it has proved unsuccesfull, I’m having lots of trouble defining the estructure that will store all the movements since I would have to check every time I want to add a new move to the tree if that move has not been done before, I want each leaf to be unique so when I find the solution it will give me the shortest path.

This is the data structure I was thinking of:

typedef struct tree(
char[MAX_BLOCK][MAX_COL] value;    
struct tree *kids
struct tree *brothers;
)Tree;

(I’m really new at C so sorry beforehand if this is all wrong, I’m more used to Java)

How would you guys do it? Do you have any good ideas?

  • 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-06-13T18:49:10+00:00Added an answer on June 13, 2026 at 6:49 pm

    You have the basic idea – though I am not sure why you have elected to choose brothers over the parent.

    You can do this problem with a simple BFS search, but it is a slightly less interesting solution, and not the one you for which seemed to have set yourself up.

    I think it will help if we concisely and clearly state our approach to the problem as a formulation of either Dijkstra’s, A*, or some other search algorithm.

    If you are unfamiliar with Dijkstra’s, it is imperative that you read up on the algorithm before attempting any further. It is one of the foundational works in shortest path exploration.

    With a familiarity of Dijkstra’s, A* can readily be described as

    Dijsktra’s minimizes distance from the start. A* adds a heuristic which minimizes the (expected) distance to the end.

    With this algorithm in mind, lets state the specific inputs to an A* search algorithm.

    Given a start configuration S-start, and an ending configuration S-end, can we find the shortest path from S-start to S-end given a set of rules R governed by a reward function T

    Now, we can envision our data structure not as a tree, but as a graph. Nodes will be board states, and we can transition from state to state using our rules, R. We will pick which edge to follow using the reward function T, the heuristic to A*.

    What is missing from your data-structure is the cost. At each node, you will want to store the current shortest path, and whether it is finalized.

    Let’s make a modification to your data-structure which will allow us to readily traverse a graph and store the shortest path information.

    typedef struct node {
      char** boardState;
      struct node *children;
      struct node *parent;
      int distance;
      char status; //pseudo boolean
    } node;
    

    You may want to stop here if you were interested in discovering the algorithm for yourself.

    We now consider the rules of our system: one block at a time, from the top of a stack. Each move will constitue an edge in our graph, whose weight is governed by the shortest number of moves from S-begin plus our added heuristic.

    We can then sketch a draft of the algorithm as follows:

    node * curr = S-begin;
    while (curr != S-end) {
      curr->status == 'T'; //T for True
      for(Node child : children) {
         // Only do this update if it is cheaper than the 
         int updated = setMin(child->distance, curr->distance + 1 + heuristic(child->board));
         if(updated == 1) child->parent = curr;  
      } 
      //set curr to the node with global minimum distance who has not been explored
    }
    

    You can then find the shortest path by tracing the parents backwards from S-end to S-begin.

    If you are interested in these types of problems, you should consider taking a uppergraduate level AI course, where they approach these types of problems 🙂

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but

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.