|| Homework 6 Answers

|| Part III

|| 1.

is_closer_than p1 p2 = distance p1 < distance p2
                       where distance (x,y) = sqrt (square x + square y)
                                              where square x = x * x
|| 2.

partition_points x [] = ([],[])
partition_points x (y:ys) = (y:a,b), if is_closer_than y x
                          = (a,y:b), otherwise
                            where (a,b) = partition_points x ys
|| 3.

quicksort_points [] = []
quicksort_points (x:xs) = quicksort_points a ++ [x] ++ quicksort_points b
                          where (a,b) = partition_points x xs

|| 4.

gen_strings cs = "":helper [""]
                 where helper lst = a ++ helper a
                                    where a = [x ++ [c] | x <- lst; c <- cs]

|| Without list comprehensions, this becomes:

gen_strings2 cs = "":helper [""]
                   where helper lst = a ++ helper a
                                      where a = foldr (++) [] (map f lst)
                                                where f x = map g cs
                                                            where g c = x ++ [c]
