Skip to content

Instantly share code, notes, and snippets.

@wz1000

wz1000/puzzle.md Secret

Created January 6, 2021 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wz1000/2bfc0ad5f41a5ee803cd2ccfcde9e1a3 to your computer and use it in GitHub Desktop.
Save wz1000/2bfc0ad5f41a5ee803cd2ccfcde9e1a3 to your computer and use it in GitHub Desktop.

You are given a diff between the lines of two text files.

The task is to match up line numbers in the first file with the corresponding line numbers in the second file. If this is not possible (a line has been deleted from the first file), then output a pair of lines which represent the range between which the line could land.

data Diff = First String | Second String | Both String

data Result = Exact Int | Range Int Int

mapLines :: [Diff] -> Int -> Result
mapLines diff line = _

File 1 (with line numbers):

0: a
1: b
2: c
3: d
4: y
5: z

File 2:

0: a
1: e
2: b
3: f
4: g
5: y
6: z

Diff:

Both "a"
Second "e"
Both "b"
First "c"
First "d"
Second "f"
Second "g"
Both "y"
Both "z"

Output:

0 -> 0
1 -> 2
2 -> (2,5)
3 -> (2,5)
4 -> 5
5 -> 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment