ASCII art puzzle discussion


#486

hello all can you give me advice how to pass this lab ? for c++ what to use ?


#487

Your question is too vague and too broad.

You’d better try solving it by yourself. When there is a problem, give details of what you have done and what problem you have.


#488

Hi, I’m trying this puzzle in C#, and my code seems to pass every test (when I test it on my computer, or according to the console output on the Coding games site) but I still got 0%.
The problem seems to be the “Console.WriteLine();” in the last for loop, but I have no idea how to deal without it.
Has someone an idea to help ?

My code below if someone wanna try it

class Program
{
static void Main(string[] args)
{
// Declare an array containing the alphabet and “?”
string[] tableauAlphabet = new string[] { “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”, “?” };

        // The width of each character in ASCII art
        int L = int.Parse(Console.ReadLine());

        // The height of each character in ASCII art
        int H = int.Parse(Console.ReadLine());

        // The string to convert in ASCII art
        string T = Console.ReadLine();

        // An array which will contain the letters in ASCII art 
        string[] tableauASCII = new string[27*H];

        // An array to store the index in tableauAlphabet of each letter of the string to convert
        int [] indexT = new int[T.Length];

        for (int i = 0; i < H; i++)
        {    
            string ROW = Console.ReadLine();


            // Storing each letter ASCII Art in an array 
            //-> example : for character "A" the 1st line is in tableauASCII[0]
            //                               the 2nd line is in tableauASCII[27]
            //                               the 3rd line is in tableauASCII[54], etc.
            for (int j = 0; j<(27); j++)
            {
                tableauASCII[(27*i) + j] = ROW.Substring(j * L, (L));
            }

        }

        // Lowering all the characters of the string passed 
        string TtoLower = T.ToLower();

        // Declaring a positioning variable for the string to convert, will allow us to store index for identical characters in the string
        int a = -1;

        // Check if every character of the string exists in the tableauAlphabet, and store the index found in an array indexT
        foreach(char c in TtoLower)
        {
            // Incrementing the variable of position foreach character treated
            a++;

            // converting the character to a string to use the .Contains method
            string caractère = c.ToString();

            // check if the character exists in the array
            if (tableauAlphabet.Contains(caractère))
            {
                // if he is, we store the index found in the indexT array
                indexT[TtoLower.IndexOf(c,a)] = Array.IndexOf(tableauAlphabet, caractère);
            }
            // Otherwise, we store the index of the "?" character
            else
                indexT[TtoLower.IndexOf(c,a)] = 26;
        }
     
        // We use the array indexT, containing the index of each character in the string to convert, to get and pass the ASCII Art lines corresponding
        for (int k = 0; k < H; k++)
        {
            Console.WriteLine();
            for(int l = 0; l < T.Length; l++)
            {
                Console.Write(tableauASCII[(indexT[l] + k * 27)]);
            }
        }           

    }
}

#489

Found the answer myself, well a little trick to deal without the first Console.WriteLine(); of the loop, just replaced the last for with :

    for (int k = 0; k < H; k++)
    {
        for(int l = 0; l < T.Length; l++)
        {
            Console.Write(tableauASCII[(indexT[l] + k * 27)]);
            if (l == (T.Length - 1))
                Console.Write(Environment.NewLine);
        }
    }

#490

In the D version of this, I found that all the test cases were missing a " " at the beginning of the first row due to the following line, which is in the for loop:
string ROW = readln.strip;

The proper line should be:
string ROW = readln;

This also causes issues with spaces being removed from the end of the ROW. It would be nice that the default code is reading in properly.


#491

In C, there is an error in the intial code, line 20. after
fgets(T, 257, stdin);
there is a
fgetc(stdin);
It forces a left shift in the fist alphabet line. This error is not present in other languages.


#492

If in the text that is given there is space what is the result that need as an output


#493

this never happens in test cases …
otherwise we should have to replace it by “?” as said in statement


#494

Hey all,

