English 中文(简体)
Need ideas for an algorithm that generates an "echo text" from a given input
原标题:

After having some fun in a chatbox on a certain website I had an interesting idea. What would be an algorithm that, given some input text, would generate an "echo" text from it. That is, it generates the echo that you would hear if you shouted the input text in a large empty cave. For example:

Input text: Hello!
Output text: Hello!
             ello!
             lo!
             o!

The problem is I don t exactly know what I want myself. I have no idea on how to create such an algorithm or what would even be a criteria to determine if it s a good algorithm. But I suppose the general idea is clear, so I d like to hear your thoughts.

You don t have to give a complete solution in your answers. Hints of the direction too look in, or just random thoughts about the problem are welcome too.

问题回答

Bad but fun (imo) solution:

Run the input through a speech synthesizer to generate a waveform. Run that waveform through an echo generator in a sound processing library. Then run the resulting waveform through a speech recognition program.

You could create an array of characters, and then interate over the list of characters, using a different starting point for each iteration.

For example in C#

string Mystring = "Is There an Echo in Here?";
        char[] charArray = Mystring.ToCharArray();
        int k = 0;
        string Echo = "";
        for (int i = 0; i < (charArray.Length / 3) + 1; i++)
        {
            for (int j = k; i < charArray.Length; i++)
            {
                Echo += charArray[j];
            }
            Echo += Environment.NewLine;
            k += 3;
        }

Should produce an output something like this
Is there an Echo in Here?
there an Echo in here?
re an Echo in here?
an Echo in Here?
Echo in Here?
o in Here?
n Here?
ere?
?

Just one possible way of doing things, and you can play around with the values to change the echo effect.

Another solution would be to split the string by the words rather than characters

string Mystring = "Is There an Echo in Here?";
        string[] Words = Mystring.Split(   );
        int k = 0;
        string Echo = "";
        for (int i = 0; i < Words.Length / 2; i++)
        {
            for (int j = k; i < Mystring.Length; i++)
            {
                Echo += Mystring[j];
            }
            Echo += Environment.NewLine;
            k += 2;
        }

Would produce the following
Is there an Echo in Here?
an Echo in Here?
in Here?





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签