Ad
  • Custom User Avatar
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    (Assuming Haskell version)
    I'm also new to functional programming, so maybe someone can comment on this. I found this challenging, it took me a while to work out what I was being asked to do, and then a while to work out how to do it.

    I think the exact problem is quite contrived, but there are cases where you get passed a function or need to pass a function into something. Or you want to iterate over some functions that on the surface seem very different. A number seems very different from a math operator, but this shows that you can consider both to be functions.

    I'll put a 2nd comment with a spoiler warning.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Numpy arrays apply '==' elementwise, so you get an array of truth values. This cannot be converted to a bool so cannot be directly used in an 'if' statement, which at some level the test will be doing.

    a1 = np.array([1,2,3])
    a2 = np.array([1,2,3])
    a1 == a2
    array([ True, True, True])

    Python lists compare equal if they have the same values for every element.

    l1 = [1,2,3]
    l2 = [1,2,3]
    l1 == l2
    True

  • Custom User Avatar

    I think it also makes a difference if you calculate as w/(h*h) or w/h/h

    The test cases should not sit on floating point boundary.

  • Custom User Avatar

    A tolerance is needed on the comparison. The out can depend on things like if you sum in an int or double, if you round the mean, and probably many other subtle things.