Closed jimismash closed 7 years ago
Sorry, it is a bit hard to follow the code - also my Python is not the best.
There is a way you can figure out what inputs you are getting though; you probably already tried to use something like print m
but whenever that line is executed it would throw back an error.
What you should do is try and figure out some properties of the matrix that is causing you to fail. If you were to put:
if (false)
print 'Hello World'
It would not throw an error because that line of code will never be executed. So what you can do is;
if (m.length == 1)
return NULL
This will cause all tests to fail where the map is a 1x1, see if you still have the same passing and failing tests as you did before.
If the same tests are failing then put;
if (m.length == 1)
print 'I will cause an error'
Now if you get an error when you run this, then you know that the failing test is a 1x1 matrix. You can do this for NxN matrix to figure out what is causing your code to fail.
My advice is that most people forget about the case where the matrix is 1x1 (already in terminal state) and 2x2.
@ivanseed
I ran:
if len(m) == N:
return 0
or
if len(m) == N:
raise Exception("I will cause and error")
I cycled N from 0 through 10.
Using the return 0 I identified the length of every other test, and then using the "Exception" I was able to determine that the test I'm failing was not a unique length(unless it is longer than 10) test, i.e. I don't think my code has an issue with a specific size of matrix. I have the intuition that the test I'm failing involves a 10x10, but that's only based on tests 5 and 7-10 being 10x10.
I'm storing all of the numbers using the built in Fraction variable type which automatically handles the fraction reduction; I don't know if this could cause any issues with denominators being stored as signed 32-bit integer. I'm trying to think of other exception cases, but this is outside of my area of expertise.
You've been very helpful, thank you for your time!
If it helps at all, one of my previous attempts involved solving systems of multiple equations. The best I could do with that approach was passing 7/10 tests.
Mmm you could also test if that the Matrix at m[0]
is of terminal state. Meaning that the first state is the terminal state. It should be all zeros. If it is not that then maybe it is just how you are storing fractions. But check if m[0]
contains only 0s.
@ivanseed ,
I still didn't pass test six, but detecting S0 as a terminal state was something that my code was not doing. It's probably for the best, classes are starting on Monday so I won't have time to fool around with the harder challenges anyway.
I appreciate all the help you have provided, especially the rundown on Markov Chains.
@ivanseed ,
You were right about the videos being very helpful. Using the approach described there I was able to come up with a solution that almost satisfies the test. I started writing code 2.5 weeks ago, so I apologize for the overall unreadability. Please let me know if you have any thoughts regarding the case that I seem to be missing. And thank you for your time. Python Code: