Hi Julius, I was playing Devil's "avocado 😁" with that. One could argue the case for that being the correct approach. One could also argue for Paul's unit tests based on seeing no reason why rotational symmetry couldn't apply. (I think my solution for that is 225 and doesn't beat my friend Paul's answer so I don't like it.) The point is that the spiral has to get smaller somewhere but we haven't been given a clear enough rule to follow. In the example in the question, the spiral only turns inward when it hits a used letter or a corner - a dead end as @Robert Cemper puts it. The unit tests below could also be valid. (My solution for this is 199)
There's an unwritten rule in the question that could be "as a human, make a decision when to turn inwards to make sense out of the order of letters". How do you code that?
Set matrix($INCREMENT(matrix)) = "A,B,C"
Set matrix($INCREMENT(matrix)) = "H,I,D"
Set matrix($INCREMENT(matrix)) = "G,F,E"
d $$$AssertEquals(..Solution(.matrix, 1, 1), "ABCDEFGHI")
d $$$AssertEquals(..Solution(.matrix, 1, 2), "BCDEFGHA") // !!?
d $$$AssertEquals(..Solution(.matrix, 1, 3), "CDEFGHABI")
d $$$AssertEquals(..Solution(.matrix, 2, 3), "DEFGHABC") // !!?
d $$$AssertEquals(..Solution(.matrix, 3, 3), "EFGHABCDI")
d $$$AssertEquals(..Solution(.matrix, 3, 2), "FGHABCDE") // !!?
d $$$AssertEquals(..Solution(.matrix, 3, 1), "GHABCDEFI")
d $$$AssertEquals(..Solution(.matrix, 2, 1), "HABCDEFG") // !!?
You are correct Paul, but there's a problem with other tests too. The one with 3,1 above could return GHABCDI because you could argue that when the spiral leaves an outer edge it should never return to it. If the test that starts at 1,2 doesn't return to row 1 then why should 1,3 return to row 1 after leaving? These could be the correct tests:
Set matrix($INCREMENT(matrix)) = "A,B,C"
Set matrix($INCREMENT(matrix)) = "H,I,D"
Set matrix($INCREMENT(matrix)) = "G,F,E"
d $$$AssertEquals(..Solution(.matrix, 1, 1), "ABCDEFGHI")
d $$$AssertEquals(..Solution(.matrix, 1, 2), "BCDEFGHI")
d $$$AssertEquals(..Solution(.matrix, 1, 3), "CDEFGHI")
d $$$AssertEquals(..Solution(.matrix, 2, 3), "DEFGHI")
d $$$AssertEquals(..Solution(.matrix, 3, 3), "EFGHI")
d $$$AssertEquals(..Solution(.matrix, 3, 2), "FGHI")
d $$$AssertEquals(..Solution(.matrix, 3, 1), "GHI")
d $$$AssertEquals(..Solution(.matrix, 2, 1), "HI")
Hi,
I knocked up some code to extract the plain text from an RTF document. It works for my purposes but would like to know if anyone can find a case where it does a bad job.
Copy your .rtf file into a flat array, eg x(1)=first line, x(2)=second line then:
d ##class(yourclass).StripRTF(.x,.y)
and you'll get the plain text in y