PHP ile her x harfi konumunu kullanarak bir dize yeniden düzenlemek

0 Cevap php

Ben "abcdefghi" bir örnek giriş dizesi ve x olan 4 DHCIFEGBA doğuracak şekilde her x konumunu kullanarak bir dize yeniden düzenlemek için nasıl anlamaya çalışıyorum. İşte bunu anladım nasıl:

The 1st letter is easy: it's character 4. [A, B, C, D]
The 2nd letter is also easy: it's character 8. [E, F, G, H]
The 3rd letter is mostly easy: it's character 3. This happens because I looped around as I counted, so I used I, A, B, C.
The 4th letter is where things get trickier: It's character 9. Because D and H are already gone, they don't get used in the count, resulting in E, F, G, I.
Letter #5 follows the same pattern, skipping C and D: A, B, E, F
Letter #6 has skips AND a wrap: G, A, B, E.
Letter #7 wraps again: G, A, B, G.
Letter #8 also wraps (technically twice since 'cursor' was behind G before: A, B, A, B
Letter #9 is our remainder: A, A, A, A


It's clearly going to need to loop until output string length matches input string length - it's all of this mess in the middle (Mostly the skips and loops) that I can't for the life of me figure out.

Herhangi bir yardım veya rehberlik takdir edilmektedir.

0 Cevap