0

Write a function allLessThan. It takes two list of integers and test if all integers in the first list are less than all integers in the second list.

For example allLessThan([2,4], [6,7,8]) would return true

I've tried to set up the function in terms of letting the sets equal xx and yy so that if every element in xx is less than every element in yy then the function would return true, but if not would return false.

- fun allLessThan([], yy) = true
=  | allLessThan(xx, []) = false
=  | allLessThan(x::xRest, y::yRest) 
Rex5
  • 771
  • 9
  • 23
  • It's very tricky to recurse over two lists at once. Think about how much easier it would be to write this if you already had a function that determined whether a single integer was less than all elements in a list. – molbdnilo Sep 13 '19 at 05:08
  • @molbdnilo yea I wish it would be that way but my teacher is a stickler and wants us to do it with 2 list at once. And she isn’t very helpful either – TheMathDude92 Sep 13 '19 at 05:10
  • Has your teacher actually said that you're not allowed to use any "helper" functions? If you had the function I mentioned, this function would be a very simple recursion. It's also possible that this is an exercise in using `map`s, `fold`s, and/or `filter`s, in particular if you've learned about those recently. (Your teacher is probably unhelpful because it's very difficult to provide any help at all without providing the entire solution, which is extremely unhelpful. In my experience, most homework can be solved if you look through your lecture notes and previous exercises for ideas.) – molbdnilo Sep 13 '19 at 07:04
  • @TheMathDude92: What molbdnilo was hinting at when saying *if you already had a function that determined whether a single integer was less than all elements in a list* is that if you make such a function, you could use it in `allLessThan`. – sshine Sep 13 '19 at 10:54
  • @SimonShine we don’t. I can go through the book where we had divisor one but it didn’t help too much. – TheMathDude92 Sep 13 '19 at 13:51
  • @SimonShine the only function that is in the book is allHaveDivisor. – TheMathDude92 Sep 13 '19 at 14:20
  • @TheMathDude92: If you make this, let's call it `singleLessThan : int -> int list -> Bool`, you would have it. You're allowed to make other functions than exactly the one you need. If you happen to make a function that solves a sub-part of a problem, you can use it in defining other functions. – sshine Sep 13 '19 at 15:57
  • 1
    One way to approach this problem is to write helper functions to compute mins and maxes of int lists. Apply these helper functions to the two lists, to check if the max of the first list is less than the min of the second. – John Coleman Sep 14 '19 at 15:55

0 Answers0