Home > Blockchain >  How to correctly arrange elements by the right indexes in haskell?
How to correctly arrange elements by the right indexes in haskell?

Time:01-23

I have a problem. I wanted to write a function that would compare 2 sheets and if they are equal, put them on the same position, otherwise put any handicap sign on that position, such as "-".

I was thinking something like this

let l1 = ["a", "b", "c"]
let l2 = ["a", "d", "c"]

(l1', l2') = myFunc l1 l2

l1' == ["a", "b", "c", "-"]
l2' == ["a", "-", "c", "d"]

I just don't understand what the algorithm should be, that's the point, maybe I could implement it in Haskell, but I think it would be very ugly

CodePudding user response:

You can use the Diff package for this. Example:

Data.Algorithm.Diff> getDiff "abc" "adc"
[Both 'a' 'a',First 'b',Second 'd',Both 'c' 'c']
  • Related