Change Directory
Asked at OpenAI· Screen
Reported by the problem's creator, not verified
Simulate the Unix cd command. Implement resolve_path(cwd, command), which returns the absolute path of the directory you end up in after running cd command from cwd.
Paths use / as a separator. Component names are non-empty strings with no /. cwd is an absolute, canonical path: it starts with / and contains no ., .., or empty components.
The result always starts with /, has no ., .. or empty components, and has no trailing slash except for the root itself, which is /.
Examples
Example 1
Input: cwd =
/foo/bar, command =boo/./../doeOutput:
/foo/bar/doeExplanation: Append
boo,.stays in/foo/bar/boo,..goes back up to/foo/bar, then appenddoe.Example 2
Input: cwd =
/a/b, command =/x//y/Output:
/x/yExplanation: The command starts with
/, so it is absolute andcwd/a/bis ignored. The empty component from the double slash and the trailing slash are dropped, leaving/x/y.