You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the input file broken.txt, print all lines between the markers top and bottom. Assume that the input file cannot have two top markers without a bottom marker appearing in between and vice-versa.
top
3.14
bottom
---
top
1234567890
bottom
top
Hi there
Have a nice day
Good bye
Issues
From my understanding, if the first line is changed to any string not equal to, but containing top (e.g. stop), the reference solution will print 3.14 when it shouldn't.
Also, if the first line (i.e. the one with top) is completely removed, 3.14 will still be printed, when, from my understanding, it shouldn't be.
My Solution
Here's a solution which doesn't rely on external commands and doesn't have any of the issues above. Let me know if there are any issues with it. The solution could be shorter, but for the sake of clarity I used descriptive variable names and line breaks.
Regarding matching top and bottom as whole lines, that wasn't a requirement - I would've emphasized word/line matching in such cases. But still, might be better to make it clearer.
Regarding the case of bottom appearing first in the file before a top marker - I hadn't considered that. I'll have to either indicate that won't be possible or change the scope of the question.
Problem text
This is Q: 78/88 of awkexercises:
Reference Solution
Input File
This is
broken.txt
:Issues
From my understanding, if the first line is changed to any string not equal to, but containing
top
(e.g.stop
), the reference solution will print3.14
when it shouldn't.Also, if the first line (i.e. the one with
top
) is completely removed,3.14
will still be printed, when, from my understanding, it shouldn't be.My Solution
Here's a solution which doesn't rely on external commands and doesn't have any of the issues above. Let me know if there are any issues with it. The solution could be shorter, but for the sake of clarity I used descriptive variable names and line breaks.
The text was updated successfully, but these errors were encountered: