Example in 258

Back to General discussions forum

gardengnome     2022-01-20 17:59:47
User avatar

Hi Rodion,

Thanks for the latest problem. I believe the solution for the example should be slightly different, i.e. the last three lines should read:

...
to the proposition that
all  men  are   created
equal.
Rodion (admin)     2022-01-20 18:22:57
User avatar

Mathias, Hello and thanks for speedy correction!

I edited example manually (cheater, heh) - though still surprising how could I have mistaken so easily :)

gardengnome     2022-01-20 18:26:03
User avatar

"Computers are incredibly fast, accurate, and stupid. Human beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination." (Albert Einstein, maybe)

Rodion (admin)     2022-01-20 18:32:41
User avatar

Hm-m-m. Quote - that's a good puzzle itself :) Einstein is one of my favourite heroes, but I suspect he passed away before computers get fast :)

We have a joke like this:

"The biggest problem with quotes from internet - is source verification" (c) V. Lenin

gardengnome     2022-01-20 20:52:13
User avatar

PS I recommend to add an example of the edge case "lines having single word only" to the checker. :)

CSFPython     2022-01-20 21:16:19

Mathias, I assume that you mean a case where the output text width is the same as the length of the longest word in the text. I can't see this being a particular problem. Clearly the text cannot contain a situation where it is not possible to achieve the justification required by the problem, so we cannot have a situation where only one word can fit on the line and that word is smaller than the required text width.

gardengnome     2022-01-20 21:31:10
User avatar

Hi, I fully agree that this is not a particular challenge. All I am suggesting is to check whether submitted solutions handle this case correctly. In the example with width 23, add for instance the word COUNTERDEMONSTRATION as the very first word.

Rodion (admin)     2022-01-20 22:27:27
User avatar

to add an example of the edge case "lines having single word only" to the checker

case where the output text width is the same as the length of the longest word in the text

Friends, I'm a bit confused since this seems not exactly the same. Cases when the line contains single word do happen (generally with width close to minimum 21 (so that, say, implementing justification won't fit).

The case when such word has exactly the same length as text width isn't much more special.

As about tweaking generator so that it always includes such a situation - I'm not sure we want it :) The task is about justifying lines, not about skipping them, e.g. it's bit out of the scope. This phrase was added only because it happens sometimes... But I don't want to force people think about various exceptional situations.

For example, source text has dashes (in form of --) sometimes. Properly we should take care that they are never put at the beginning of the line (e.g. preceding word should be "borrowed" from the previous line.

And borrowing can also potentially save situation with long word!

But this makes problem more alike Knuth-Plass version. Perhaps we may decide to have such advanced version in future, but I'm not sure whether it is interesting enough :)

gardengnome     2022-01-20 22:50:01
User avatar

My suggestion was simply to check that a solution handles the “single word on a line” case correctly. No complex thinking behind this. Simple test: run the given example with width 12 instead of 23. This should now include a few lines with only a single word and aligned to the left.

Rodion (admin)     2022-01-21 07:15:34
User avatar

Yep, I got it :) though on second thought decided to fix the checker so than single-word-per-line won't occur (except probably last line) - and remove mentioning it. (adding some spare word to the text was possible, but not quite elegant as the paragraphs are pulled out from the book)

It is all my stupid laziness due to which this "exception" was added to the statement, but it really feels "outlier" to the task (and shows deficiency of our "greedy" justification algorithm). Excuse me and hopefully you won't be offended that several people who solved initial version had slightly more complicated code. :)

sam_bandara     2022-02-08 02:46:47

Hey Rodion, I manually check the output of my program, but it fulfills the requirements. But checker’s outcome is “Wrong”. Then I ran the example text. Got the exact same length of the texts from the len() function but when I compared the two outcomes (youroutcome == myoutcome) got false. When I examine more, I found the error. In the second line “years ago our fathers” space counts are 2,1,2 but in my outcome, it is 2,2,1 Should it be exactly like 2,1,2 ?

Rodion (admin)     2022-02-08 07:09:53
User avatar

Sam, Hi! (hopefully that's the name - correct me please if not)

But checker’s outcome is "Wrong"

See, checker produces some "verdict", explanation of what exactly is wrong. What it says in your case?

Should it be exactly like 2,1,2

No, I don't think so. Checker's code just tests that spaces do not differ more than 1. Along with check on line length and minimum space width it is enough...

Feel free to share your input and supposedly "wrong" answer, we shall try to figure out!

sam_bandara     2022-02-08 23:36:13

You nailed it mate, thats my name :-)

Checker just said, "text not match"

Here is the input :

"We shall see." He pushed past the servant
and rushed into the drawing-room, followed by the King and myself.
The furniture was scattered about in every direction, with dismantled shelves
and open drawers, as if the lady had
hurriedly ransacked them before her flight. Holmes
rushed at the bell-pull, tore back a
small sliding shutter, and, plunging in his hand, pulled
out a photograph and a letter. The photograph was of
Irene Adler herself in evening dress, the letter
was superscribed to "Sherlock Holmes, Esq. To
be left till called for." My friend tore it
open and we all three read it together. It was dated
at midnight of the preceding night and ran in this way:

and here is the output : Edit : Once I posted, all the formatting has gone

"We   shall   see."  He
pushed past the servant
and   rushed  into  the
drawing-room,  followed
by the King and myself.
The    furniture    was
scattered    about   in
every  direction,  with
dismantled  shelves and
open drawers, as if the
lady    had   hurriedly
ransacked  them  before
her    flight.   Holmes
rushed      at      the
bell-pull,  tore back a
small  sliding shutter,
and,  plunging  in  his
hand,   pulled   out  a
photograph     and    a
letter.  The photograph
was   of   Irene  Adler
herself    in   evening
dress,  the  letter was
superscribed         to
"Sherlock  Holmes, Esq.
To  be left till called
for." My friend tore it
open  and  we all three
read  it  together.  It
was  dated  at midnight
of  the preceding night
way:

Thanks!!

Rodion (admin)     2022-02-09 05:12:34
User avatar

Once I posted, all the formatting has gone

There is a link to markdown quick reference... what you want here is "code block" style - just indent the block with tab (e.g. select the text and press "tab" to shift it whole)... (just did it myself)

Checker just said, "text not match"

Yep, that's it (there are other error types - wrong spacing, wrong line length etc - we needed to know what exactly checker thinks).

So since it says exactly "not match" just take some patience and check. It really doesn't match - your version lacks several words in the end :)

sam_bandara     2022-02-09 05:48:41

Thanks mate!!! I will check the program.

sam_bandara     2022-02-11 03:31:14

Hi Rodion, Still I got the same issue. Can I post my codes here?

Cheers

Rodion (admin)     2022-02-11 05:47:26
User avatar

Sam, Hi!

You can, but there is no need - your code is visible to everyone who solved the task by the link from your profile:

Text Justification by Sam

However, have you identified the issue itself? You seemingly miss the line of text before last:

Original ends with:

It was dated at midnight of the preceding night and ran in this way:

You return:

It was  dated  at midnight of  the preceding night way:
Please login and solve 5 problems to be able to post at forum