php-school / learn-you-php

🏆 Learn You PHP! - An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.
http://www.phpschool.io/
MIT License
319 stars 36 forks source link

Exercise 3 is ambiguous #63

Closed weichenlin closed 8 years ago

weichenlin commented 8 years ago

the exercise ask for the number of newlines, but what is the correct answer for strings that without a newline at end? for example, "line1\nline2" should be count as 2 lines, but it actually has only 1 newline char. and the funny part is "wc -l" also show "1" for this case.

AydinHassan commented 8 years ago

The problem asks to print the number of new lines, specifically \n's so it would be the same as wc, so with you're input it should also be 1. Is there a problem?

weichenlin commented 8 years ago

yes there is problem. if the correct answer is 1, then the solution in learnyouphp/exercises/my-first-io/solution is wrong. because explode "line1\nline2" by newline will return an array contains 2 element.

when running "learnyouphp verify", the generated text file has no new line at end, so the solution always expected a wrong line number.

weichenlin commented 8 years ago

sorry, please ignore the "newline at end" part. if there are newline at end like "line1\nline2\n", explode will return a 3 elements array. it's still wrong.

AydinHassan commented 8 years ago

Indeed it looks incorrect - would you mind submitting a PR?

Sent from my iPhone

On 28 Aug 2016, at 02:09, weichenlin notifications@github.com<mailto:notifications@github.com> wrote:

yes there is problem. if the correct answer is 1, then the solution in learnyouphp/exercises/my-first-io/solution is wrong. because explode "line1\nline2" by newline will return an array contains 2 element.

when running "learnyouphp verify", the generated text file has no new line at end, so the solution always expected a wrong line number.

You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/php-school/learn-you-php/issues/63#issuecomment-242947997, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACr76pDOGsFTp3FWVShEq1FLAEdVSICjks5qkNGsgaJpZM4Jux8A.

weichenlin commented 8 years ago

here is my PR: #64

AydinHassan commented 8 years ago

Fixed with #64