Given any four letter word, for example: “card”
Replace one to three letters with “~”,
How can I get the result collection ( ["~ard", “c~rd”, …, “~~r~”,
“~~~d”])?
I know ruby, but I am bad at any algorithms, help please.
Nanyang Z. wrote:
Given any four letter word, for example: “card”
Replace one to three letters with “~”,
How can I get the result collection ( ["~ard", “c~rd”, …, “~~r~”,
“~~~d”])?
One idea:
irb> 1.upto(14) {|i| printf("%04b\n", i)}
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
Regards,
Bill
Bill K. wrote:
Nanyang Z. wrote:
Given any four letter word, for example: “card”
Replace one to three letters with “~”,
How can I get the result collection ( ["~ard", “c~rd”, …, “~~r~”,
“~~~d”])?One idea:
irb> 1.upto(14) {|i| printf("%04b\n", i)}
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110Regards,
Bill
Thanks.
Given I have the 0 and 1 array,
Replacing all the 0s with “~”, and replacing all the 1s with the right
letters, I think it should work.