Array to solve hidden phrase puzzle

1

"You have two arrays

letras   = ["m", "D", " ", "e", " ", "G", "v", "e", "i", "e", " ", "r", "S", "G", "D", "u"];

caminho  = [ 12, 7, 11, 9, 8, 4, 15, 0, 2, 13, 14, 5, 10, 1, 3, 6];

There is a hidden phrase that you have to find out, but not just that! you must write the function (in any programming language) that solves the problem. "

Good afternoon, I need to solve this problem and I would like suggestions, as I am in the second period of BSI and I am not understanding what the "path" of the array is.

    
asked by anonymous 04.03.2016 / 17:21

1 answer

2

To do this using C # would look like this:

using System;

public class Program
{
    public static void Main()
    {
        //Array de caracteres utilizadas para montar a frase
        var letras = new string[] { "m", "D", " ", "e", " ", "G", "v", "e", "i", "e", " ", "r", "S", "G", "D", "u" };
        //Array de index referente ao array de letras para montar a fras
            var caminho = new int[] { 12, 7, 11, 9, 8, 4, 15, 0, 2, 13, 14, 5, 10, 1, 3, 6 };
            //A variável para acumular os caracteres
            var frase = string.Empty;
            //Para cada index no array de indexes, adiciona o carácter na variável para armazenar a frase
            foreach(var index in caminho)
            {
                frase += letras[index];
            }
            //Escreve a frase no console.
            Console.WriteLine("Frase: " + frase);
    }
}

You can view the result at .Net Fiddle

    
04.03.2016 / 17:52