![]() |
VOOZH | about |
Given a target string 'S', the task is to generate random strings of the same length as 'S' until the generated string exactly matches the target. For Example:
Input: hello
Output:
jfus
flsf
sowe
hello
Target matched after 3 iterations
Let's look at the different methods below:
This approach starts with a random string and slowly evolves it toward the target string. It changes one character at a time and only keeps changes that make the string closer to the target.
Output
geDjs
geDjs
geDjs
geD2s
geD2s
geD2s
......
geek
Target matched after 1307 iterations
Explanation:
This approach starts with a random string and gradually improves it by fixing the correct characters and only changing the incorrect ones. Any change that reduces correctness is discarded, so the string slowly climbs toward the target.
Output
sx18
1EEp
mzhm
8JQN
SeLb
......
geek
Target matched after 113 iterations
Explanation:
In this approach, we start with a random string and repeatedly replace only the incorrect characters with random choices, keeping correct characters unchanged, until the string matches the target.
Output
vkZ2
tac4
I56g
zqPR
9XuS
.....
geek
Target matched after 114 iterations
Explanation:
In this approach, a completely random string is generated in each iteration until it exactly matches the target string.
Output
g5ek
gUek
gWek
gXek
gOek
gWek
......
geek
Target matched after 1104 iterations
Explanation: