removed the patterns cases, as we don't need to print patterns, and wrote simple recursive implementation