Let x and y be the two numbers. Then one can remove the digits in x which it has in common with y like this:
Prelude> import Data.List
Prelude Data.List> let x = 68
Prelude Data.List> let y = 76
Prelude Data.List> read (show x \\ show y) :: Int
8
Flip x and y to remove digits from y. This uses xs Data.List.(\\) ys, which removes the first occurrence of each element in ys from xs.
Edit: you may have solved problem 33 by now. If not, let me give you some more hints:
The code which I gave above, i.e. read (show x \\ show y) is not really suitable for this problem. What happens if x equals ab and y equals ba, for some digits a and b?
The solution to this problem can be written as a single list comprehension. You may want to use Data.List.intersect and Data.List.nub to create the following term in your list comprehension:
s <- nub $ intersect (show x) (show y)
Now s ranges over the digits that x and y have in common. You can remove these from x and y using
map (read . delete s . show) [x, y]
I cannot be more explicit without solving the exercise for you, but I'll leave you with two more hints:
- In your code you write
y <- [10..99], x <- [10..y], x /= y. Observe that this can be written more succinctly as y <- [10..99], x <- [10..y-1].
- Have a look at
Data.Ratio, which provides an easy way to test the equality of rational numbers and automatically calculates the numerator and denominator of a fraction in its reduced form.