Welcome to Stack Overflow! If you believe that the code works correctly, consider presenting your work (with its unit tests if you can) in a more-complete fashion over at
Code Review. You'll likely get some suggestions on making it more efficient, easier to read, and better tested. Before you do that, make sure to read
A guide to Code Review for Stack Overflow users first, as some things are done differently over there - e.g. question titles should simply say what the code
does, as the question is always, "How can I improve this?". —
Toby Speight 48 secs ago