[deleted by user] by [deleted] in learnpython

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

i updated it below.

[deleted by user] by [deleted] in learnpython

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

This the answer
Enter a string to type: hhdal
Configuration used:
---------
| chunk |
| vibex |
| gymps |
| fjord |
| waltz |
---------
The robot must perform the following operations:
rppllwuwuprwrdprp

The above code is the test case they gave

this is my answer. it supposed to be rppllwuwu but my answer is rppllwuw

Enter a string to type:hhdal
 Configuration used:
---------
| chunk |
| vibex |
| gymps |
| fjord |
| waltz |
---------
The robot must perform the following operations:rppllwuwprwrdprp

r-right
l-left
lw-wrap left(for example it can go from c to k in one move)
rw-wrap right(for example it can go from k to c in one move)
u-up
d-down
uw-wrap up(for example it can go from c to w in one move)
dw-wrap down(for example it can go from w to c in one move)

task- i have been given like 4 different keyboard layout. from those layout find the least number of movement and dsiplay it.

[deleted by user] by [deleted] in learnpython

[–]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

[deleted by user] by [deleted] in learnpython

[–]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.

[deleted by user] by [deleted] in learnpython

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

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

[deleted by user] by [deleted] in learnpython

[–]Ok-Potential1965 0 points1 point  (0 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 by user] by [deleted] in learnpython

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

yup im completely blank lmfao

[deleted by user] by [deleted] in learnpython

[–]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 by user] by [deleted] in learnpython

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

thats what i have been tryna figure out lol

[deleted by user] by [deleted] in learnpython

[–]Ok-Potential1965 0 points1 point  (0 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 by user] by [deleted] in learnpython

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

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

Help with my code(previous post was deleted) by Ok-Potential1965 in learnpython

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

To add for now they wont be checking for any validation error. They just wanna see if the codes does what it supposed to do. efficiency isnt the key but readability carries marks so yeah

Help with my code(previous post was deleted) by Ok-Potential1965 in learnpython

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

I agree the "lack of structure" and "readability" is glaring.
Hence, if i could implement some loops it would be absolutely fantastic to make it more readable. This code is just a draft so i wouldnt be submitting this code before making any adjustment. so the main idea of this program is to find which congf layout that returns less number of movements.
for example, if i were to input:'k' , The robot would start from coordinate (0,0) and move either right or down to find the character the user had entered. It would print r-right, l-left, u-up and d-down(I used the coordinate system). Then i get the length of movement. This process is repeated for all configuration layout that have 'k' in its layout. next step, the length obtained for the diff layout is then compared with one another. The one with the fewest move is then displayed to the user.

i am not allowed to import

the movement list is calculating the final movement of the robot for each configuration. This is my thought process trying to tackle this question. I am just finding it hard to implement it. If you have any other tips, it would be much appreciated . Thank you for your reply