Created
April 6, 2020 18:27
-
-
Save crclark96/1d02f16d32f89c30c1b2ed003f5af3b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pop :: [a] -> [a] | |
pop [] = [] | |
pop (x:xs) = xs | |
compareWithBackspace :: String -> String -> Bool | |
compareWithBackspace xs ys = compare' s1 s2 | |
where s1 = buildStack xs | |
s2 = buildStack ys | |
buildStack :: String -> String | |
buildStack xs = buildStack' xs [] | |
buildStack' :: String -> String -> String | |
buildStack' [] ys = ys | |
buildStack' ('#':xs) ys = buildStack' xs $ pop ys | |
buildStack' (x:xs) ys = buildStack' xs (x:ys) | |
compare' :: Eq a => [a] -> [a] -> Bool | |
compare' xs ys = and $ (length xs == length ys) : (zipWith (==) xs ys) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help | |
Prelude> :l compareWithBackspace.hs | |
[1 of 1] Compiling Main ( compareWithBackspace.hs, interpreted ) | |
Ok, modules loaded: Main. | |
*Main> compareWithBackspace "a##c" "#a#c" | |
True | |
*Main> compareWithBackspace "xy##" "z#w#" | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment