unholy_matrix.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can solve a rather hard dynamic programming problem"
  3. TAGS = ['code', 'c']
  4. question = "A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies."
  5. step = """To solve this question:
  6. - Use bit arithmetic and an unsigned long to represent the matrix.
  7. - Write a function is_unholy that tests if a matrix is unholy by bit-shifting and masking.
  8. Use a dynamic program to count the number of unholy matricies.
  9. - Recurse on the number of rows the matrix has.
  10. - Enumerate all 2^16 next two rows. This is enough to completely isolate the prior solutions from the next.
  11. Write out a plan for the program, and then implement the plan in C."""
  12. answer = "1121231537486377866"
  13. TestUnholyMatrix = question >> LLMRun() >> ExtractCode(keep_main=True) >> CRun() >> SubstringEvaluator(answer)
  14. TestUnholyMatrixStep = (question + step) >> LLMRun() >> ExtractCode(keep_main=True) >> CRun() >> SubstringEvaluator(answer)
  15. if __name__ == "__main__":
  16. print(run_test(TestUnholyMatrix))