ASCII art puzzle discussion

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

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.

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)]);
            }
        }           

    }
}
1 Like

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);
        }
    }
1 Like

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.

1 Like

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.

1 Like

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

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

1 Like

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

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

Thank you ! Solved it !

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.

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???

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

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;
}
2 Likes

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

Completed 100%

Char.IsLetter(val) helped.

l’exercice a l’air barbant à la première lecture,
mais il permet en traitant l’entrée asciiart,
de manipuler les dict, listes et chaines python

Testcase 05
i don’t quite figure out the pattern about
Expected: .----------------. .---------…-. .----------------. .----------------. .-----------------.
In this pattern due to the stdin should be
.----------------. .----------------. .----------------. .----------------. .----------------.

May someone tell me how to solve it?

Hi @CodinGame65

I was trying to solve the puzzle using C language and I found an error in the initial code… My solution wasn’t working and I tryed to understand why… So I debug printing the value of ROW along H iterations using fprintf() and I realized that in the first row, a space character was removed…

The initial code is:

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);
}

And ROW value along the iteration is:
https://pastebin.com/H0sENkEY

Then when I remove the function fgetc(stdin) before for cycle, the ROW value along the iteration is:
https://pastebin.com/fUyyZ69L

So fgect(stdin) function just before the for cycle is removing the space character and shouldn’t. This means that initial code should be:

int L;
scanf("%d", &L);
int H;
scanf("%d", &H); fgetc(stdin);
char T[257];
fgets(T, 257, stdin);
for (int i = 0; i < H; i++) {
    char ROW[1025];
    fgets(ROW, 1025, stdin);
}

Best regards and please FIX IT!
Gabriel Correia-Brito