Array to solve hidden sentence puzzle

Asked

Viewed 183 times

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’s a hidden phrase that you have to figure 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, because I am in the second period of BSI and I am not understanding what is the "path" of the array.

  • Path means you must access array elements letras by the index given by the elements in the array caminho. E.g: letras[12], letras[7], letras[11], etc. What have you tried so far? (Post your code).

1 answer

2


To do using C# would be 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 on .Net Fiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.