Solved LeetCode program · 954 of 1,000
#1320 · Minimum Distance to Type a Word Using Two Fingers
Original English source
Keep a shared word as empty text. Keep a shared seeds as an empty list of text. Keep a shared alphabet as empty text. Keep a shared letters as an empty list of text. Keep a shared gaps as an empty list of whole numbers. Keep a shared costs as an empty list of whole numbers. Keep a shared nexts as an empty list of whole numbers. Keep a shared key of 0. Place "CAKE" into seeds. Set word to item 0 of seeds. Place "ABCDEFGHIJKLMNOPQRSTUVWXYZ" into letters. Set alphabet to item 0 of letters. For every cell from 0 to 728, Place 0 into gaps. For every cell from 0 to 728, Place 1000000 into costs. For every cell from 0 to 728, Place 1000000 into nexts.
To locate from spot (a whole number). The symbol is character spot of word. Set key to 0.
For every look from 0 to 25.
The candidate is character look of alphabet. If candidate is symbol, Set key to look.
To improve from one (a whole number) with two (a whole number) and goal (a whole number). The here is one times 27 plus two. The value is item here of costs.
If value is less than 1000000.
The reach is value plus item (one times 27 plus goal) of gaps. The slot is goal times 27 plus two. If reach is less than item slot of nexts, Set item slot of nexts to reach.
To improveother from one (a whole number) with two (a whole number) and goal (a whole number). The here is one times 27 plus two. The value is item here of costs.
If value is less than 1000000.
The reach is value plus item (two times 27 plus goal) of gaps. The slot is one times 27 plus goal. If reach is less than item slot of nexts, Set item slot of nexts to reach.
To relax from one (a whole number) with two (a whole number) and goal (a whole number). Improve from one with two and goal. Improveother from one with two and goal.
To advance from goal (a whole number). For every cell from 0 to 728, Set item cell of nexts to 1000000.
For every one from 0 to 26.
For every two from 0 to 26.
Relax from one with two and goal.
To adopt.
For every cell from 0 to 728.
Set item cell of costs to item cell of nexts. Set item cell of nexts to 1000000.
For every one from 0 to 26.
For every two from 0 to 26.
The rowone is one divided by 6. The colone is one modulo 6. The rowtwo is two divided by 6. The coltwo is two modulo 6. The raw is the absolute value of (rowone minus rowtwo) plus the absolute value of (colone minus coltwo). If one is 26 or two is 26, Set item (one times 27 plus two) of gaps to 0, otherwise Set item (one times 27 plus two) of gaps to raw.
Locate from 0. Set item (key times 27 plus 26) of costs to 0. The start is 1.
Repeat while start is less than 4.
Locate from start. The goal is key. Advance from goal. Adopt. Increase start by 1.
The best is 1000000.
For every cell from 0 to 728.
The value is item cell of costs. If value is less than best, Set best to value.
Show best.
Expected stdout
3