[Community Puzzle] Frame the picture

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Grarzyna,validated by @Adnane_Arharbi,@ishibashijun and @FredericLocquet.
If you have any issues, feel free to ping them.

Hello, I have a problem with last testcase in C language. This testcase contains ā€˜bulletā€™ (unicode character U+2022) as a frame so Iā€™m using wide characters in all strings and functions. But I think there is some general problem with wide characters in CG IDE. To investigate this, Iā€™ve tried this simple ā€œrepeaterā€:

int main(){
wchar_t text[100];
wscanf(L"%ls", text);
wprintf(L"%ls", text);
}

When I send in some ordinary string (e.g. ā€œHelloā€), it works correctly. But when I try this ā€˜bulletā€™ character from the last testcase, it returns nothing. Can anyone help?

Itā€™s a utf8 character, it ought to be fixed.

Problem solved: I have to call

setlocale(LC_ALL, ā€œC.UTF-8ā€);

at the beginning of my code. Iā€™m new to wide chars. Thanks for quick answer.

Iā€™d almost like to leave it as is, I learned a lot trying to solve it in C++.

1 Like

I tried solving it in Ruby. The framed picture is frist created as an array of strings, then put out like this:

for i in 0..fh do
    puts pic[i]
end

Weirdly, while this wasnā€™t a problem in other puzzles I solved in Ruby here, this time my console output shows the framed picture as it ought to look like, but then fails with:

Found:
#####End of line (\n)
Expected:
Nothing

I havenā€™t seen this kind of output before, and since it isnā€™t a Ruby error message, I wasnā€™t able to find anything useful using online search. Then I tried out appending .rstrip to get rid of any superfluous \ns and the test succeeds even though the console now claims ā€œundefined method `rstripā€™ for nil:NilClass (NoMethodError)ā€. Does anyone have any idea what is going on here?

EDIT: Okay, it works without error messages if I make the output with

for i in 0...(fh - 1) do
    puts pic[i]
end
print pic[fh - 1]

but surely that canā€™t be the intended solution?

Your first loop is 0 to fh inclusive (2 dots) and prints pic[fh] which is past the end of your array and returns a nil (this is why you get the rstrip error as rstrip on the nil is undefined). puts with a nil just prints a blank line (which is the extra \n the server complains about).

Your second loop has 3 dots so doesnā€™t include the upper bound and works properly.

1 Like

Oh wow, now I feel really stupid making such an obvious error. Thanks for your answer! Curious that the Ruby interpreter doesnā€™t throw an error when itā€™s told to access something outside an arrayā€™s boundsā€¦

Nice exercise! Simple at the first steps, then quickly interesting and more complex, while solving a real problem, congratulations :+1:

1 Like

Nice puzzle!

I get problems with the length of the image when I run the following code in java I get:

        String line = in.nextLine(); // the ASCII art picture line by line
        System.err.printf("%s -length: %d%n", line, line.length());

the result of the print is (Test 5)

ā€¦@@ -length: 8
.@* ā€¦@* -length: 10
ā€¦@* .@* -length: 11
.@* ā€¦@* -length: 10
.@@ā€¦ -length: 17

the blanks are cut off at the end. or they donā€™t exist.

result for test 4 is correct:

o -length: 7
< _ -length: 7
(
)>(
) -length: 7

Thank you for reporting the issue. I have just fixed test 5.

1 Like

Not so simple as it should be at the first read.
Nice one !!

Not easy as it looks. Cool puzzle