[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