In the ruby version of this problem, I encountered an error that I don’t understand with the “MANHATTAN with another ASCII representation” test case.

Failure
Found:

Nothing

Expected:

 .----------------.  .---------...-.  .----------------.  .----------------.  .-----------------.

Here’s my solution :

l = gets.to_i
h = gets.to_i
t = gets.chomp
rows = {"0" => [], "1" => [], "2" => [], "3" => [], "4" => []}
result = {"0" => [], "1" => [], "2" => [], "3" => [], "4" => []}

h.times do |i|
    rows["#{i}"] = gets.chomp 
end

t.each_char do |c|
    rows.each do |k, v|
        if c.ord >= 65 and c.ord <= 90
            ascii_base = (c.ord - 65) * 4
            result[k] << v[ascii_base..ascii_base + 3]
        elsif c.ord >= 97 and c.ord <= 122
            ascii_base = (c.ord - 97) * 4
            result[k] << v[ascii_base..ascii_base + 3]
        else
            result[k] << v[v.length - 4..v.length]
        end
    end
end


result.each do |k, v|
    puts v.join
end

The other thing I noticed is that for this test, the L and H values are way off

L : 20

H : 11

T : MANHATTAN

#495

you expected all the ASCII representations to be 4*5, didn’t you? It would have been too easy:
image


#496

Thank you ! Solved it !


#497

To everyone who is having troubles with the Lorem Ipsum test, I managed to solve the problem in C++.
In my code, I use a vector to memorise the index of each letter from the T text, then I use a for to display each ASCIIART letter from ROW based on the indexes from the vector.

The problem aren’t the spaces, you don’t need them. You need to display “?” instead of spaces.
The problem was the size of the index vector. The size should be 200 because in the exercise, N is < 200.

Hope this helps.


#498

what is the relationship between the readline and the for loop in JavaScript mode?

I just dont undestand how it work at all and if this whole thing is a loop???


#499

aah! Help me to start!
i don’t even know from where to start
Thanks


#500

For the C language, the first ASCII ROW is incorrect and it causes my solution to fail. My solution works on all the other lines except the first line and I can copy/paste my solution to the C++ language and it works 100% correctly. If I do a simple printf("%s", ROW); you will see that the first row of the input ASCII is incorrect. Please fix this!

A copy of my code is as follows for C (to convert to c++, add “.cstr()” to the ROW variable in fwrite() functions):

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define CHAR_QUESTION_MARK 26

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/

int main()
{
    int L;
    scanf("%d", &L);
    int H;
    scanf("%d", &H); fgetc(stdin);
    char T[257];
    fgets(T, 257, stdin); fgetc(stdin);
    for (int i = 0; i < H; i++) {
        char ROW[1025];
        fgets(ROW, 1025, stdin);
        
        //printf("%s",ROW);
        
        for (int i = 0; i < 257; i++)
        {
            if(T[i] <= 122 && T[i] >= 97)
            {
                T[i] -= 32;
            }
            //printf("%d",i);
            if ( T[i] == '\0' || T[i] == '\n' )
            {
                break;
            }
            
            if(T[i] >= 65 && T[i] <= 90 )
            {
                int offset = L*((int)T[i] - 65); // Calc the offset into the row for char T[i]
                //printf("%c %d\n",(int)T[i], T[i]-65);
                //printf("%d",offset);
                fwrite(ROW+offset, L, 1, stdout); //print ascii char output from ROW
            }
            else /* Input char is not valid */
            {
                /* Invalid character chosen, print question mark (?) */
                fwrite(ROW+CHAR_QUESTION_MARK*L, L, 1, stdout); //print ascii char output from ROW
            }
        }
        printf("\n");
    }
    return 0;
}

#501

it seems there is an issue with the default code. Thanks for reporting it.

You can remove the second fgetc(stdin); to remove the shift

Sorry about the late answer @Abunth


#502

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#503

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#504

Completed 100%

Char.IsLetter(val) helped.