EugeneJudo's blog

By EugeneJudo, history, 3 years ago, In English

I've been building up tools for problem solving, and one that came to mind was a form of meta programming. I've found that often I'll know exactly how to structure the entire program, but there are a few loop bounds where it's not immediately clear (e.g. do we end the loop at n, or n-1, or n+1.) Rather than do this hard work of thinking/debugging, every reasonable bound choice is added as a label, and a higher level program generates program strings that are compiled with every possible combination of bounds, returning all of the program strings which pass all local test cases.

Does anyone actually do this, or similar metaprogramming trickery in practice, or is it a fools errand?

  • Vote: I like it
  • +27
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I'm not sure if that's what you are looking for. But when upsolving D2. RPD and Rap Sheet (Hard Version), I vaguely guessed the possible pieces that could be a part of the calculation formula. Then implemented a function, which combined these pieces together in various ways based on a bitmask parameter. And then bruteforced all the possible bitmask values to find a magic constant 0x0001C8ED, which passed my local tests and also was accepted when submitted as 121667819. This approach worked fine when fooling around and having fun after a contest, but it's probably too slow and wasteful in a real contest.

»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

While I do a fair bit of guess and checking in cp as well (not to this automated extent tho), I do not think it's good practice. It is better to train your thinking by working out and finding exact details, because it gets easier the more you do it. If you already have such a tool created, perhaps use it during live contests but try not to use it while upsolving.