Task: Seasickness Checker with File I/O (2-skill task)
Description:
Extend the Seasickness Checker to include file-based input/output while preserving the original algorithmic requirement.
Requirements:
Algorithm: Keep the original logic
Analyze the sea string to count level-change occurrences using the two-character sequences "" and "".
Compute the percentage: (number of level-change sequences) / (total length of the string) * 100.
Return "Throw Up" if this percentage is greater than 20%; otherwise return "No Problem".
Edge cases: if the string is empty, the percentage is 0% and the result should be "No Problem".
Overlapping occurrences should be considered (slide a window of length 2 over the string and count any occurrence of "" or "").
File I/O requirement (exactly 2 skills: algorithm plus file I/O)
Read input from a file at /app/input.txt.
Write output to a file at /app/output.txt.
The input file contains the sea string (the string may contain any characters). Read the entire file content and treat it as the sea string; strip only a trailing newline if present.
Implement a Python program located at /app/solution.py that:
Defines the function check_seasickness(sea: str) -> str (the algorithm above).
Includes a main entry that reads the sea string from /app/input.txt, calls check_seasickness, and writes the resulting string to /app/output.txt as a single line.
Cohesion:
This must be a single cohesive task: implement the function and provide the file-based I/O in one program, with /app/solution.py containing both check_seasickness and the main I/O flow.
Implementation details to include in /app/solution.py:
Function:
def check_seasickness(sea: str) -> str:
If len(sea) == 0: percentage = 0
Else: count occurrences by iterating i from 0 to len(sea) - 2 and counting 1 if sea[i:i+2] in {"", ""}.
percentage = (count / len(sea)) * 100
Return "Throw Up" if percentage > 20 else "No Problem"