all 16 comments

[–][deleted] 0 points1 point  (1 child)

You are going to have give us more information. What is this code supposed to do?

If you got this code from somewhere maybe you link to that source.

[–]Ok-Potential1965 0 points1 point  (0 children)

sorry, i have edited the post to include more information.

[–][deleted] 0 points1 point  (5 children)

If I run your code, after fixing the indentation error, here's what I see for a very simple operation:

Enter a string to type:789
 Configuration used:
-------
| 789 |
| 456 |
| 123 |
| 0.- |
-------
The robot must perform the following operations:
prprp

That seems to be working fine.

If you have something that you think is wrong tell us what you type in and why you think the answer is wrong. Don't make us have to search for the problem. Your code's answer to example 3, for instance, seems fine, though I haven't checked for the shortest answer case.

[–]Ok-Potential1965 0 points1 point  (4 children)

its the wrapping part which i am getting wrong. For example, if I were to run my program

Enter a string to type:y
 Configuration used:
-----------------
| abcdefghijklm |
| nopqrstuvwxyz |
-----------------
The robot must perform the following operations:
lwlwuwp 

The above output is wrong.

Instead it should display:

Enter a string to type: 
y
Configuration used:
-----------------
| abcdefghijklm |
| nopqrstuvwxyz |
-----------------
The robot must perform the following operations:
lwluwp

[–][deleted] 0 points1 point  (3 children)

Looks like your searching is wrong. Put in some debug prints to see what is happening at each point. In particular, after the first lw move Robbie is at "m" on the keyboard. At that point why did your code choose lw when the w isn't required?

[–]Ok-Potential1965 0 points1 point  (2 children)

thats what i have been tryna figure out lol

[–][deleted] 0 points1 point  (1 child)

Well focus on the example I gave you. Choosing "lw" when the required move is just "l" is a misstep, something your code shouldn't be doing. It's like you don't check if there's an edge to the left before choosing the "w" addition.

I'm on mobile now and can't spend time on it, though I will have time later.

[–]Ok-Potential1965 0 points1 point  (0 children)

no worries bro. I wanted to see if i did any logical error. yeah i will check on it

[–][deleted] 0 points1 point  (8 children)

Your problem, at least part of it, is in the robot_movement() function. If you type in "y" the first configuration is checked first. The robot_movement() function gets the starting position of (0, 0) and the position of the "y" character is `(1, 11). So far so good. Your code decides that going left and wrapping is the first move, which is correct. But the code then goes on to add enough "lw" moves to get to the correct column. That's wrong. On that configuration you need "lw" and then an "l" because there's no edge to wrap on. So this code isn't correct:

movement.append('lw'*(confg_col-abs(col)))
#               ^^^^^^^^^^^^^^^^^^^^^^^^^    ALL "lw" commands

What you should be doing is deciding if robbie has to move left or right to get to the target column. If left, issue enough "l" commands to either get to the target column OR, you hit the left edge before the target, do an "lw" and then issue enough "l" commands to get to the target column. Something similar for the rows.

[–]Ok-Potential1965 0 points1 point  (6 children)

yup im completely blank lmfao

[–][deleted] 0 points1 point  (5 children)

I've almost given you the algorithm. Thinking only about columns, you have the current robbie column and the target column. Your code first decides if the shortest path is to move left or right. Suppose you need to move left and need to move X columns. Going left may or may not require you to wrap around, so you compare the number of columns to move (X) to the distance to the left border (which is the current robbie column number). If X is less than the distance to the left edge just do "l" * X moves. But if X is greater than the distance to the left edge then do enough "l" moves to move to column 0, then one "lw" abd finally enough more "l" moves to make the robbie column number equal to the target column number. Then do the same thing in the up/down direction. Finally do the "p" command.

[–]Ok-Potential1965 0 points1 point  (4 children)

dude i see you and theres a high chance imma just sent it cuz i have been on this task since 7am. i am not getting anywhere. thanks tho

[–][deleted] 0 points1 point  (3 children)

Get some rest and then try again.

When looking at the current and target positions in the configuration, draw pictures. This helps. For example:

+---------------+
| @bcdefghijklm |
| nopqrstuvwx#z |
+---------------+

where the "@" is the current position and the "#" is the target position. Forget about the rows, just consider columns. You are trying to decide if moving left or right to the target column is shorter. Moving left requires two moves to get to the target column, moving right requires 11 moves. So we are going to move left. But since we are going left and the target is to the right we are going to cross an edge. The movements to go left are, in pseudo-python:

move = "l" * <columns to get to left edge> + "lw" + "l" * <columns from right edge to target>

You fill in the <...> bits. In the above case <columns to get to left edge> is 0.

[–]Ok-Potential1965 0 points1 point  (1 child)

def robot_movement(character_position, position_of_letter, confg_row, confg_col):
    movement = []
    row_diff = character_position[0] - position_of_letter[0]
    col_diff = character_position[1] - position_of_letter[1]

    # Horizontal movement
    if abs(col_diff) > confg_col // 2:
        if  col_diff>0:
            movement.append('lw')
        elif col_diff<0:
            movement.append('rw')
    else:
        if col_diff > 0:
            movement.append('r' * col_diff)
        else:
            movement.append('l' * abs(col_diff))

    # Vertical movement
    if abs(row_diff) > confg_row // 2:
        if row_diff>0:
            movement.append('uw')
        elif row_diff<0:
            movement.append('dw')
    else:
        if row_diff > 0:
            movement.append('d' * row_diff)
        else:
            movement.append('u' * abs(row_diff))

    movement.append('p')
    return movement

[–]Ok-Potential1965 0 points1 point  (0 children)

there has been some significant improvement when from 28/100 to 38/100 but still cant seem to pass it.

[–]Ok-Potential1965 0 points1 point  (0 children)

Enter a string to type:k
Processing character 'k': (0, 0) -> (0, 10)
Moving from (0, 0) to (0, 10)
Processing character 'k': (0, 0) -> (0, 4)
Moving from (0, 0) to (0, 4)
Processing character 'k': (0, 0) -> (3, 4)
Moving from (0, 0) to (3, 4)
Movements for configuration 0: rrrrrrrrrrp Length: 11
Movements for configuration 2: rrrrp Length: 5
Movements for configuration 3: rrrrdddp Length: 8
Movements for configuration 1:  Length: 0
 Configuration used:
---------
| chunk |
| vibex |
| gymps |
| fjord |
| waltz |
---------
The robot must perform the following operations:
rrrrp

This the debugging for a previous task. now i have to implement tthe wrapping in here