ASCII art puzzle discussion

I guess no one told you that you can use more than one character for variable names. You really should use more descriptive names. :wink:

The big switch statement is not good style. Do you see the pattern the numbers are forming? You can use that to replace the whole switch statement with just one line. Except the last case, that has to stay in an If statement.

i replaced it with

case n: m[i]=row.substring(nl,l(n+1));
but i got some errors and switched it back ,

my new code bellow the one i just posted is : i pass the first test and i get at the second test MANHATTAN but the chars are separated with a coma , could some one help on how to remove the coma between the chars …(i use JavaScript)

var f=[]

var a=[];
var p=0;
for(p=0;p<h;p++){

a.push(z.slice(pt.length,t.length(p+1)));
for(var i=0;i<h

;i++)

{

a[i];  }}

var ar= function(z) {for(var e=0;e<h;e++){ print(a[e]); };}

ar(a);

please print “&lt;” instead of <

That looks very good. Except that you can’t use case n:. In that place you can’t use an expression like n. It has to be a value like 17, 'c', or "jhsdfsf". So you have to use an If statement instead of a switch statement. Try the following:

if (0<=n && n<=25)
    m[i]=...
else
    m[i]=...

And for pasting code in the forum you should use the preformatted text button in the editor.

1 Like

Thank’s , i’ll change that…

I tried to replace the coma from my strings with this comand but it doesn’t work , does anyone have any ideeas?(i use JavaScript , a - is my string)
(a.replace(/,/g , " "));

a.replace(",", "whatever you want")

Your statement a.replace(/,/g , " "); to remove the commas from the string is right. If that doesn’t help the commas are from somewhere else. Or they are not in the string at all and only get printed to the output. Maybe you use a wrong index when you output the strings.

a.replace(",", "whatever you want") would only replace the first comma.

i bet no:

The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

Example

var str = “Mr Blue has a blue house and a blue car”;
var res = str.replace(/blue/g, “red”);

The result of res will be:

Mr Blue has a red house and a red car

http://www.w3schools.com/jsref/jsref_replace.asp

Cuz you add the /g for global replace :slight_smile:

@bvs23bkv33 You can’t just quote half a sentence and ignore the other half I was talking about.

I didn’t say replace() would only replace the first comma, like you are suggesting.

I said a.replace(",", "whatever you want") would only replace the first comma.

it say’s a.replace(",", “whatever you want”) is not a function on other tipes of framework it works… i stored the need strings in an array
after that i sliced that array and pushed it into another array and when i read that array with for loop i get the text but i get it with comas after each string , i guess what i need to do print some how every string from the array …

i can not beleive javascript is so dumb, need to test it

it’s a pity for me that i read the whole documentation on this method and understood like only half

i can send you my code to check it out and see

I’m not sure I understand what you are trying to do. Try to think about it this way.

As input you get a string with the text (save it as a string). You also get a number of strings with the “artwork” for the letters. The first string represents the first line of the letters and so on (save them as an array of strings).

Then you have to print out the text with the artwork, also line after line.

For each line.
    Let *str* be an empty string.
    For each letter in the text.
        Take the corresponding substring from the array and append it to *str*
    Print *str*.

You don’t have to transform any arrays, you just have to lookup the result with an array access and the substring function. You already know how to calculate the indices for substring.

hello (world)
first of all i am using java to solve the game

i am putting all the ascii representation of the letters in a hashMap with the letters as keys and String arrays as values.
to print the answer i build a string for each line of the answer, from the corresponding line of the letters.

for some reason when i enter the strings to the arrays on the map they lose the space characters on their end
i can solve it for most cases by hardcoding an extra space when i insert it to the answer.
but i am looking for a way to get those spaces in without hardcoding solutions.

this is the code i am using to insert values to the map:

for (int i = 0; i < h; i++) // inserts values to ascii map
        {
        String rOW = in.nextLine();
        for (char j='A';j<='Z';j++)
        {
            String letter = String.valueOf(j);
            String arr[] = ascii.get(letter);
            arr[i]=rOW.substring(0,l-1);
            rOW=rOW.substring(l);
        }
        ascii.get("question mark")[i]=rOW.substring(0,l-1);
    }

what map? you are overwriting the task

[NO FULL CODE]

bvs23bkv33 thanks for the answer

i am not sure why but i wanted it to be easy to access the ascii letter even out of the loop so i created the map to store the values.

now i have solved it with your idea and it works.
but i am still trying to figure out why it dropped the spaces at the end of the strings before.

thanks for your help i solved it eventualy …