Ad
  • Custom User Avatar

    Also, findIndex is NOT the correct solution for the problem in the description.

    You're still solving the wrong problem.

    Not a kata issue. Closing.

  • Custom User Avatar
      it "random tests" $ do
        forAll gen $ \ (xs,i,expected) -> do
          -- print $ (xs,i,expected)
          let actual = leastLarger xs i
          (xs !!) <$> actual `shouldBe` expected $ "testing value at index " ++ show actual
    
  • Custom User Avatar

    You can see the example tests. They're in the box under your solution, marked "Sample Tests". If you don't know which test you are failing, comment out all but one test at a time.

    Yes, you are returning Just 0. Just 9 comes from that index. Any index that points to -4 would have been correct.

    Keep in mind that multiple answers may be correct, so I can't test against a reference solution, I have to test that THE returned index points to A correct value in the array. Which is what is being tested.

  • Custom User Avatar

    Thanks for your reply.

    I refreshed and retry, now there are more errors,
    in example test:
    Test Failed
    expected: Just 3
    but got: Just 1

    cannot see the input so I don't know why this is failing

    in random test:
    Falsifiable (after 10 tests):
    testing value at index Just 0
    expected: Just (-4)
    but got: Just 9
    ([9,-3,-3,2,-2,-8,-4,-2],5,Just (-4))

    I am pretty sure my solution will return Just 0 for leastLarger [9,-3,-3,2,-2,-8,-4,-2] 5, I tried this on https://repl.it, I am confused by expected: Just (-4), but got: Just 9, where does these numbers coming from..is any of these really the response from my solution?

  • Custom User Avatar

    the index of the least number larger than the element at the given index

    You are not returning "the least index of a number larger than the element at the given index," are you?

    ETA: I have added an Example test for everybody who is doing this wrong ( you may have to refresh .. ). The existing tests did not fail on this. I now have added this to all languages.

    ETA: Looks like you are. Also, it's called findIndex.

  • Custom User Avatar

    The Just 1 you got in your own environment is the output from a function that delivers wrong results, so I cannot interpret that.

    I have updated the random tests to give an error message including the value solver returned ( you may have to refresh something(s) to see that ).

    Keep in mind that multiple answers may be correct, so I can't test against a reference solution, I have to test that THE returned index points to A correct value in the array. Which is what is being tested.

    Just 3 is the value at your returned index. Just (-1) is the value at any correct index.

    Does this answer your questions?

  • Default User Avatar

    As I understand it, in simple terms, Prolog is about searching for values that satisfy predicates. So the result is always something like Alternative f => f Int and the caller decides if it needs all results or any result. The Prolog way would probably be to require "returning" all results in the first place because it's up to the caller to get only one result when needed. So I'm not sure how this should be addressed in katas in general in this kind of cases. -1 looks as bad to me as it would be in Haskell, at the same time the possibility of having an empty set of solutions is directly linked with the possibility of having multiple solutions. So I just don't know...

  • Custom User Avatar

    Falsifiable (after 6 tests):
    expected: Just (-1)
    but got: Just 3
    ([-2,3,0,-1,1],0,Just (-1))

    I ran this leastLarger [-2,3,0,-1,1] 0 in my environment and I got Just(1), the error message is non-sense to me, where does this got Just 3 came form? and also I don't understand the expectation Just (-1) mean?

  • Default User Avatar

    implementing mergesort using quicksort, seems legit.

  • Custom User Avatar

    Yep, if anyone else is stumped just reading the unit tests remember that the arrays are columns going down from left to right, for example:

    The following mine: mine = [[1,2,3], [4,5,6],[7,8,9]] would not look like

      x0 x1 x2
    y0 1 2 3
    y1 4 5 6
    y2 7 8 9

    but rather like:

      x0 x1 x2
    y0 1 4 7
    y1 2 5 8
    y2 3 6 9

    This makes the right/left/up/down directions easier to visualise although it doesn't really affect the problem.

  • Custom User Avatar

    I have the same issue

  • Custom User Avatar

    moving to Right is D, it's not intuitive at all.

  • Custom User Avatar

    pageIndex [0] 1 -1 = Just 0 makes nonsense to me, I reckon nagative page number should get Nothing